Application Note:OpenPLC on VisionFive 2

This application note provides the steps for the application of OpenPLC based on VisionFive 2. The OpenPLC application used is adapted to the platform of VisionFive 2.It is now available for download in the RVspace community:OpenPLC on VisionFive 2

Official repository: GitHub - thiagoralves/OpenPLC_v3: OpenPLC Runtime version 3

The overview of OpenPLC on VisionFive 2 can be seen below:

There are 8 digital inputs, 8 digital outputs, and 1 analog output defined in VisionFive 2 hardware layer, pins distribution are shown below:

OpenPLC Runtime uses the IEC 61131-3 nomenclature to address input (I), output (Q), and memory (M) locations. Moreover, memory bits (%MX) locations were not implemented, create any variable of type bool with no location (leave location blank) for it to serve as memory bits. If those variables need to be accessed by Modbus, locate those variables in the %QX area outside of device bounds, for example ‘%QX80.0’. More details can be seen at: 2.3 Input, Output and Memory Addressing – Autonomy

In the table above, %IX0.x, %QX0.x and %QWx represent digital input, digital output, and analog output respectively. All these I/Os are controlled by python lib:’Visionfive.gpio’. The pin num that is marked green indicates that this pin can be enabled by the Python library. More details of ‘VisionFive.gpio’ can be seen in Preparing Software.

The physical pins and number (if VisionFive.gpio supports) of OpenPLC I/O can be defined in the hardware layer file (openplc_v3/webserver/core/hardware_layers/VisionFive2_py.cpp):


Before installing OpenPLC, some preparations need to be completed.

1. Environment Requirements
The environment requirements are as follows:

  • Linux Kernel: Linux 5.15
  • OS: Debian 12
  • SBC: VisionFive 2
  • SoC: JH-7110

2. Required Hardware

3. Burn Image
Please reference to 快速入门 to download, burn and scale a Debian image.

Install OpenPLC

Download link:
File path: VisionFive2/Engineering Release/202308/debian-packs/

Preparing Software
Follow the steps below to prepare software environment:

  1. Execute the following command to preparing software:
    sudo apt-get install -y curl git udev libxml2-dev autoconf automake autotools-dev icu-devtools libicu-dev libsigsegv2 m4 autoconf-archive gnu-standards libtool gettext m4 make cmake build-essential pkg-config bison flex libtool nodejs libbz2-dev sqlite3 libgdbm-dev openssl libexpat1-dev python${version}-dev python2 python2-dev

  2. Install pip for python2.7 and python3:

curl --output && sudo python2.7
curl --output && sudo python3
  1. Install python packages:
sudo pip2 install flask
sudo pip2 install flask-login
sudo pip2 install pyserial
sudo pip2 install pymodbus
sudo pip3 install pymodbus==2.5.3


Perform the following steps to install OpenPLC:

  1. Execute the following command to install:
    sudo dpkg -i openplc-vf2.deb
    After the installation is completed, there will be:

  2. After installation of OpenPLC runtime, the python library VisionFive.gpio should also be installed by referring to the Preparing Software section.

  3. After installing VisionFive.gpio, a reboot is required.

OpenPLC Editor

The OpenPLC Editor is an IEC 61131-3 compliant PLC code editor. It allows you to create, compile and upload your IEC 61131-3 programs to the OpenPLC Runtime. OpenPLC Editor implements all the languages described in the IEC-61131-3 standard: Ladder Logic (LD), Function Block Diagram (FBD), Instruction List (IL), Structured Text (ST), and Sequential Function Chart (SFC).

Basic knowledge of PLC programming can be seen at:

Install OpenPLC Editor
Download Link: Download – Autonomy.
More details of PLC programming language and examples: 3.2 Creating Your First Project on OpenPLC Editor – Autonomy.

Programming and Generating Program
Single Program
Multiple Programs

PLC Simulation

After programming, it is necessary to determine whether the logic is correct and the function is complete, and then upload it to run in PLC, the simulation function of the OpenPLC editor can be used to show how a program is performing at every step. Take the ‘single program’ mentioned before as an example:

As shown in the figure above, click Start PLC Simulation and Debug instance, and a new tab Config0.Res0.instance0 will appear. Then the value of input point I0 can be changed and the variation of point Q0 can be observed.

The current values of each point can be seen from the Debugger bar on the right side:


After installation and restart of the system, the OpenPLC HMI (Human-Machine Interface) can be viewed by accessing port 8080 of VisionFive 2 in your browser:

The followings are the default credentials and can be modified in the Users menu:

  • Username: openplc
  • Password: openplc

The HMI main page is shown below by default:

Run OpenPLC

On the Dashboard menu, the information on OpenPLC status, active program, and runtime log are shown.

After clicking the Start PLC button, OpenPLC runtime will start, and the information of runtime will be printed in the Runtime Log field.

It’s recommended to run the CPU at the highest frequency by running the following commands:

su -
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

to achieve optimal system performance.

Upload New Program

On the Programs menu, the new program can be updated to OpenPLC or reverted to a previously uploaded program shown on the table.

Take the example of uploading a new program: and click

  1. Click the label view to choose a new program:

2. Select an .st file for the new program and click Open. The name of the file that will be uploaded is then displayed next to the ‘view’ label.
3. Click the label Upload Program, complete the information, and click Upload Program


After the successful compilation, the compilation log will be printed, and information that “Compilation finished successfully!” will be displayed.

4. Click Go to Dashboard and Start the OpenPLC runtime, the information about the running program can be viewed:

Connect slave device



In the Monitoring menu, the state of each I/O point defined in the ladder diagram can be seen. For example, after uploading the program mentioned in the Basic digital I/O & Analog Output Test section and starting the OpenPLC runtime, the state and details of each I/O points are shown as:

Hardware Layer

OpenPLC controls inputs and outputs through a piece of code called hardware layer, different hardware layers can be selected for different devices.

Users and Settings

The user of OpenPLC can be added or modified in the Users menu. And some settings, such as ports of server and start mode can be changed in the Settings menu.

Basic Functions

This section record OpenPLC digital input/output, analog output, and basic program function block test methods and results.

Ladder diagram program is located in your computer after you download and unzipped the,for example: C:\Users\chloe.chen\Downloads\openplc\6. Basic

Basic digital I/O & Analog Output Test
Bistable Test
Timer Test
Counter Test

1 Like