Using multiple Modbus RTU slaves at the same time can be challenging. In this blog we'll explain how to properly achieve communication with mutiple slaves.
Hardware used
For our tests, we used a Raspbery Pi PLC 21+ running Node-RED as the master, and three M-Duino 21+ PLCs as slaves. We also used a protoboard to facilitate the circuitry.
To communicate the slaves with the master we used the RS485 protocol. This is how we connected them (not including the wiring of the power supply):
Node-RED flow
In the Raspberry Pi PLC, we created a Node-RED flow to handle Modbus read requests to multiple devices. Modbus RTU is a sequential protocol, meaning that we will encounter issues if we try to send multiple read requests to multiple devices at the same time. To avoid this issue, we created a fucntion node that handles the sequencing of requests. When implementing this function node in a setup with a different amount of slaves, there's no need to change its code, just change the amount of outputs of the function node.
Click on this icon to download the JSON of the flow:
Or if you are only interested in the code of the function node:
To properly configure each Modbus Getter there's a few things to take into account. The Unit-Id is the identification number given to each of the slaves, we will later see how this number is assigned to the slave. The Modbus Getters from the attached flow are configured to read five digital outputs:
Next is the server. You can access the server configuration from the configuration of any of the Modbus Getter nodes. The setting you are most likely to have to change is the Serial port, as it depends on what model of Raspberry PLC you have:
Arduino IDE
The code for the slaves can be found here:
The code is made for the M-Duino 21+, so if you have a different PLC with a different IO confguration you'll have to modify the code accordingly.
It is important that you set a different ID for each slave device, and that they coincide with one of the Unit-Id value of one of the Modbus Getter nodes. The line that configures the ID is line 57.
Results
After uploading the code to each slave and deploying the Node-RED flow on the master, you should start seeing this in the debug output:
These contain arrays with the values of the digital outputs of each slave PLC.

Using multiple Modbus RTU slaves in Node-RED