Learn how to install the popular industrial automation software CodeSys on your Raspberry Pi and create your own PLC program.

This guide will show you how to install the industrial automation software CodeSys on your Raspberry Pi, which is a powerful tool for creating programmable logic controllers (PLCs) and Industrial Inte …


Updated October 14, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


This guide will show you how to install the industrial automation software CodeSys on your Raspberry Pi, which is a powerful tool for creating programmable logic controllers (PLCs) and Industrial Internet of Things (IIoT) applications. We will cover all the steps necessary to get started, including downloading and installing the software, configuring your system, and running your first PLC program on Raspberry Pi.

  1. System Requirements

Before we begin, it’s important to check if your Raspberry Pi meets the minimum requirements for CodeSys installation. At the time of writing, the official documentation recommends the following configuration:

  • Raspberry Pi 4 Model B (2GB or 4GB) with a 64-bit OS
  • 8 GB or more microSD card
  • Internet connection
  • Monitor and keyboard (optional)

Note that while CodeSys can technically be installed on other Raspberry Pi models, some features may not work properly. It’s always best to follow the official recommendations for optimal performance.

  1. Getting the CodeSys Installer

First, you need to download the CodeSys installer from the official website. The latest version can be found here: https://codesys.com/downloads/. Choose the “Linux DEB” package suitable for your Raspberry Pi model and architecture (32-bit or 64-bit).

  1. Installing the CodeSys Installer

To install the downloaded package, open a terminal window on your Raspberry Pi and navigate to the folder where you saved the installer. Then run the following command:

sudo dpkg -i codesys_32bit_raspbian.deb  # for 32-bit Raspberry Pi models
sudo dpkg -i codesys_64bit_raspbian.deb  # for 64-bit Raspberry Pi models
  1. Configuring CodeSys

After installation, you need to configure CodeSys by running the following command:

codesyscontrol config

This will open a configuration window where you can specify various settings such as licensing options, user accounts, and project directories. It’s important to set up your license now to avoid any issues later on. If you don’t have one yet, you can request a trial license from the CodeSys website or purchase a full license.

  1. Creating a New Project

Now that CodeSys is installed and configured, let’s create our first PLC project. Open the CodeSys graphical user interface (GUI) by running:

codesys

In the main menu, select “File” > “New Project…” and choose a location for your project file. Give it a name and click “OK”.

  1. Configuring the PLC

The next step is to configure your PLC settings. In the CodeSys GUI, expand the “PLC Project” node in the project tree, right-click on “PLC configuration”, and select “Properties”. Here you can set parameters such as the runtime (e.g., CoDeSys Runtime or twincat), target device type (e.g., Raspberry Pi 4), and communication settings.

  1. Creating a Simple PLC Program

To create a simple PLC program, add a new “Program” node to the project tree by right-clicking on “PLC Programs” and selecting “Add new Program”. Name your program and click “OK”. Double-click on the newly created program to open the code editor.

In the main window, you will see a blank canvas where you can create your PLC logic. Let’s create a simple program that toggles an LED connected to GPIO pin 18 every second:

PROGRAM MAIN
VAR_OUTPUT
    led : BOOL;
END_VAR

led := NOT led; (* Toggle the LED state *)
WAIT(T#1s); (* Wait for 1 second *)
  1. Compiling and Running the Program

To run your PLC program on Raspberry Pi, you need to compile it first by selecting “Build” > “Make All” from the main menu. If there are no errors, CodeSys will generate a binary file in the project directory that can be deployed to your device.

To deploy and run the program, connect your Raspberry Pi to your PC via USB or Ethernet, then right-click on the PLC configuration node in the project tree and select “Deploy”. Choose the correct target device and click “OK” to start deployment. Once the process is complete, your PLC program will be running on Raspberry Pi.

  1. Monitoring and Debugging

While the program runs, you can use the CodeSys GUI to monitor the status of your PLC variables and debug any issues that may arise. To do this, right-click on the “PLC configuration” node and select “Start/Stop TwinCAT System”. A new window will open with live data from your Raspberry Pi, including the current state of the LED variable. You can also set breakpoints and step through your code to troubleshoot any problems.

That’s it! You have successfully installed CodeSys on your Raspberry Pi and created a simple PLC program that controls an LED. From here, you can continue exploring the world of industrial automation and IoT with this powerful software. With a bit more knowledge and creativity, you can build all sorts of applications for your Raspberry Pi, from smart home devices to industrial control systems.