|
| 1 | +/** |
| 2 | + * @file h_SDI-12_slave_implementation.ino |
| 3 | + * @copyright (c) 2013-2020 Stroud Water Research Center (SWRC) |
| 4 | + * and the EnviroDIY Development Team |
| 5 | + * This example is published under the BSD-3 license. |
| 6 | + * @date 2016 |
| 7 | + * @author D. Wasielewski |
| 8 | + * |
| 9 | + * @brief Example H: Using SDI-12 in Slave Mode |
| 10 | + * |
| 11 | + * Example sketch demonstrating how to implement an arduino as a slave on an SDI-12 bus. |
| 12 | + * This may be used, for example, as a middleman between an I2C sensor and an SDI-12 |
| 13 | + * datalogger. |
| 14 | + * |
| 15 | + * Note that an SDI-12 slave must respond to M! or C! with the number of values it will |
| 16 | + * report and the max time until these values will be available. This example uses 9 |
| 17 | + * values available in 21 s, but references to these numbers and the output array size |
| 18 | + * and datatype should be changed for your specific application. |
| 19 | + * |
| 20 | + * D. Wasielewski, 2016 |
| 21 | + * Builds upon work started by: |
| 22 | + * https://github.com/jrzondagh/AgriApps-SDI-12-Arduino-Sensor |
| 23 | + * https://github.com/Jorge-Mendes/Agro-Shield/tree/master/SDI-12ArduinoSensor |
| 24 | + * |
| 25 | + * Suggested improvements: |
| 26 | + * - Get away from memory-hungry arduino String objects in favor of char buffers |
| 27 | + * - Make an int variable for the "number of values to report" instead of the |
| 28 | + * hard-coded 9s interspersed throughout the code |
| 29 | + */ |
| 30 | + |
| 31 | +#include <SDI12.h> |
| 32 | + |
| 33 | +#define DATA_PIN 7 /*!< The pin of the SDI-12 data bus */ |
| 34 | + |
| 35 | +// Create object by which to communicate with the SDI-12 bus on SDIPIN |
| 36 | +SDI12 slaveSDI12(DATA_PIN); |
| 37 | + |
| 38 | +void setup() { |
| 39 | + Serial.begin(115200); |
| 40 | + slaveSDI12.begin(); |
| 41 | + delay(500); |
| 42 | + slaveSDI12.forceListen(); // sets SDIPIN as input to prepare for incoming message |
| 43 | + Serial.println("Starting SDI-12 Spy"); |
| 44 | +} |
| 45 | + |
| 46 | +void loop() { |
| 47 | + while (slaveSDI12.available()) { |
| 48 | + int readChar = slaveSDI12.read(); |
| 49 | + Serial.write(readChar); |
| 50 | + // if (readChar == '\n') { |
| 51 | + // slaveSDI12.forceListen(); |
| 52 | + // } else { |
| 53 | + // delay(10);// 1 character ~ 7.5ms |
| 54 | + // } |
| 55 | + } |
| 56 | +} |
0 commit comments