Example A: Using the Wildcard - Getting Single Sensor Information.
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 the attached sensor, including its address and manufacturer info.
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>
8 * @brief Example A: Using the Wildcard - Getting Single Sensor Information
10 * This is a simple demonstration of the SDI-12 library for Arduino.
12 * It requests information about the attached sensor, including its address and
19#define SDI12_DATA_PIN 7
21#ifndef SDI12_POWER_PIN
22#define SDI12_POWER_PIN 22
25uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port */
26int8_t dataPin = SDI12_DATA_PIN; /*!< The pin of the SDI-12 data bus */
27int8_t powerPin = SDI12_POWER_PIN; /*!< The sensor power pin (or -1) */
29/** Define the SDI-12 bus */
30SDI12 mySDI12(dataPin);
33 '?' is a wildcard character which asks any and all sensors to respond
34 'I' indicates that the command wants information about the sensor
35 '!' finishes the command
37String myCommand = "?I!";
40 Serial.begin(serialBaud);
41 while (!Serial && millis() < 10000L);
43 Serial.println("Opening SDI-12 bus...");
45 delay(500); // allow things to settle
49 Serial.println("Powering up sensors...");
50 pinMode(powerPin, OUTPUT);
51 digitalWrite(powerPin, HIGH);
57 mySDI12.sendCommand(myCommand);
58 delay(300); // wait a while for a response
59 while (mySDI12.available()) { // write the response to the screen
60 Serial.write(mySDI12.read());
62 delay(3000); // print again in three seconds