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
