Trouble in making SDIserial.h, SD.h and RTClib.h work well together

Hi folks,
I’m playing with 5TE (a sensor for soil water content) using SDIserial library. However new problem comes out.
When I use SD.h and RTClib.h together, it works well, you can check code NO 1 and screenshot NO1.
When I use SDIserial.h and RTClib.h together, it works well, you can check code NO 2 and screenshot NO2.
When I use SD.h and SDIserial.h together, it also works well, you can check code NO 3 and screenshot NO3.
However, When I combine SD.h, RTClib.h and SDIserial.h together, it doesn’t work! No data is showed in the screen. It’s so strange. You can check code NO4 where I just put “#include <SD.h>” inside.
I also attach the libraries I use. I really confused with that it doesn’t work when I combine three libraries.

I’m looking forward to your reply
Best regards
Jingbo

files and libraries.rar (1.21 MB)

No data is showed in the screen. It’s so strange. You can check code NO4 where I just put “#include <SD.h>” inside.

Including SD.h reserves 1/4 of the Uno's memory for reading from/writing to the SD card. If just including that file causes problems, it is because you have run out of memory.

Quit wasting it:
Serial.println(F("SDIserial.h and RTC.h with SD.h"));

           String Datetime=String(now.month(),DEC)+"/"+String(now.day(),DEC)+"/"+String(now.year(),DEC)+" "+String(now.hour(),DEC)+":"+String(now.minute(),DEC)+":"+String(now.second(),DEC);

Absolutely NOT on a limited memory system.

Ditch the String class. Write the pieces to the SD card/file/buffer one piece at a time. On the card, it will make NO difference.

Hello Pauls,
please check the code below. when I delete the statements" #include <Wire.h>, #include "RTClib.h" , RTC_DS1307 rtc; ", the code worked well, you can check the picture 1, where card is ready and there is data.
However, When I put the statements " #include <Wire.h>, #include "RTClib.h" , RTC_DS1307 rtc; " inside the code. The code didn't work well, you can check the picture 2, where card failed and there is not data.
In my opinion, SD, RTC DS1307 and 5TE are all I2C divices, maybe they are not compatible. Could you tell me how to make them work together well?
The libraries of SD.h, RTClib.h and SDIserial.h which I'm using also are attached behind.

  #include <SD.h> 
  int chipselect=4;
  int i=1;
  
 // #include <Wire.h>
  //#include "RTClib.h"
 // RTC_DS1307 rtc;
  
  char X='+';
  #include <SDISerial.h>       
  #define DATALINE_PIN 5
  #define INVERTED 1
     
  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()
    {
        Serial.begin(57600);

         if(!SD.begin(chipselect))
              {
                Serial.println("Card Failure!");
               // return;
              }
          Serial.println("Card Ready!");
          File datafile=SD.open("TEST.csv",FILE_WRITE);
          if(datafile)
              {
                String Title="NO,DATA";
                datafile.println(Title);
                delay(100);
                datafile.close();
              }
           else
              {
                Serial.println("Couldn't open data file!");
              }

         sdi_serial_connection.begin();
         delay(1000);
        
    }
    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);
           }
           
           String datastring = "NO: "+String(i)+"  data:  "+FTE;
           Serial.println(datastring);
           delay(50);
           File datafile=SD.open("TEST.csv",FILE_WRITE);
           if(datafile)
              {
                 datafile.println(datastring);
                 delay(100);
                 datafile.close();
              }
            i++;

    }

libraries.rar (742 KB)

From SDISerial.h:

#define _SS_MAX_RX_BUFF 255 // RX buffer size
class SDISerial : public Stream
{
private:
  //sdi12 stuff 
  char response[255];
  static char _receive_buffer[_SS_MAX_RX_BUFF];

So, when you create an instance of the class, 510+ bytes of memory are used.

When you use SD.h, another 512+ bytes are used.

That's half the UNO's (and other 328-based Arduinos) memory.

The String class that you are using wastes a lot of memory, for no real gain. The stuff you are doing can be done using C string functions.

String literals occupy SRAM. You have a LOT of them. Keep them out of SRAM by using the F() macro.