Is the hard coded checksum in your canned modbus message correct for the contents of the message?
You also have to set your RE/DE control pin low once the transmission completes before you can read the reply from your sensor, otherwise the sensor can't take control of the RS485 bus and respond.
That I don't know I also think the error is in the request, but I don't see where.
I also tried using libraries so I don't have to compose the request myself, but there I get an "E2" HEX error.
#include<ModbusMaster.h>
#include <SoftwareSerial.h>
#define RX_PIN 11
#define TX_PIN 10
#define MAX485_REDE_PIN 12
SoftwareSerial modbusSerial(RX_PIN, TX_PIN);
ModbusMaster node; //object node for class ModbusMaster
void preTransmission() //Function for setting stste of Pins DE & RE of RS-485
{
digitalWrite(MAX485_REDE_PIN, 1);
}
void postTransmission()
{
digitalWrite(MAX485_REDE_PIN, 0);
}
void setup()
{
pinMode(MAX485_REDE_PIN, OUTPUT);
digitalWrite(MAX485_REDE_PIN, 0);
Serial.begin(9600); //Baud Rate as 9600
Serial.println( MAX485_REDE_PIN );
modbusSerial.begin(9600); //Baud Rate as 9600
node.begin(1, modbusSerial); //Slave ID as 1 on SoftwareSerial
node.preTransmission(preTransmission); //Callback for configuring RS-485 Transreceiver correctly
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result = node.readHoldingRegisters(8,1); // Reads Holding Register 8
Serial.println(result,HEX);
if (result == node.ku8MBSuccess)
{
Serial.print("data : ");
Serial.print(node.getResponseBuffer(0));
}
Serial.print("\n");
delay(3000);
}
E2 is the error code for a response timeout - i.e. the remote device didn't respond.
Do you have a common ground between your Arduino and the sensor?
Also, I thing you have your RX and TX swapped over. If RX is on pin 10, then that should connect to the RO pin on the MAX485 module. TX should go to the DI pin.
There's debate of the addition of the common ground. Some say it has to be there, others say no. Over workbench type distances you probably do not need it. The specifics on why you need it are a bit over my head. I do note that there are several questions regarding this if you do a google search for "RS485 common ground".
The Modbus DIPS: DIP1 -> Only 1 is on. DIP2 -> Default (All off). ON DIP: Only 5 is on.
(Oh just noticed that the second datasheet is only available in Dutch, But I don't think you need that one for the Modbus communication)
I do have the problem that there is no output on the analog output. Could be that It's a faulty sensor. But the fact it responds and doesn't give the E2 is already a great achievement haha.
That's good. You have established comms with the sensor.
I would try with querying a parameter that you know what the value should be - roughly!
What does the sensor respond with if you were to query temperature, which the manual says is at register address 0?
You could also try register 500 which the manual says should return the value 0x0700 (assuming the 16 subscript means base 16 - i.e. hexadecimal - and not a note 16.
I would have expected register 0 to give you temperature. Regardless of the units of temperature I would have thought you should get some non-zero value back.
A little update. I'm finally getting some data back from register 8 (differential pressure). When I blow on one end the value seems to go up and cap at a certain value. Which looks good. Going to try and translate it to the actual value now.