Why simulate a Modbus slave on a Raspberry Pi?
A Raspberry Pi is small, cheap, and can sit physically next to real RS485 wiring or on the same network segment as PLCs and SCADA systems — something a laptop running a desktop simulator often can't do conveniently in a field cabinet. That makes it a popular choice for engineers who want a persistent, low-power slave device for integration testing or demos, separate from their main workstation.
Modbus TCP slave on a Raspberry Pi (pymodbus)
For Modbus TCP, no extra hardware is needed beyond network connectivity. Install pymodbus and run a minimal slave:
pip install pymodbus
from pymodbus.server import StartTcpServer
from pymodbus.datastore import ModbusSequentialDataBlock, ModbusSlaveContext, ModbusServerContext
store = ModbusSlaveContext(
hr=ModbusSequentialDataBlock(0, [0]*100) # holding registers
)
context = ModbusServerContext(slaves=store, single=True)
StartTcpServer(context=context, address=("0.0.0.0", 502))
Point any Modbus master (PLC, SCADA, or a desktop simulator) at the Pi's IP address on port 502 to read/write the simulated holding registers.
Modbus RTU slave on a Raspberry Pi (RS485 wiring)
The Pi's GPIO UART is 3.3V TTL, not RS485, so you need a USB-to-RS485 adapter (or a Pi HAT with a built-in RS485 transceiver) to actually connect to real serial field devices or a serial master. Once wired:
- Plug in the USB-to-RS485 adapter; it will typically enumerate as
/dev/ttyUSB0 - Wire A/B (or D+/D-) to the master or bus, matching polarity
- Configure pymodbus's serial server with the matching baud rate, parity, and unit ID your master expects
- Start the RTU server and confirm the master can read registers
Raspberry Pi vs a desktop Modbus simulator
| Aspect | Raspberry Pi (pymodbus) | Desktop simulator (Windows/PC) |
|---|---|---|
| Setup time | Python + wiring + scripting | Install and click "Start Slave" |
| Physical field placement | Yes — can sit in a cabinet or near RS485 wiring | Limited to wherever the PC/laptop is |
| GUI for register values | None by default (script/CLI only) | Built-in GUI, live editing |
| Best for | Persistent field-adjacent test rigs, IIoT demos | Day-to-day desk testing, CI/regression, quick checks |
| Cost | Pi + RS485 adapter (~$40–70 hardware) | Free 30-day trial, $99 one-time after |
When you don't need a Raspberry Pi at all
If your goal is simply to have a Modbus slave to validate PLC logic, HMI tags, or SCADA polling — without needing the Pi's physical placement advantages — a desktop Modbus simulator gives you the same TCP and RTU slave behavior with a visual register editor, no code, and no separate device to keep powered and network-reachable.
Related pages
Skip the Pi setup for desk testing
Simulate Modbus TCP and RTU slaves on your PC in minutes — free 30-day trial, then a $99 one-time license.
Download Free tierFAQ
Can a Raspberry Pi act as a Modbus slave?
Yes. Using a library like pymodbus, a Raspberry Pi can run a Modbus TCP or RTU slave process that responds to master requests with simulated register data, making it useful as a low-cost, always-on test device.
Do I need special hardware for Modbus RTU on a Raspberry Pi?
For Modbus RTU you need a USB-to-RS485 adapter (or a Pi HAT with an RS485 transceiver) since the Pi's GPIO UART is 3.3V TTL, not RS485. Modbus TCP needs no extra hardware beyond network connectivity.
Is a Raspberry Pi Modbus simulator reliable for CI or regression testing?
It can be, but it adds infrastructure to maintain: SD card wear, network reachability, and script upkeep. Many teams use a Pi for physical field simulation (e.g. next to real RS485 wiring) and a desktop simulator for day-to-day CI/regression testing where a Pi isn't necessary.
What's a simpler alternative to setting up pymodbus on a Raspberry Pi?
If you just need a Modbus slave to test PLC or SCADA logic against and don't specifically need Pi-based physical I/O, a desktop Modbus simulator gives you the same TCP/RTU slave behavior with a GUI, no Python setup, and no separate device to manage.
Can a Raspberry Pi run both a Modbus master and slave at the same time?
Yes, pymodbus supports running a client and server in the same process or as separate scripts, though for serious master+slave testing workflows most engineers still keep a dedicated simulator on a PC for convenience.