Modbus and Arduino

I found the transform folder. there are two files de.map and en.map almost empty. Do I need to create a new transform / divide10.js file here? If I configure via PaperUI, then the files will be empty. Probably I need to go completely to the setting through the files so that there are no errors and confusion. I am using modbus binding v2. Where can I find examples of settings for modbus RTU? Thanks for the help, in the head porridge

The transform folder is the place to put any kind of transform, because that is where openHAB looks for transforms.
A couple of MAP type transforms are provided as examples.

If you want to create a new JS type transform, thats obviously the place to put it.
If you were making what you asked for, you could call it divide100.js for example, but its up to you. banana.js will work just as well, but the .js part is important for the type.

This is really just a text file, it’s up to you what you would prefer to use to edit content into it. I’ve no idea if you can use PaperUI to edit text files, I doubt it. What do you use for a simple text editor usually?

For examples of modbus RTU setups, you could look at the actual documentation for this binding.


This forum has a good search feature too, use those keywords.

I’m confused why we’re worrying about divide by 100 if you don’t have basic modbus working?

Because all numbers I need divide by 100, that it will be right.

Well, I guess that means “I do have modbus working”,

Let us know if you want more help.

Thank you
Yes, modbus is work, but I setting it only in PaperUI, and now that I can use transform I need learn how configure OH2 in files…I use text editor “Visio Studio Code”. I don’t find examples for Modbus v.2, but offen I finded example only modbus v1

here is I finded examples only modbus TCP

You don’t have to. If you are happy using PaperUI, all you have to do is configure your data Thing readTransform parameter to point to your js filename.

PaperUI method and xxx.things file method set exactly the same parameters in your Things. See

A poller Thing is a poller Thing.
A data Thing is a data Thing.
Whether the bridge Thing that owns them is TCP or RTU makes no difference at all to them.
You set up a serial bridge Thing for RTU or a tcp bridge Thing for TCP.

Which part of setting up a serial bridge Thing are you having trouble with?
I searched this forum for an example of modbus serial Thing, here’s one

here’s another

Thank you very much!Now it is working!
I setup it in text redactor and I understood it. When I has written files .things, .items, sitemap I saw all it in PaperUI. And I fully worked after I choose channel in PaperUI. Look





After I will learn other type data and also written data in modbus. Sorry for my English, I’m from Russia. By the way site Openhab don’t work in Russia, I need use VPN for it

Well. I communicated OH with Epsolar in modbus and this work good. How I want communicate arduino with OH. I create scetch as arduino slave and I ran OPC modbus programm in my PC and I recieve data from modbus. But I can’t recieve this data in OH. I use the same settings as OPC modbus programm

I guess this Arduino is serial, and that the PC that works is not the box running openHAB.

So there is different RS485 wiring - take care with those +/- or A/B wires, it’ll only work one way round and not all manufacturers agree which is which. Swap it and see, it does no harm.

Maybe your openHAB settings are different to the PC - we can’t tell from here. As you already have a serial setup, make sure your Arduino uses the same serial settings as the solar thingy. You cannot successfully have devices with different baud or parity on the same wired bus.

When you have several devices or a longer wiring run, you must take care to terminate the RS485 wired bus properly. A 120R resistor at each end usually.

Well. I use OH in PC. Arduino I connected with PC USB cable and I see Arduino as COM port in PC. I disconnected Epsolar and I connect only arduino in PC. In OPC modbus programm I set ID, boud rate, number COM port and etc…And this setting I used in OH…I know about RS-485…May be I need use this connection like arduino-RS-485/RS-485-USB-PC or I need will try serial thing for OH…

I’m not sure what you mean there.
If you want help with openHAB, you’re going to have to share your setup details and things like messages in openhab.log

