I am trying to read a energy meter data using Arduino uno. The energy meter communicates through MODBUS. I have connected the Meter with Arduino through RS-485 to TTL but I am unable to get the data. The aim is to read the register data from ENergy meter and print on serial monitor. Please help me finding whats's wrong with the code and how can I proceed.
Hi,
it would make our attempt to help a lot easier if you let us know which meter model, datasheet, link or image, which RS485 module you are using and which link you used to download the "ModbusMaster.h" library.
(I recommend that when using libraries that are not the IDE's default ones, comment out its origin link in the include line of the library).
Print the error code in hex and check what the library tells you. 0xE0 (224) is "id not matching". Imho your register 30001 is far off. Try numbering start with 0 instead.
Seems overly simple, but are you certain that the Rx and Tx pins of your Arduino module are/are-not swapped? My RS-485 transceiver board has LEDs for both Tx and Rx pins which makes basic wiring troubleshooting a bit easier (at least you know that you are getting Tx and Rx "bit" transmissions both TO and FROM your microcontroller to the RS-485 transceiver...
Also, there are a few MAX485 serial transceiver variants, so a specific board/model; number would be required.
I am using one from eBay/Amazon that does automatic ""transmission driver activation" and does not need any of the "pre" and "post" transmission bit toggling to both send and receive half-duplex RS-485 serial messages. It works fine for me communicating to a PZEM-014.
These modules have only 4-pins on the microcontroller serial side:
+5V, GND, Tx, Rx (note no DE or RE
Also, if you are stuck on using "manual" transceiver RE/DE for asserting the RS-485 transmitter, you can just as easily wire DE/RE to the same pin and save a digital output as DE is active HIGH and RE is active LOW.