I have an SDI-12 moisture sensor and it is working very well with the code below but I need to separate the values for each parameter such as Volumetric Water Content or Temperature. cause what i am currently receiving all the parameters on a single output.
Can anybody help me.
#include <SDISerial.h>
//in order to recieve data you must choose a pin that supports interupts
#define DATALINE_PIN 2
#define INVERTED 1
//see: attachInterrupt() - Arduino Reference
//for pins that support interupts (2 or 3 typically)
SDISerial sdi_serial_connection(DATALINE_PIN, INVERTED);
char* get_measurement(){
char* service_request = sdi_serial_connection.sdi_query("?M!",1000);
//you can use the time returned above to wait for the service_request_complete
char* service_request_complete = sdi_serial_connection.wait_for_response(1000);
//dont worry about waiting too long it will return once it gets a response
return sdi_serial_connection.sdi_query("?D0!",1000);
}
void setup(){
sdi_serial_connection.begin(); // start our SDI connection
Serial.begin(9600); // start our uart
Serial.println("OK INITIALIZED"); // startup string echo'd to our uart
delay(3000); // startup delay to allow sensor to powerup and output its DDI serial string
}
int j=0;
void loop(){
uint8_t wait_for_response_ms = 1000;
char* response = get_measurement(); // get measurement data
//if you you didnt need a response you could simply do
// sdi_serial_connection.sdi_cmd("0A1")
Serial.print("RECV:");Serial.println(response!=NULL&&response[0] != '\0'?response:"No Response!"); //just a debug print statement to the serial port
delay(500);
}
Response from the sensor are as follows
RECV:1+99.64+25.37+79.65+0.03
RECV:1+99.74+25.35+79.74+0.03
RECV:1+99.64+25.35+79.65+0.04
RECV:1+99.84+25.35+79.83+0.02
RECV:1+99.64+25.37+79.65+0.02
RECV:1+99.93+25.35+79.92+0.00
RECV:1+99.84+25.37+79.83+0.05
RECV:1+99.84+25.37+79.83+0.01
RECV:1+99.84+25.37+79.83+0.02
Thank you very much