Example A: Using the Wildcard - Getting Single Sensor Information

This is a simple demonstration of the SDI-12 library for Arduino. It requests information about a single attached sensor, including its address and manufacturer info, and prints it to the serial port

PlatformIO Configuration

1; PlatformIO Project Configuration File
2
3[platformio]
4description = SDI-12 Library Example A: Getting information for a single attached sensor
5src_dir = .piolibdeps/Arduino-SDI-12_ID1486/examples/a_wild_card
6
7[env:mayfly]
8monitor_speed = 115200
9board = mayfly
10platform = atmelavr
11framework = arduino
12lib_ldf_mode = deep+
13lib_ignore = RTCZero
14lib_deps =
15 SDI-12

The Complete Example

1/**
2 * @example{lineno} a_wild_card.ino
3 * @copyright Stroud Water Research Center
4 * @license This example is published under the BSD-3 license.
5 * @author Kevin M.Smith <SDI12@ethosengineering.org>
6 * @date August 2013
7 *
8 * @brief Example A: Using the Wildcard - Getting Single Sensor Information
9 *
10 * This is a simple demonstration of the SDI-12 library for Arduino.
11 *
12 * It requests information about the attached sensor, including its address and
13 * manufacturer info.
14 */
15
16#include <SDI12.h>
17
18uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port */
19int8_t dataPin = 7; /*!< The pin of the SDI-12 data bus */
20int8_t powerPin = 22; /*!< The sensor power pin (or -1 if not switching power) */
21
22/** Define the SDI-12 bus */
23SDI12 mySDI12(dataPin);
24
25/**
26 '?' is a wildcard character which asks any and all sensors to respond
27 'I' indicates that the command wants information about the sensor
28 '!' finishes the command
29*/
30String myCommand = "?I!";
31
32void setup() {
33 Serial.begin(serialBaud);
34 while (!Serial)
35 ;
36
37 Serial.println("Opening SDI-12 bus...");
38 mySDI12.begin();
39 delay(500); // allow things to settle
40
41 // Power the sensors;
42 if (powerPin >= 0) {
43 Serial.println("Powering up sensors...");
44 pinMode(powerPin, OUTPUT);
45 digitalWrite(powerPin, HIGH);
46 delay(200);
47 }
48}
49
50void loop() {
51 mySDI12.sendCommand(myCommand);
52 delay(300); // wait a while for a response
53 while (mySDI12.available()) { // write the response to the screen
54 Serial.write(mySDI12.read());
55 }
56 delay(3000); // print again in three seconds
57}