Back to Home

Control of Raspberry Pi Pico via OpenPLC and Modbus RTU

The article describes the integration of Raspberry Pi Pico W into a distributed control system using OpenPLC and Modbus RTU. Hardware configuration, register addressing, logic programming, and limitations of the DIY approach in an industrial environment are considered.

Raspberry Pi Pico as I/O node in OpenPLC: practical guide
Advertisement 728x90

# Integrating Raspberry Pi Pico W into an Industrial Control System via OpenPLC and Modbus RTU

In a project based on STM32-IHM03 for PMSM motor control, a remote I/O node using Raspberry Pi Pico W with logic implemented in OpenPLC has been added. Communication between nodes is handled via Modbus RTU over RS485, while system coordination is managed by an Orange Pi 4 Pro using Node-RED. This architecture demonstrates the use of open-source tools to build a distributed automation system compliant with the IEC 61131-3 standard.

Hardware Configuration and Connections

The system core consists of three key components: STM32-IHM03 for motor control, Raspberry Pi Pico W as a remote I/O module, and Orange Pi 4 Pro as the central controller. A CAN bus (using the SN65HVD230 transceiver) connects the STM32 to the Orange Pi, while a two-wire Modbus RTU bus based on the MAX485 chip links the Orange Pi to the Pico.

To connect Modbus and CAN to the Orange Pi, an RS485 CAN HAT shield originally designed for Raspberry Pi is used. Adapting it to the Orange Pi required:

Google AdInline article slot
  • Changing the MCP2515 clock frequency from 8 MHz to 12 MHz in the Device Tree Overlay;
  • Enabling UART7 via orangepi-config for communication with the SP3485 transceiver;
  • Physically mounting the shield on standoffs due to the processor's position under the board.

Power for all components is supplied by an external source, which doesn't affect the operating logic but is crucial for prototype stability.

Pin and Register Addressing in OpenPLC

When programming the Raspberry Pi Pico W in the OpenPLC Editor, you need to match the RP2040's physical pins to Modbus addresses. The table below shows the key mappings:

| PLC Data Type | Notation | Modbus Address Range | Size | Access |

Google AdInline article slot

|---------------|----------|----------------------|------|--------|

| Discrete Outputs | %QX0.0 – %QX6.7 | 0–55 | 1 bit | RW |

| Discrete Inputs | %IX0.0 – %IX6.7 | 0–55 | 1 bit | R |

Google AdInline article slot

| Analog Inputs | %IW0 – %IW31 | 0–31 | 16 bit | R |

| Holding Registers | %QW0 – %QW31 | 0–31 | 16 bit | RW |

| Memory (16/32/64 bit) | %MW / %MD / %ML | 32–171 | up to 64 bit | RW |

These addresses are used when creating logic in ladder diagram (LD) or function block diagram (FBD) languages. For example, controlling a relay connected to GPIO2 corresponds to %QX0.2 and Modbus address 2.

Implementing Logic in OpenPLC v4

OpenPLC v4 enables development of programs compliant with the IEC 61131-3 standard. For Raspberry Pi Pico W, the following programming languages are available:

  • LD (Ladder Diagram) — relay ladder logic, intuitive for electrical engineers.
  • FBD (Function Block Diagram) — graphical representation of functions and their connections.
  • ST (Structured Text) — high-level textual language.

The program is uploaded to the OpenPLC runtime, which runs directly on the microcontroller. In this project, the Pico acts as a Modbus RTU Slave with a fixed address, such as 10. All read/write operations are initiated by the Master device — the Orange Pi via Node-RED.

Example of simple logic: Upon receiving a "start" signal via Modbus, coil %QX0.0 activates, closing the SRD-05VDC-SL-C relay. Meanwhile, the state of discrete input %IX1.0 can serve as an emergency stop signal.

Limitations of the DIY Approach in Industrial Automation

Despite its flexibility and low cost, the Raspberry Pi Pico and OpenPLC solution has significant limitations for industrial use:

  • Lack of galvanic isolation on inputs/outputs makes the system vulnerable to interference from power equipment.
  • Non-standard connectors (e.g., Micro-USB and 2.54 mm headers) can't withstand vibrations in industrial environments.
  • No hardware watchdog, increasing the risk of hangs without reboot.
  • Limited Modbus support in OpenPLC v4: Writing to Holding Registers and Coils may require modifying the runtime source code.

Such systems are suitable for training, prototyping, or small local tasks, but not for mission-critical production lines.

Key Takeaways

  • Raspberry Pi Pico W can serve as a remote I/O node in an automation system using OpenPLC.
  • Modbus RTU communication requires proper pin and register addressing per OpenPLC documentation.
  • Adapting the RS485 CAN HAT shield to Orange Pi is possible but involves editing the Device Tree and enabling the required UART.
  • OpenPLC v4 supports the IEC 61131-3 standard but falls short functionally compared to industrial environments like CODESYS.
  • DIY solutions aren't suitable for industrial deployment without added protection and interface standardization.

— Editorial Team

Advertisement 728x90

Read Next