Hello all,
I have been working with some Teros 12 soil moisture sensors for a precision irrigation project in my lab. This project has been handed over to me from a previous coworker who was able to get proper data values from the sensor. Since I have been working on the projects I have not been able to get output values from the sensors despite submerging them in different soil moisture environments with various water content levels. The output is consistently "Raw (data) is 0.00 and VWC is -0.7.". From the sketch, these are the values that would show up if there is no output from the sensor.
For the past few weeks I have had some summer interns assisting me with this project, and in a troubleshooting effort, we ran the exact same sketch on one of their laptops which is a Mac and we got numbers back that adjusted logically in different water environments. I have a Windows. My previous coworker had a Mac as well. This is really the only difference between us running the code and getting different outputs.
Does anyone know of any discrepancies between using Arduino IDE on Mac or Windows laptops? Or possibly something about using SDI12 libraries on the different hardware?
Thank you for your time and help!!
Here is the sketch we are running if it helps:
// Sensor Library and Definitions
#include <SDI12.h>
#define DATA_PIN 11
// SDI-12 bus data pin
#define SOIL_SENSOR_ADDRESS_1 2
// #define SOIL_SENSOR_ADDRESS_1 1
// #define SOIL_SENSOR_ADDRESS_2 2
// #define SOIL_SENSOR_ADDRESS_3 3
// #define SOIL_SENSOR_ADDRESS_4 4
SDI12 busSDI12(DATA_PIN);
#define SERIAL_BAUD 115200
String dataString = " ";
// Raw data coming from the Teros sensors
float RAW1;
// float RAW2;
// float RAW3;
// float RAW4;
// Volumetric Water Content
float VWC1;
// float VWC2;
// float VWC3;
// float VWC4;
void setup() {
// Serial setup
Serial.begin(SERIAL_BAUD);
Serial.print("Starting Program...");
// SDI-12 setup
busSDI12.begin();
delay(500);
}
void loop() {
echoData();
delay(500);
}
void echoData() {
// Calls subFunction Measurement_Output() which calls TakeValue() which irecieves returned value TakeMeasurement()
// The result is stored into RAW1 an VWC1 which is echoed to the screen
// The three subfunctions are presented in order of appearance for readability
RAW1 = Measurement_Output(SOIL_SENSOR_ADDRESS_1, 1.0, 0.0); // 1st measurement on SOIL_SENSOR_ADDRESS_1
// RAW2 = Measurement_Output(SOIL_SENSOR_ADDRESS_2, 1, 1.0, 0.0); // 1st measurement on SOIL_SENSOR_ADDRESS_2
// RAW3 = Measurement_Output(SOIL_SENSOR_ADDRESS_3, 1, 1.0, 0.0); // 1st measurement on SOIL_SENSOR_ADDRESS_1
// RAW4 = Measurement_Output(SOIL_SENSOR_ADDRESS_4, 1, 1.0, 0.0); // 1st measurement on SOIL_SENSOR_ADDRESS_2
VWC1 = (3.879e-4)*RAW1-0.6956 ;
// VWC2 = (3.879e-4)*RAW2-0.6956 ;
// VWC3 = (3.879e-4)*RAW3-0.6956 ;
// VWC4 = (3.879e-4)*RAW4-0.6956 ;
// average_value = (VWC1 + VWC2 + VWC3 + VWC4) / (number_of_sensor) ;
// Adding the parameters to the string that will be logged to the SD card ( will need to add/subtract depending on parameters being logged )
// dataString += String(VWC1) + "," + String(VWC2) + "," + String(VWC3) + "," + String(VWC4) + "," + " Average:" + String(average_value) + ",";
dataString += "Raw is: " + String(RAW1) + " and VWC is " + String(VWC1);
Serial.println(dataString);
dataString ="";
}
// Function allows the sensor to take a measurement and convert it into a float
float Measurement_Output(int Sensor_Address, float Slope, float Offset ){
String raw_data = getValue(TakeMeasurement(Sensor_Address));
float reading_actual = (raw_data.toFloat() * Slope) + Offset;
return reading_actual;
}
String getValue(String data){
char separator= '+';
int index= 1;
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length()-1;
for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
String TakeMeasurement(int Sensor_Address){
//Setup the command measuremt cmd
String Command = "";
Command += Sensor_Address;
Command += "M!";
busSDI12.sendCommand(Command);
delay(2000);
busSDI12.clearBuffer();
//set up data request cmd
Command = "";
Command += Sensor_Address;
Command += "D0!";
String Measurement = ""; //Assigning an output
//Starting bus and sending command
busSDI12.sendCommand(Command);
delay(30);
//Compliling reading and appending to the empy output string
while(busSDI12.available()){
char c = busSDI12.read();
if ((c != '\n') && (c != '\r')) {
Measurement += c;
delay(10); // 1 character ~ 7.5ms
}
}
busSDI12.clearBuffer();
return Measurement; // Returning raw measurement
}
// Function that can split up a string (split raw data into usable data)