Modbus RTU RS485 to ESP8266 autonics MT4W

I have problem with reading data from autonics mt4w through rs-485. Ive been following every step that i watched from youtube edc. And keep failing to read either holding register or input register. This is my code:

#include <ModbusMaster.h>

#define MT4W_ADDRESS 1 // Set according to your MT4W Modbus address
#define RX_PIN D2 // GPIO pin connected to RS485 RX
#define TX_PIN D3 // GPIO pin connected to RS485 TX

ModbusMaster node;

void setup() {
Serial.begin(9600);
Serial.println("Starting Modbus RTU with ESP8266");

// Initialize Modbus communication with MT4W
node.begin(MT4W_ADDRESS, Serial);
}

void loop() {
uint8_t result;
uint16_t measuredValue;

// Read "Measured value" from holding register 30001 (0x0000)
result = node.readHoldingRegisters(0x0000, 1); // Register 30001 in hex is 0x0000

if (result == node.ku8MBSuccess) {
measuredValue = node.getResponseBuffer(0);
Serial.print("Measured Value: ");
Serial.println(measuredValue);
} else {
Serial.print("Error reading register: ");
Serial.println(result);
}

delay(1000); // Polling delay
}

Does anyone has experienced to help me to read value from autonics. Thanks

Have you tried to test communication mt4w via software modbus poll with modul RS485 to ttl?

please follow the forum how to and post your code in code tags.
It is described here:

You can edit your first post and put the code in code tags.

Error Code 226 (in hex 0xE2) means the device is not responding - you might have a wrong connection.

provide following missing information:

  • upload a schematic so we can see how you want to connected your components
  • upload pictures so we can see what you have connected in reality
  • link to the datasheet of the "MT4W" so we can check the supported modbus functions and addresses

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.