This is a simple demonstration of the SDI-12 library for Arduino.
This is a very basic (stripped down) example where the user initiates a measurement and receives the results to a terminal window without typing numerous commands into the terminal.
PlatformIO Configuration
1; PlatformIO Project Configuration File
4description = SDI-12 Library Example F: Taking Measurements and Requesting Results
5src_dir = .piolibdeps/Arduino-SDI-12_ID1486/examples/f_basic_data_request
The Complete Example
2 * @example{lineno} f_basic_data_request.ino
3 * @copyright Stroud Water Research Center
4 * @license This example is published under the BSD-3 license.
5 * @author Ruben Kertesz <github@emnet.net> or \@rinnamon on twitter
8 * @brief Example F: Basic Data Request to a Single Sensor
10 * This is a very basic (stripped down) example where the user initiates a measurement
11 * and receives the results to a terminal window without typing numerous commands into
14 * Edited by Ruben Kertesz for ISCO Nile 502 2/10/2016
19/* connection information */
20uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port */
21int8_t dataPin = 7; /*!< The pin of the SDI-12 data bus */
22int8_t powerPin = 22; /*!< The sensor power pin (or -1 if not switching power) */
23char sensorAddress = '1'; /*!< The address of the SDI-12 sensor */
25/** Define the SDI-12 bus */
26SDI12 mySDI12(dataPin);
28String sdiResponse = "";
32 Serial.begin(serialBaud);
36 Serial.println("Opening SDI-12 bus...");
38 delay(500); // allow things to settle
42 Serial.println("Powering up sensors...");
43 pinMode(powerPin, OUTPUT);
44 digitalWrite(powerPin, HIGH);
50 do { // wait for a response from the serial terminal to do anything
52 } while (!Serial.available());
53 Serial.read(); // simply hit enter in the terminal window or press send and the
54 // characters get discarded but now the rest of the loop continues
56 // first command to take a measurement
57 myCommand = String(sensorAddress) + "M!";
58 Serial.println(myCommand); // echo command to terminal
60 mySDI12.sendCommand(myCommand);
61 delay(30); // wait a while for a response
63 while (mySDI12.available()) { // build response string
64 char c = mySDI12.read();
65 if ((c != '\n') && (c != '\r')) {
67 delay(10); // 1 character ~ 7.5ms
70 if (sdiResponse.length() > 1)
71 Serial.println(sdiResponse); // write the response to the screen
72 mySDI12.clearBuffer();
75 delay(1000); // delay between taking reading and requesting data
76 sdiResponse = ""; // clear the response string
79 // next command to request data from last measurement
80 myCommand = String(sensorAddress) + "D0!";
81 Serial.println(myCommand); // echo command to terminal
83 mySDI12.sendCommand(myCommand);
84 delay(30); // wait a while for a response
86 while (mySDI12.available()) { // build string from response
87 char c = mySDI12.read();
88 if ((c != '\n') && (c != '\r')) {
90 delay(10); // 1 character ~ 7.5ms
93 if (sdiResponse.length() > 1)
94 Serial.println(sdiResponse); // write the response to the screen
95 mySDI12.clearBuffer();
97 // now go back to top and wait until user hits enter on terminal window