I'm try to read some value from a soil NPK sensor using RS485 Modbus e Arduino uno.
I menage to sent the request msg and I got the response but now i don't know how to read the response in order to get the information I need.
the following code sent the request to get moisture value to the sensor:
#include <SoftwareSerial.h>
#define RE 8
#define DE 7
const byte msg[] = {0x01,0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11];
SoftwareSerial mod(2, 3);
void setup() {
Serial.begin(4800);
mod.begin(4800);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
delay(500);
}
void loop() {
test();
}
byte test(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(10);
Serial.flush();
if(mod.write(msg,sizeof(msg))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
for(byte i=0;i<7;i++){
values[i] = mod.read();
Serial.print(values[i],HEX);
}
Serial.println();
Serial.flush();
delay(4000);
}
}
My response is following bits:
114BA4134
1D5112A671
341D2119B
A61341D51
12A671341
E811BBAB13
41DB114BA4
1341DB11
4BA41341DB
114BA4134
1E311CA691
341C911EB
A11341E31
1CA691341
EC11FA6A13
41E4117BA8
looking at the datasheet below there should be a data area in the message response from the sensor.
how to convert this bit info to my humidty value.
my be this example from the datasheet can help

