Skip to main content
added 43 characters in body
Source Link

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++){ Serial.println( values[i] = mod.read(),HEX);   values[i] = modSerial.readprint(values[i],HEX); } Serial.println(); Serial.flush(); delay(4000); } } 

My response is folloingfollowing bits:

1 2 F1 50 FFFFFFFF FFFFFFFF FFFFFFFF 1114BA4134 21D5112A671 E4341D2119B 9FA61341D51 FFFFFFFF12A671341 FFFFFFFFE811BBAB13 FFFFFFFF41DB114BA4 1341DB11 14BA41341DB 2114BA4134 F11E311CA691 50341C911EB FFFFFFFFA11341E31 FFFFFFFF1CA691341 FFFFFFFFEC11FA6A13 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.

pic

my be this example from the datasheet can help

pic 2

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++){ Serial.println(mod.read(),HEX);   values[i] = mod.read(); } Serial.println(); Serial.flush(); delay(4000); } } 

My response is folloing bits:

1 2 F1 50 FFFFFFFF FFFFFFFF FFFFFFFF 1 2 E4 9F FFFFFFFF FFFFFFFF FFFFFFFF 1 2 F1 50 FFFFFFFF FFFFFFFF FFFFFFFF 

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.

pic

my be this example from the datasheet can help

pic 2

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.

pic

my be this example from the datasheet can help

pic 2

Source Link

Modbus RS485 Decode the message received

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++){ Serial.println(mod.read(),HEX); values[i] = mod.read(); } Serial.println(); Serial.flush(); delay(4000); } } 

My response is folloing bits:

1 2 F1 50 FFFFFFFF FFFFFFFF FFFFFFFF 1 2 E4 9F FFFFFFFF FFFFFFFF FFFFFFFF 1 2 F1 50 FFFFFFFF FFFFFFFF FFFFFFFF 

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.

pic

my be this example from the datasheet can help

pic 2