Modbus binding only works sometimes (CRC error)

Hi folks,

I’m a modbus noob and currently trying to get a simple test-setup running. I just want to control the onboard LED (Pin 13) on my arduino with openhab over modbus from my raspi. Therefore my setup is like follows:

  1. raspi with openhab and installed modbus binding
  2. USB to RS485 adapter at the raspi
  3. Max485 module
  4. Arduino mega with the led to control

My modbus.cfg is like this:

serial.slave1.connection=/dev/ttyUSB0:38400:8:none:1:rtu:35:1500:none:none
serial.slave1.type=coil
serial.slave1.id=1
serial.slave1.length=1

My switch.items file:

Switch Relais_1 "My Modbus Switch" (ALL) {modbus="slave1:0"}

On the Arduino I’m using this modbus library: https://github.com/yaacov/ArduinoModbusSlave

My issue is, that controlling the LED on the Arduino works sometimes, but not always. And if it works it is delayed. I have attached my logs here: https://pastebin.com/zyicwp9c

This log is from idle state. I assume that something with the regular connection does not work. Does someone have an Idea what I’m doing wrong? Please let me know if you need more information.

So long

Sven

Meanwhile I was able to make a slight progress on this.

The arduino library has the possibility to register callbacks for reading and writing data. If I do not register for writing and only use the reading callback switching of my LED does work. It is also not delayed anymore. However, the errors in the openhab log still occur. It seems that the received data on arduino is fine, but the response from arduino to raspberry pi seems to be the problem.

Any further Ideas?

So long

Sven

Have you arranged any termination for your RS485 line? It is not always necessary - but sometimes it is.

I would also try running at a lower baud rate (set this at both ends) to improve noise immunity.

Hi,

thank you for the reply :). Yes I have a 120ohm resistor and the end of the line and I assume the USB to RS485 converter has one internally. I also tried to add one to the converter, but it didn’t change anything.

Meanwhile I switched from this modbus1 binding to the experimental modbus2 binding, which is mentioned in the community: Modbus openHAB2 binding available for alpha testing

With this binding it does work way better, but I still have an issue so solve…

So long

Sven

Okay, use the Modbus2 settings to try things like more time between polls. Is the “delayed” action still present? That does suggest something may be ‘busy’ when you don’t expect it…