pheww
November 6, 2024, 11:39pm
1
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?
pheww:
This is my code:
please follow the forum how to and post your code in code tags.
It is described here:
NOTE: Some parts of this excellent guide have become outdated after a change to the forum software. For an updated guide, see:
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966
Note: If you don't see any images in this post you may be blocking cross-site images (eg. with Privacy Badger). The images are hosted at a different site. Allow the domain gammon.com.au if this happens to you.
1. Register and sign in
Create an account (if necessary), and login (sign in).
[image…
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
system
Closed
May 6, 2025, 6:23am
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.