rnunley
Is it possible to use multiple Arduino Unos with a single Raspberry Pi host? If so, what would be the recommended way to do this? 
Reply 0 0
thiagoralves
Currently there isn't a straightforward way to do that. However, if you are well versed in coding, you can modify the /core/hardware_layer.cpp file to accomplish that. In any case, I don't recommend you to try this if you are not comfortable with C/C++
Reply 0 0
Olorin
Hello everyone
Implementing the modbus (SLAVE) protocol on Arduino I think you can handle as many Arduino you want.
Obviously on the Arduino side you will have to write some code.
================
http://www.flussiliberi.it/
================
Reply 0 0
thiagoralves
You're right. Using the Arduino as a Modbus slave will do the trick. Obviously, on the OpenPLC side you will have to use the Modbus driver instead of the Arduino one. On the Arduino side, nowadays with Google and github, you don't even have to write code anymore. I googled for Arduino modbus and found this: https://github.com/yaacov/ArduinoModbusSlave
Reply 0 0
Olorin
Hello
I think it would be better to implement modbus on tcp ip, the extension of the Arduino network in that case would not have physical limits
I have not tried yet but the candied libraries are the ones I carry under:
http://myarduinoprojects.com/modbus.html
https://github.com/siamect/mudbus
https://code.google.com/archive/p/mudbus/
https://code.google.com/archive/p/mudbus/downloads

If you know a good library to implement modubs tcip on Arduino you could give me the link?

Thank you 
================
http://www.flussiliberi.it/
================
Reply 0 0
thiagoralves
The problem about Modbus on TCP/IP is that the Ethernet shield uses many valuable pins that could be used for normal I/O. The Modbus RTU (serial) uses only two pins, and because of the internal serial to USB converter, the arduino's USB port can be used for that. With a simple USB hub on the host you solve the problem of having many arduinos connected at the same time.

But in any case, if you still want to have Modbus/TCP on your arduino, I remember using the Mudbus library a long time ago: https://github.com/luizcantoni/mudbus/tree/master/Mudbus
Reply 0 0
rnunley
Thanks guys. I ended up sorting it out with this library: https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino. 
Reply 0 0
kain5266
I am using modbus master driver on raspberry to connect multiple arduino unos trough rs-485. Everything works perfect with one arduino, but when I connect two or more its not working correctly. I run the same code on both arduinos only with different slave ID. I think the problem is in the configuration file for openPLC as only the first device works, eg: I have Num_devices= "2" and only device0 works, but with slow speed, and for device1 I get continuous error connection lost. 
I use the same library for arduino:   https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino.    

I would really appreciate help, thank you.
Here is my config file:
Num_Devices = "2"

device1.name = "device2"
device1.protocol = "RTU"
device1.slave_id = "2"
device1.address = "/dev/ttyUSB0"
device1.IP_Port = ""
device1.RTU_Baud_Rate = "9600"
device1.RTU_Parity = "N"
device1.RTU_Data_Bits = "8"
device1.RTU_Stop_Bits = "1"
device1.Discrete_Inputs_Start = "0"
device1.Discrete_Inputs_Size = "0"
device1.Coils_Start = "0"
device1.Coils_Size = "1"
device1.Input_Registers_Start = "0"
device1.Input_Registers_Size = "0"
device1.Holding_Registers_Start = "0"
device1.Holding_Registers_Size = "0"

device0.name = "device1"
device0.protocol = "RTU"
device0.slave_id = "1"
device0.address = "/dev/ttyUSB0"
device0.IP_Port = ""
device0.RTU_Baud_Rate = "9600"
device0.RTU_Parity = "N"
device0.RTU_Data_Bits = "8"
device0.RTU_Stop_Bits = "1"
device0.Discrete_Inputs_Start = "0"
device0.Discrete_Inputs_Size = "0"
device0.Coils_Start = "0"
device0.Coils_Size = "1"
device0.Input_Registers_Start = "0"
device0.Input_Registers_Size = "0"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "0"
Reply 0 0
thiagoralves
I'm suspecting that libmodbus is not being able to access multiple devices over the same serial port. Have you tried connecting each arduino using a separated usb cable and then specify which virtual COM port each arduino is connected to on the modbus configuration file?
Reply 0 0
kain5266
I tried and it works. I connected each arduino with separate usb cables directly to rpi, and set the adress to dev/ttyUSB0 and dev/ttyUSB1 in the config file. Now i had to be careful to connect arduino in the correct USB port in order so that the port adress on the rpi is the same as in config file for specific arduino.

Is there any way to make it work over the same USB port trough USB to RS-485 adaper?
Is it a limitation in libmodbus? because it should be possible over 485.
Reply 0 0
thiagoralves
I don't have an RS485 adapter to test, so I don't really know. Libmodbus is a pretty standard Modbus library, everybody uses it, so it should support multiple devices on the same port.

But in any case, you should be careful with your wiring. Even if libmodbus supports multiple devices but you're doing a wrong wiring, it will not work. Also, Arduinos are not compatible with the RS485 standard. You probably should use an RS485 shield to connect them to the bus and you must have a bus terminator at the end or it can go bad.
Reply 0 0
kain5266
I used rs232 to 485 adapter for arduino, as well as the MAX485 chip itself and both work perfectly.
I got it to work over 485, but i used the same slave ID on both arduinos and the same slave ID in the config file for both devices. I only changed the addresses of the I/O so I could access them individually.
The connection is slow and I get continuous errors in the OpenPLC, but it works.
Reply 1 0
thiagoralves
I was looking at my implementation of the Modbus Master driver using libmodbus and I think I've done something wrong that is preventing multiple slaves on the same serial port to communicate properly. Instead of creating multiple mb_ctx with the same address, I need to create a single mb_ctx and just change the slave id address with modbus_set_slave() while querying different devices. This change is not going to be pretty, because it will require modifications on the structure of the driver, but I might do it in the near future if no one is willing to try to fix it.
Reply 1 0
Reply