ModBus help

Hello again,

I have an em115-mod and can't seem to figure out if it does work with Arduino, but why shouldn't it?

I'm supposed to send this command: "01 04 00 02 00 02 CRC CRC" to get the voltage meter out of the device but I have tried for over a week with different libraries and such things, but can't get it to work.

Are the anybody else that have tried something similar, that maybe could help a little towards the right direction?

show the code you have. you know you should not send it as string but as bytes with CRC calculated?

If Juraj's comment doesn't help, post (in addition to the code) a link to the manual of that device.

The bytes you wrote will read registers 2 and 3 but you don't get just these values but a complete ModBus message with header and CRC.

Juraj:
show the code you have. you know you should not send it as string but as bytes with CRC calculated?

pylon:
If Juraj's comment doesn't help, post (in addition to the code) a link to the manual of that device.

The bytes you wrote will read registers 2 and 3 but you don't get just these values but a complete ModBus message with header and CRC.

Dont have any real code other than the examples from:

The manual can be downloaded from here: Dropbox - EM115-Mod Type A datasheet.docx - Simplify your life

Have tried a lot of small edits to the example in hope for it to work, but nope. Most of them use "Read Holding Registers" but I need the "Read Input Registers", if I understand the manual correctly.

Dont have any real code other than the examples from:

GitHub - yaacov/ArduinoModbusSlave: Modbus slave library for Arduino
GitHub - andresarmento/modbus-arduino: A library that allows your Arduino to communicate via Modbus protocol, acting as a slave (master in development). Supports serial (RS-232, RS-485) and IP via Ethernet (Modbus IP).
GitHub - 4-20ma/ModbusMaster: Enlighten your Arduino to be a Modbus master

The first and the last one are ModBus slave libraries but in your case the Arduino must be master, the energy meter is the slave.
The middle one should work, although I never tried that library myself.

Have tried a lot of small edits to the example in hope for it to work, but nope. Most of them use "Read Holding Registers" but I need the "Read Input Registers", if I understand the manual correctly.

Effectively there is no difference between the two except the function ID. I cannot find a reference in the linked document where the available functions are documented. Do you have additional documentation we haven't seen yet?

Post a wiring diagram of your setup. Without the correct hardware you won't get any communication with that device.

see this Arduino Modbus Master code to read data using arduino uno from EB meter - Arduino Stack Exchange

pylon:
The first and the last one are ModBus slave libraries but in your case the Arduino must be master, the energy meter is the slave.
The middle one should work, although I never tried that library myself.

Effectively there is no difference between the two except the function ID. I cannot find a reference in the linked document where the available functions are documented. Do you have additional documentation we haven't seen yet?

Post a wiring diagram of your setup. Without the correct hardware you won't get any communication with that device.

I have looked more into the second library I sent and can't seem to get anything to work either.
The meter is connect with A to digital pin 5 and B to digital pin 6, have also tried pin 0 1.

With the library I didn't find any options to ask the meter for data.

ReneDyhr:
I have looked more into the second library I sent and can't seem to get anything to work either.
The meter is connect with A to digital pin 5 and B to digital pin 6, have also tried pin 0 1.

With the library I didn't find any options to ask the meter for data.

A and B are RS485 and possibly 12 V. you can't connect it to Arduino pins. use a MAX485 module

Juraj:
A and B are RS485 and possibly 12 V. you can't connect it to Arduino pins. use a MAX485 module

I actually thought that the Arduino had the option to connect it directly.
Have connected a RS485 antenna and that's working fine with A and B.

I actually thought that the Arduino had the option to connect it directly.

No, RS-485 transmits signals differentially, so the voltage difference between A and B show if a 0 or a 1 is transmitted. A and B are not RX and TX.

Have connected a RS485 antenna and that's working fine with A and B.

I don't know what an RS485 antenna is but if it really has a RS-485 interface, it won't work.

pylon:
No, RS-485 transmits signals differentially, so the voltage difference between A and B show if a 0 or a 1 is transmitted. A and B are not RX and TX.

I don't know what an RS485 antenna is but if it really has a RS-485 interface, it won't work.

Alright, thanks. That may be why nothing is working.
I'll get a MAX485 module and then try again. Can you recommend a good schematic on how it should be connected? If I find it correctly, it's needing wires in both ends to the Arduino

Can you recommend a good schematic on how it should be connected?

Depends on the module you buy. If done mine myself because the commercially available all had some serious drawbacks. Once you got the modules post a link to them or better to their schematics. You shouldn't buy modules without the schematics, otherwise you'll be busy to reverse engineer the schematics yourself.

Iv'e had success with this Rs-485 shield and the EM115 https://www.hwhardsoft.de/english/projects/rs485-arduino/ I've also used the r-pi Hat from Zihatec, and that works well with pymodbus library. The demo code for Pymodbus has a "decoder" function that can convert the EM115 reponses into human readable volts/amps/power.
And becuase its python it works great on Ubuntu laptops and my UP2 boards.