So, I set one holding register in OPC and I see this traffic:
(COM4) Tx: [0008] 02 03 00 01 00 01 D5 F9
(COM4) Rx: [0007] 02 03 02 05 87 BF 76
and after it I stoped OPC and closed this programm. After it I started OH and I saw this log
2019-06-17 21:28:04.403 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 02 03 00 01 00 01 d5 f9
2019-06-17 21:28:04.403 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2019-06-17 21:28:04.404 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@806b0e5 (unit id 2 & transaction 130). Serial parameters: SerialParameters@22725c39[portName=COM4,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2019-06-17 21:28:04.404 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@806b0e5 (unit id 2 & transaction 130). Serial parameters: SerialParameters@22725c39[portName=COM4,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2019-06-17 21:28:04.404 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@2cfaf8d5[slaveId=2,functionCode=READ_MULTIPLE_REGISTERS,start=1,length=1,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 25172098-85b3-489c-bd4c-2b95873afa87]
2019-06-17 21:28:05.950 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 02 03 00 01 00 01 d5 f9
2019-06-17 21:28:05.951 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2019-06-17 21:28:05.951 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@23566edb (unit id 2 & transaction 131). Serial parameters: SerialParameters@22725c39[portName=COM4,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2019-06-17 21:28:05.952 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@23566edb (unit id 2 & transaction 131). Serial parameters: SerialParameters@22725c39[portName=COM4,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2019-06-17 21:28:05.952 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 2 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@2cfaf8d5[slaveId=2,functionCode=READ_MULTIPLE_REGISTERS,start=1,length=1,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 25172098-85b3-489c-bd4c-2b95873afa87]
2019-06-17 21:28:07.497 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 02 03 00 01 00 01 d5 f9
2019-06-17 21:28:07.497 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2019-06-17 21:28:07.498 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@5250b5b8 (unit id 2 & transaction 132). Serial parameters: SerialParameters@22725c39[portName=COM4,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2019-06-17 21:28:07.498 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@5250b5b8 (unit id 2 & transaction 132). Serial parameters: SerialParameters@22725c39[portName=COM4,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2019-06-17 21:28:07.498 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@2cfaf8d5[slaveId=2,functionCode=READ_MULTIPLE_REGISTERS,start=1,length=1,maxTries=3]). Aborting. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 25172098-85b3-489c-bd4c-2b95873afa87]
2019-06-17 21:28:07.501 [ERROR] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:c93c902e ‘Modbus data_ARD1’ had ModbusSlaveIOExceptionImpl error on read: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message=‘I/O exception: IOException Error reading response (EOF)’, cause2=null)

This is a good start; openHAB is sending the identical request.

But maybe your serial Thing settings don’t match, we cannot tell from here.
As you can see, no valid reply message is getting to openHAB.

You might get a bit more info by enabling debug logging as described in the binding docs.

So. I don’t understend, when I need set debug logging. And I don’t know, when I need will do, that it will work…
Also I tried set Serial Binding, that I can communicate arduino and PC, but I read docs about it, but I don’t understand when I need right configuration…my item look as:
String AVR “String_Test” (FF_Modbus) { serial=“COM4@9600” }
sitemap:
Text item=AVR
and Arduino:
Serial.println(“Text”);
delay(1000);
Serial.println(1);

Not sure what you are trying to achieve with that. It will be very difficult to get Modbus communication working over the simple serial binding.

It’s important to note that only one binding can use COM4. You must delete your Modbus Things to free COM4 up for the serial binding to use.

Remember that your Arduino modbus slave will never send anything until you send it a valid modbus function with correct CRC etc.

But in your Modbus settings you have baudRate=115200

So, I have one goal, communicated arduino and OH2. And I see two ways, modbus or serial connection. I prefer modbus, because it’s good and simple protocol. I used ID=2, 115200, download modbus scetch and I got data in OPC master. But I didn’t recieve this data in OH2.
After it I deleted all modbus setting (I use paper UI)
After it I thougth that I can use serial binding. I downloaded new scetch in arduino with baud rate=9600. I read docs about serial thing, but there is small information. with my setting can I see text in sitemap, which I sent in serial port arduino?

I think you are going at this wrong.
You know openHAB works okay with Modbus, you have it working with another device,
You know your arduino worked with Modbus, you had it working to some other PC program.
So more than likely you just had some small setting wrong. Who knows, you kept your setting secret.

Also reminder that you cannot have Modbus and ordinary serial share the COM4 port.

You would need to link a String type Item to the serial binding.
To get it working, look in openhab.log an events.log to see what is happening.
When it is working, put the String Item on your sitemap as a Text Item.

Hello. I understood, why Openhab don’t work with arduino. Because in arduino library in modbus slave you need read all register all at once. Openhab can read registers one by one. I create test project on STM 32 and it’s work
Now I have other problem. I installed Openhab on Raspberry 3 on clean raspberry system and I setup it’s from teamViewer by remote. I use USB-485 devise and I don’t understand how I can setup Serial Port in Raspberry

openHAB Modbus binding will read between 1 and 120 registers at once, depending how you set it up. How you chose to set it up before was kept secret.

What are you trying to do with serial, send data to openHAB? What part are you having trouble with?

Yes. But how I can set modbus thins if I need read for examle 10 parameters in 10 registers at the same time?

in the Serial Port Configuration I need write number and name port, which I use. In Windows I write COMx, but in RPI I need /dev/ttyUSB0 or /dev/ttyAMA0 and etc. How can I define it?