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.