This is a simple demonstration of the SDI-12 library for Arduino. It uses the blocking SDI12Recorder API to query the address of a single attached sensor, request its identification information, and print the parsed fields to the serial port.
PlatformIO Configuration
1; PlatformIO Project Configuration File
4description = SDI-12 Library Example A: Getting information for a single attached sensor
5src_dir = .piolibdeps/Arduino-SDI-12_ID1486/examples/a_wild_card
The Complete Example
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 uses the wildcard query to find exactly one attached sensor and prints its
13 * identification information.
16#include <SDI12Config.h>
17#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && !defined(SDI12_INTERNAL_PCINT)
18#include <EnableInterrupt.h>
21#include <SDI12Recorder.h>
24#define SDI12_DATA_PIN 7
26#ifndef SDI12_POWER_PIN
27#define SDI12_POWER_PIN 22
29#ifndef SDI12_TERMINAL_BAUD
30#define SDI12_TERMINAL_BAUD 115200
33uint32_t serialBaud = SDI12_TERMINAL_BAUD; /*!< The baud rate for the serial port */
34int8_t dataPin = SDI12_DATA_PIN; /*!< The pin of the SDI-12 data bus */
35int8_t powerPin = SDI12_POWER_PIN; /*!< The sensor power pin (or -1) */
37/** Define the SDI-12 bus and recorder */
38SDI12 mySDI12(dataPin);
39SDI12Recorder mySDI12Recorder(mySDI12);
42 Serial.begin(serialBaud);
43 while (!Serial && millis() < 10000L);
45 Serial.print(F("Opening SDI-12 bus on pin "));
46 Serial.print(dataPin);
47 Serial.println(F("..."));
49 delay(500); // allow things to settle
53 Serial.println(F("Powering up sensors..."));
54 pinMode(powerPin, OUTPUT);
55 digitalWrite(powerPin, HIGH);
61 // The wildcard query works only when exactly one sensor is attached to the bus.
62 const char address = mySDI12Recorder.queryAddress();
63 if (address == '\0') {
64 // A return of null for the address means nothing was found
65 mySDI12Recorder.printRecorderResult(Serial);
68 SDI12Recorder::Identification sensorInfo;
69 if (mySDI12Recorder.identify(address, sensorInfo)) {
70 mySDI12Recorder.printSensorInfo(sensorInfo, Serial);
72 Serial.print(F("Identification failed for address "));
73 Serial.print(address);
74 Serial.print(F(": "));
75 mySDI12Recorder.printRecorderResult(Serial);
79 delay(3000); // print again in three seconds