Modbus and Arduino

Hey. I’m still new and just learning the system. Now I’m trying to properly configure the modbas on OH2 Windows 10. Next, I plan to transfer all settings to RPI3 and program arduino. Now I use the Epsolar solar controller for the modbass. Already managed to get data through paperui and display in basicui. The problem is that all data must be divided by 100. How to do it correctly? And how to configure OH2 correctly, is it possible to combine a setting through paperui and editing .things files and so on? And, through editing files, I can’t figure out how to configure the modbas

Scroll down to ‘Transformations’ in the docs for a divide-by-10 example

Yes. You’ll probably want to be consistent in some areas to avoid driving yourself mad.
Personally I prefer configuring Modbus with a xxx.things file, but you can use that with PaperUI Items etc.

You said you can already display data. What’s the problem?

Can I use the Transformations setting in Paper UI? Or is it possible only through editing the file? I did not understand how to do this. I also do not understand the correct structure of files and folders in the folder with OH2. For example, where should the modbus.cfg or transform / multiply10.js file be from the example?

Sure.
But be consistent. Don’t define a Thing in a xxx.things file and then use PaperUI to change it. It will confuse openHAB as well as you, and likely lose any changes at next reboot when the (unaltered) xxx.things file is loaded again.
I think PaperUI does its best to stop you making that mistake.

There is no modbus.cfg with the modbus binding v2.
There are no things and channels with the obsolete modbus binding v1.
You can use either, but not both binding versions.
If you don’t know what you’ve got, it’s probably v2 by default.

Be careful when looking at old forum posts or tutorials about which version they refer to.

That’s not unique to modbus, it’s about transforms in general.
In the conf folder, where you find sub-folders for items, things, etc. you will also find a transform folder.

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?