SDI 12 script serial monitor issue

Hi everyone,Im trying to make an arduino script that communicates with SDI 12 protocol and send data from a sensor to an mkr board and put the result in serial monitor.
.Im already using a level shifter turning 5 volts to 3.3v,the electrical part works.

When I run my script,I get all working but in my serial monitor for the M command I get 10012F or 10012lca.
I dont know why I get this F or lca, it should just be 10012 and then receive de data whenever is ready with the D command.
Months before I tried this script with an arduino uno board(5V) and from what I remember It worked perfectly,but a colleague told me its not possible my sccript is not working for an electrical scheme issue.

I leave the code here:

#include <SDI12.h>

#define DATA_PIN 7
#define SENSOR_ADDRESS 1
String sdiResponse = "";
SDI12 sdi(DATA_PIN);

void setup() {
  Serial.begin(1200);
  while(!Serial);

  sdi.begin();
  delay(500);
  // String command = String(SENSOR_ADDRESS) + "M";
   String command = "";
    command += 1;
    command += "M";
    command += "!"; 
  
  sdi.sendCommand(command);
  
  delay(1000);

  while (sdi.available()) {
    char c = sdi.read();
    if ((c != '\n') && (c != '\r')) {
      sdiResponse += c;
      delay(10);  // 1 character ~ 7.5ms
      
    }
    
  }
  Serial.println(sdiResponse);
  Serial.println("");

   delay(500);
   
   delay((((sdiResponse[1]-48)*100000)+((sdiResponse[2]-48)*10000)+((sdiResponse[3]-48)*1000))-500); //el [0] es el primer nĂºmero.
   
    
// String command = String(SENSOR_ADDRESS) + "D0";
   String command1 = "";
    command1 += 1;
    command1 += "D0!";
  
  sdi.sendCommand(command1);
  
  delay(30);

  while (sdi.available()) {  // build string from response
    char c = sdi.read();
    if ((c != '\n') && (c != '\r')) {
      sdiResponse += c;
      delay(10);  // 1 character ~ 7.5ms
    }
  }
    Serial.println(sdiResponse);// write the response to the screen
    String Potencia = sdiResponse.substring(7, 14);
      int Potenciaint = Potencia.toInt();
      String T_suelo = sdiResponse.substring(15, 19);
      int T_sueloint = T_suelo.toInt();
      delay(1000);
      Serial.println("Potencia=" );
      Serial.println(Potenciaint);
      Serial.println("T_suelo=" );
      Serial.println(T_sueloint);
      
       
  sdi.clearBuffer();
  
}

void loop() {
  

}

I would appreciate any help,thank you.

What kind of string character do want this to put into 'command'?
Really odd coding. Why are You not using loop?

Im not using loop because this script is made to try that the comunication using SDI 12 works,when it fully works,I will add it into a data logger script in loop function.

In ''command'' string I want to write the 1M! and 1D0! to send information to the sensor,those commands are part of SDI12 library.

Then You choose the wrong way.

Look at this:
command += 1;
command += '1';
command += "1";

Arduino/reference might give inspiration!

You put a control character having the value 1 there. Check the ASCII table what that is!

Not true. The String class is smart enough to turn that into the string representation of the int 1 so the whole thing comes out as "1M!".

Just a long, odd whay of doing it vs.

command = "1M!";

Surprice, surprice. Never used C## after a half day introduktion 1994....

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.