OpenPLC on Raspberry Pi: Step-by-Step Setup Tutorial
Turn a $50 Raspberry Pi into a working PLC. Full path from blank SD card to running ladder logic with GPIO acting as digital I/O and a Modbus TCP client reading the values.
What you'll need
- • Raspberry Pi 4 (any RAM size) or Raspberry Pi 5
- • microSD card, 16 GB or larger, Class 10
- • USB-C power supply (3 A for Pi 4, 5 A for Pi 5)
- • Ethernet cable (recommended) or Wi-Fi credentials
- • A development PC with the OpenPLC Editor installed
- • Optional: relay HAT or external 24 V interface board to drive industrial loads safely
Pi GPIO is 3.3 V logic. Do not wire it directly to 24 V industrial signals — use an opto-isolator board, relay HAT, or a Pi-compatible PLC interface like PiXtend, RevPi, or Sequent Microsystems' industrial HATs.
Step 1: Flash Raspberry Pi OS Lite
- Download Raspberry Pi Imager from
raspberrypi.com/software. - Insert your microSD card. In Imager, choose Raspberry Pi OS Lite (64-bit).
- Click the gear icon to set hostname, enable SSH, set username/password, configure Wi-Fi if not using Ethernet.
- Write the image. Eject and insert into the Pi.
Step 2: Boot and update
ssh pi@openplc-pi.local
sudo apt update
sudo apt full-upgrade -y
sudo rebootStep 3: Install OpenPLC Runtime
sudo apt install -y git
git clone https://github.com/thiagoralves/OpenPLC_v3.git
cd OpenPLC_v3
./install.sh rpiThe installer takes 5–15 minutes. When it finishes, the OpenPLC web interface is at http://openplc-pi.local:8080, default credentials openplc / openplc.
Step 4: Configure GPIO as PLC I/O
Log into the OpenPLC web interface, click Hardware, select Raspberry Pi:
| PLC address | Direction | Pi GPIO pin |
|---|---|---|
| %IX0.0 – %IX0.7 | Digital input | GPIO 8, 7, 16, 20, 21, 26, 19, 13 |
| %IX1.0 – %IX1.6 | Digital input | GPIO 6, 5, 12, 11, 25, 9, 10 |
| %QX0.0 – %QX0.7 | Digital output | GPIO 2, 3, 4, 17, 27, 22, 23, 24 |
| %QX1.0 – %QX1.6 | Digital output | GPIO 18, 14, 15, 1, 0, 8, 7 |
| %IW0 – %IW7 | Analog input (over MCP3008 SPI ADC) | SPI bus, requires hardware |
Step 5: Write your first ladder program
On your development PC, install OpenPLC Editor from openplcproject.com/runtime. New project → Ladder Diagram. Add a single rung that wires Input 0.0 to Output 0.0. Save. File → Generate program for OpenPLC Runtime.
Step 6: Upload and run
- OpenPLC web interface → Programs → Upload Program.
- Select your generated
.stfile. - Click Compile program; wait for "Compilation finished successfully".
- Click Start PLC on the Dashboard.
- Click Monitoring to see live tag values.
Step 7: Connect a Modbus TCP client
OpenPLC exposes its variables via Modbus TCP on port 502:
mbpoll -m tcp -a 1 -t 0 -r 1 -c 8 openplc-pi.localFor visual clients use qModMaster (cross-platform, free) or Modbus Poll (Windows). Both can read/write coils, discrete inputs, holding registers and input registers.
Where to go next
- • Real I/O: pair the Pi with a relay HAT (Sequent Microsystems Home Automation HAT) to drive 24 V loads safely.
- • Industrial Pi: upgrade to PiXtend or Revolution Pi for proper isolated I/O, DIN-rail mounting, CE/UL certification.
- • Connect to SCADA: Ignition Maker Edition (free for non-commercial) connects to OpenPLC over Modbus TCP for full HMI graphics.
- • Move to production: ladder logic ports cleanly to CODESYS Control or commercial PLCs — IEC 61131-3 portability is OpenPLC's main strength.