Example Code for LattePanda-Python ModBus Library Control
Last revision 2026/01/08
This article presents example code for controlling relay modules using Python ModBus libraries on LattePanda V1, including hardware setup, wiring diagrams, operation steps, and results to achieve effective device control.
Hardware Preparation
- LattePanda V1 x1
- DFR0684 RS485 Connector Expansion Shield for LattePanda V1 x1
- DFR0290 8 Channel IoT Ethernet Relay Controller x1
Wiring Diagram
-
Connect the Shield and LattePanda V1
-
Use the Copper Columns and screws to fix the shield on LattePanda Board.

Not Sopport Hot Plugging
Operation Steps
The following are the popular ModBus thrid-party Python libraries at present.
- Modbus_tk
- Pymodbus
- Minimalmodbus
- Umodbus
| Name | Source Code | Third-party Dependencies | Main Function |
|---|---|---|---|
| modbus_tk | https://github.com/ljean/modbus-tk | Pyserial | Support modbus TCP and RTU, both master and slave. Not support modbus ASCII. Heavyweight |
| pymodbus | https://github.com/riptideio/pymodbus/ | Pyserial | Support modbus TCP/RTU/ASCII, master and slave. Heavyweight |
| minimalmodbus | https://github.com/pyhys/minimalmodbus | Pyserial | Only support Modbus RTU and ASCII, and only work in master(clinet). Very lightweight |
| uModbus | https://github.com/AdvancedClimateSystems/uModbus/ | Pyserial | Support both Modbus client amd server (both TCP and RTU). Not support Modbus ASCII. Lightweight |
Here we will take modbus_tk as an example.
- Repeat the steps above.
- Install Python and modbus_tk and other dependency packages on LattePanda.
- Write Python codes to control the relay modudle according to the ModBus protocol principle of the 8 channel relay controller.
Result
Run Python script to get device name and control device to turn on/off all relays in order, shown as below:
Additional Information
- Click to download the Python3 Script Sample.
Was this article helpful?
