Hi, I want to read the water flow from meter basically which is water meter and has a rs 485 on meter backside which i have connected to arduino mega 2560 through another MAX485.
The positive pin of meter's rs 485 is connected to the max 485 pin A.
The negative pin of meter's rs485 is connected to the MAx485 pin B.
On other side of max485 D1 pin is connected to arduino pin tx1 and max485 R0 pin is connected to arduino pin Rx1.
Pins DE and RE are connected to arduino pin 3 for transmitting and receiving.All and other connections are also made perfectly like grounding and 5v to max485 from arduino.
But i can find why the code can't read the value and print on serial monitor instead of that it displays "err" message on serial monitor which means no response from meter.
Please help out to solve this problem i am stuck at this from very long.
Thanks
#include <ModbusMaster.h>
ModbusMaster node;
void setup() {
pinMode(3, OUTPUT);
// use Serial (port 0); initialize Modbus communication baud rate
Serial.begin(9600);
Serial1.begin(9600);
// communicate with Modbus slave ID 2 over Serial (port 1)
node.begin(2, Serial1);
}
void loop() {
uint16_t m_startAddress = 1800;
uint8_t m_length = 2;
uint8_t result;
digitalWrite(3, HIGH); // TX
result = node.readHoldingRegisters(m_startAddress, m_length);
// do something with data if read is successful
if (result == node.ku8MBSuccess) {
Serial.print("DATA:");
digitalWrite(3, LOW); // RX
for (uint8_t j = 0; j < m_length; j++)
Serial.print( node.getResponseBuffer(j) );
}
else {
Serial.print("ERR ");
}
delay(500);
}