Low-Cost Microcontroller & Single-Board Computer Platforms Aid in Building OpenPLC ControllersLow-Cost Microcontroller & Single-Board Computer Platforms Aid in Building OpenPLC Controllers

OpenPLC provides a low-cost entry point into controls engineering & automation development by using an open-source approach.

Dr. Don Wilcher

November 25, 2024

6 Min Read
Low-Cost Microcontroller Single-Board Computer OpenPLC Controllers
Dr. Don Wilcher

At a Glance

  • OpenPLC was started as a PhD research project focusing on cybersecurity for industrial programmable logic controllers (PLCs).
  • OpenPLC can be used with the BCM2711, the ESP32 & the ATmega328 microcontrollers.
  • The OpenPLC Runtime Environment software engine also allows PLC programs to run on the Raspberry Pi 4.

An open-source ecosystem allows sharing application resources and providing technical support through an active developers’ community. OpenPLC is a programming editor that support the International Electrotechnical Commission (IEC) standard on functional programming languages for programmable logic controllers (PLCs). The specific IEC standard is 61131-3. The development of OpenPLC is based on the mission of making PLC technologies affordable for controls engineers and technicians. The typical cost of a PLC can range from $100 to over $1000. The cost of the PLC is based on the programmable features and input/output (I/O) termination points managed by I/O modules. The OpenPLC platform aided by the IEC 61131-3 standard allows a cost-effective and functional PLC to be constructed using off-the-shelf microcontroller and single-board computer (SBC) platforms. Supporting electrical and electronic components completes the controls features of the PLC. Figure 1 illustrates the OpenPLC platform supporting some of the popular microcontrollers.

OpenPLC-Figure1-Don-Wilcher.jpg

OpenPLC supports the BCM2711 microcontroller

The popular Raspberry Pi 4 Model B single-board computer (SBC) is powered by the Broadcom BCM2711 microcontroller. The Broadcom BCM2711 is a quad-core Cortex-A72 system on chip (SoC). The chip has an operating frequency of 1.5 GHz. With such processing power, the BCM2711 allows the Raspberry Pi 4 Model B to be transformed to an effective, low-cost PLC. The PLC transformation of the Raspberry Pi 4 Model BCM2711 microcontroller is based on the use of the OpenPLC runtime. A typical BCM2711 microcontroller populated on a Raspberry Pi 4 Model B is shown in Figure 2.

Related:What Is OpenPLC?

Raspberry_Pi_OpenPLC_PXL_20241202_231141874.jpg

OpenPLC Runtime Environment

The concept behind developing a PLC using a Raspberry Pi 4 Model B is the implementation of the OpenPLC Runtime Environment. The OpenPLC Runtime Environment (RE) software engine allows PLC programs to run on the Raspberry Pi. The OpenPLC RE has an integrated web server that allows the configuration of runtime parameters. The runtime parameters are aligned with data types and memory registers. Listed below are a few OpenPLC runtime parameters.

  • X: for bit (1 bit)

  • B: for byte (8 bits)

  • W: for word (16 bits)

  • D: for double word (32 bits)

  • L: for long word (64 bits)

These parameters are created during the compilation and download process of the structured text (.st) file executed in the OpenPLC editor. The runtime web server is obtainable using the Raspberry Pi’s internet protocol (IP) address on port 8080.The runtime web server allows the Raspberry Pi based OpenPLC’s I/O to be visible and accessible. An example of the OpenPLC runtime environment by way of the integrated web server is shown in Figure 3. 

Related:The New Raspberry Pi 4 Is All About AI and Embedded IoT

OpenPLC-Figure3-Wilcher.jpg

The OpenPLC ladder diagram (LD) that enables the runtime monitor is shown in Figure 4.

OpenPLC-Figure4-Wilcher.jpg

OpenPLC & the ESP32 microcontroller

