How to set address for 5TE (DECAGON device for soil water content) with UNO

Hi folks,
I’m working on 5TE, a decagon soil water content sensor, using SDIserial.h in I2C protocol. Attachment is the sketch of one 5TE in arduino uno. I didn’t set the address for it, which works well. You can check the result showed in the picture. Now I want to connect 2 sensors to arduino. Could you check the sketch and tell me how to set it? the library of SDIserial.h is also attached.
Thanks
Jingbo

#include <SDISerial.h>
String VWC;   //volumetric water content
String EC;    // electrical conductivity
String TEMP;  // temperature
char X='+';
char *FTEvalue=new char[20];
/*
I used a few devices with no problem using a MEGA 2560 as well as an UNO.
Sketch was built with Arduino 1.0.4, however I also tested it under 1.0.0
Place the SDISerial folder in    "<ARDUINO_ROOT>/libraries"

with the 5TE 
the WHITE wire is power. 
   - I hooked it up to the arduino 5v output pin, however you could also connect it to a pin and drive power only when you wanted it
the RED wire is the DATA_LINE.
   - you must hook it up to a pin that can process interrupts (see link below)
   
the remaining wire must be connected to ground
*/

//in order to recieve data you must choose a pin that supports interupts
#define DATALINE_PIN 5
#define INVERTED 1
//see:   http://arduino.cc/en/Reference/attachInterrupt
//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!",150);
	//you can use the time returned above to wait for the service_request_complete
	char* service_request_complete = sdi_serial_connection.wait_for_response(150);
	//dont worry about waiting too long it will return once it gets a response
	return sdi_serial_connection.sdi_query("?D0!",150);
}

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
  Serial.println("VWCvalue      EC       TEMP");
  delay(3000); // startup delay to allow sensor to powerup and output its DDI serial string
}


void loop(){

  char* response = get_measurement(); // get measurement data
  String FTE=response;
  char tmp1='+';  
  int tmp2=FTE.indexOf(tmp1);
  while(tmp2!=1)
  {
  char* response = get_measurement(); // get measurement data
  FTE=response;
  tmp2=FTE.indexOf(tmp1);
  }
  int FTElength=FTE.length();

  FTE.toCharArray(FTEvalue,FTElength);
      int plustest=FTEvalue[5];
      if (plustest=43)
        {
         VWC= String(FTEvalue[2])+String(FTEvalue[3])+String(FTEvalue[4]);
         EC= String(FTEvalue[6])+String(FTEvalue[7])+String(FTEvalue[8])+String(FTEvalue[9]);
         TEMP= String(FTEvalue[11])+String(FTEvalue[12])+String(FTEvalue[13])+String(FTEvalue[14]);
        }
     else
        {
         VWC= String(FTEvalue[2])+String(FTEvalue[3])+String(FTEvalue[4])+String(FTEvalue[5]);
         EC= String(FTEvalue[7])+String(FTEvalue[8])+String(FTEvalue[9])+String(FTEvalue[10]);
         TEMP= String(FTEvalue[12])+String(FTEvalue[13])+String(FTEvalue[14])+String(FTEvalue[15]);
        }
     float VWCvalue=VWC.toInt()/100;
     Serial.print(VWCvalue);
     Serial.print("         ");
     Serial.print(EC);  
     Serial.print("       ");
     Serial.println(TEMP);
     delay(2000);
}

SDISerial.rar (459 KB)

The attached SDIserial library is a (maybe slightly modified) version of the standard SoftwareSerial library which has nothing to do with I2C. It's modified that way that just one pin is used to send and receive and the baud rate seems to be 1200 in every case. That seems to be what your sensor is also using to communicate.

As the sensor seems to send data only if it's requested to do so, it should be no problem to just instantiate the class twice with different data pins and call the listen method on the objects before making the request.

Thanks for your kind reply.
I will test it later.
The specified baud rate for SDIserial is 1200. In my code, what will happen or how does it effect the result , if I set the baud rate to 9600 or 57600?

The specified baud rate for SDIserial is 1200. In my code, what will happen or how does it effect the result , if I set the baud rate to 9600 or 57600?

You cannot change it easily and from a quick overview of the datasheet I would say that it would be contra-productive because the sensor wouldn't answer.
Why would you want to change it?

If you want to enhance your code, get rid of the String class and work with C strings (character arrays) instead. The String class is probably the worst piece of code in the whole Arduino IDE (just very little ahead of the SoftwareSerial) and should definitely not be used. As you seem to be relying on one of them abandon at least the one that you're easily able to.

Thanks for your kind reply.
Because RTC works well in at least 9600 baud rate and I need to run 5TE with RTC. You mentioned it's better for me to use C strings instead of string class. However, the data I get from 5TE is in the form of "0+1234+5.67+25.6". I need to get 1234, 5.67 and 25.6 respectively from the string. How can I get the value when I use C string?

Because RTC works well in at least 9600 baud rate and I need to run 5TE with RTC.

That's your first mention of an RTC. What kind of RTC are you using? Please provide a link to the hardware (you forgot the link to the 5TE also). Does that RTC also use the SDIserial protocol?

However, the data I get from 5TE is in the form of "0+1234+5.67+25.6". I need to get 1234, 5.67 and 25.6 respectively from the string. How can I get the value when I use C string?

One possibility is to use the strtok() function: strtok - C++ Reference. Another one is to parse it yourself.

Dear Pylon,
Thanks for your kind reply. I'm using DS1307 for time record. DS1307 is running in I2C protocol. I also use DS3234 for time record, which is running in SPI protocol. Please check the links I attached.

5TE link
www.decagon.com/products/soils/volumetric-water-content-sensors/5te-vwc-ec-temp/

DS1307 link

DS3234 link

Thanks for your kind reply. I'm using DS1307 for time record. DS1307 is running in I2C protocol.

The I2C interface doesn't use baud rates (that what it has a clock line for) and usually is much faster than 9600 bps. In what way is this related to your sensor or the addition of an additional sensor?

could you use the 2 sensors at the same time?
share the code please i have the same problem

Has anyone tried this code on an Adalogger Feather MO?

If so, what (if any) changes are needed to the coding.

Did you manage to finish this code? I just need the 5te sensor that measures conductivity, humidity and temperature. Thanks