Example G: Using the Arduino as a Command Terminal for SDI-12 Sensors.
Example G: Using the Arduino as a Command Terminal for SDI-12 Sensors
This is a simple demonstration of the SDI-12 library for Arduino. It's purpose is to allow a user to interact with an SDI-12 sensor directly, issuing commands through a serial terminal window.
Edited by Ruben Kertesz for ISCO Nile 502 2/10/2016
2 * @example{lineno} g_terminal_window.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>
7 * @author Ruben Kertesz <github@emnet.net> or \@rinnamon on twitter
10 * @brief Example G: Using the Arduino as a Command Terminal for SDI-12 Sensors
12 * This is a simple demonstration of the SDI-12 library for Arduino. It's purpose is to
13 * allow a user to interact with an SDI-12 sensor directly, issuing commands through a
14 * serial terminal window.
16 * Edited by Ruben Kertesz for ISCO Nile 502 2/10/2016
22#define SDI12_DATA_PIN 7
24#ifndef SDI12_POWER_PIN
25#define SDI12_POWER_PIN 22
28uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port */
29int8_t dataPin = SDI12_DATA_PIN; /*!< The pin of the SDI-12 data bus */
30int8_t powerPin = SDI12_POWER_PIN; /*!< The sensor power pin (or -1) */
32/** Define the SDI-12 bus */
33SDI12 mySDI12(dataPin);
36String sdiResponse = "";
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 if (Serial.available()) {
58 inByte = Serial.read();
59 if ((inByte != '\n') &&
60 (inByte != '\r')) { // read all values entered in terminal window before enter
62 delay(10); // 1 character ~ 7.5ms
66 if (inByte == '\r') { // once we press enter, send string to SDI sensor/probe
68 Serial.println(myCommand);
69 mySDI12.sendCommand(myCommand);
70 delay(30); // wait a while for a response
72 while (mySDI12.available()) { // build a string of the response
73 char c = mySDI12.read();
74 if ((c != '\n') && (c != '\r')) {
76 delay(10); // 1 character ~ 7.5ms
79 if (sdiResponse.length() >= 1)
80 Serial.println(sdiResponse); // write the response to the screen
82 mySDI12.clearBuffer(); // clear the line