The ESP32 microcontroller can be deployed to various IoT and controller projects with low manufacturing development costs and a highly effective processor. The ESP32 microcontroller has become quite popular in the maker and embedded communities because of its low cost, ease of use, and technical support. Some key features of the ESP32 microcontroller include Wi-Fi, Bluetooth, and a small form factor. The ESP32 uses an Xtensa L6 32-bit microprocessor. With 32-bits of processing power, the ESP32 microcontroller can easily be transformed into a mini-PLC. The general-purpose input-output (GPIO) pins allow the electrical interface of industrial pushbutton switches, LED indicators, and solid-state relays to be implemented using an ESP32 microcontroller seamlessly. Additional features like inter-integrated circuit (I2C) peripheral interface and the controller area network (CAN) bus extends the ESP32 PLC machine-to-machine connectivity. The temperature sensor and touch-sensing features of the ESP32 PLC can establish safety features within the OpenPLC LD. These peripheral devices and features are shown in this functional block diagram.

Related:How to Equip an Arduino Opta DC Motor Controller with HMI

OpenPLC & the ATmega328 microcontroller

The ATmega328 microcontroller initially started the development of the OpenPLC platform. OpenPLC was initiated as a PhD research project with the focus on cybersecurity for industrial controllers, particularly PLCs. The ATmega328 microcontroller, which is populated on an Arduino Uno board, became the development unit of choice. The cost effectiveness of the ATmega328 microcontroller and the compatibility of the OpenPLC software allowed a community of developers to be built, thereby providing application PLC LDs to be implemented and shared online. The I/O structure of the ATmega328 consisting of digital and analog pins align quite well with the IEC 61131-3 Functional Programming language standard. 

The IEC standard supports five programming languages: Instruction list (IL), structured text (ST), sequential function chart (SFC), ladder diagram (LD), and function block diagram (FBD). They provide a diverse set of coding tools to be deployed on the ATmega328-based Arduino Uno. The most common programming language used by control engineers and plant technicians in industrial and automation environments is the LD. Therefore, the Arduino Uno established the concept of a cost-effective microcontroller being used in a PLC application. The LD approach to programming aligns with creating industrial controls using relay ladder logic wiring diagrams. The contacts and coils used in electromechanical relay controllers can easily be converted into a LD using bit instructions. An example of the relay ladder logic wiring diagram is shown in Figure 5. A LD equivalent PLC program is illustrated in Figure 6.

OpenPLC-Figure5-Wilcher.jpg

OpenPLC-Figure6-Wilcher.jpg

The final control circuit was implemented using an Up/Down pushbutton switch box. The Down pushbutton implements the Stop function. The Start function is initiated using the Up pushbutton. The pushbutton switch box was wired to the appropriate Arduino Uno digital pins established by the OpenPLC software pin guidelines. Figure 7 illustrates the completed Arduino Uno-OpenPLC Start-Stop Controller. This example can easily be built using the ESP32 microcontroller and the BCM2711 based Raspberry Pi 4 Model B SBC. Therefore, a PLC can be built using cost-effective microcontrollers and SBC platforms.

OpenPLC-Figure7_Wilcher.jpg

About the Author

Dr. Don Wilcher

Dr. Don Wilcher, an Electrical Engineer, is an Associate Certified Electronics Technician (CETa), a Technical Education Researcher, Instructor, Maker, Emerging Technology Lecturer, Electronics Project writer, and Book Author. His Learn Electronics with Arduino book, published by Apress, has been cited 80 times in academic journals and referenced on patents. 

He is the Director of Manufacturing and Technology at Jefferson State Community College. His research interest is Embedded Controls, Robotics Education, Machine Learning, and Artificial Intelligence applications and their impact on Personalized Learning, Competency-Based Models curriculum, and instructional development in Mechatronics, Automation, IoT, Electronics, Robotics, and Industrial Maintenance Technologies. He is also the Founder and owner of MaDon Research LLC, an instructional technology consulting, technical training, and electronics project writing company serving Electronics Marketing Media, Technical and Engineering Education companies.

Sign up for Design News newsletters

You May Also Like