PLC Programming with the Raspberry Pi and the OpenPLC Project - Josef Bernhardt - E-Book

PLC Programming with the Raspberry Pi and the OpenPLC Project E-Book

Josef Bernhardt

0,0
27,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Introduction to PLC programming with OpenPLC, the first fully open source Programmable Logic Controller on the Raspberry Pi, and Modbus examples with Arduino Uno and ESP8286 PLC programming is very common in industry and home automation. This book describes how the Raspberry PI 4 can be used as a Programmable Logic Controller. Before taking you into the programming, the author starts with the software installation on the Raspberry PI and the PLC editor on the PC, followed by a description of the hardware. You'll then find interesting examples in the different programming languages complying with the IEC 61131-3 standard. This manual also explains in detail how to use the PLC editor and how to load and execute the programs on the Raspberry PI. All IEC languages are explained with examples, starting with LD (Ladder Diagram) over ST (Structured Control Language) to SFC (Special Function Chart). All examples can be downloaded from the author's website. Networking gets thorough attention too. The Arduino UNO and the ESP8266 are programmed as ModbusRTU or ModbusTCP modules to get access to external peripherals, reading sensors and switching electrical loads. I/O circuits complying with the 24V industry standard may also be of interest for the reader. The book ends with an overview of commands for ST and LD. After reading the book, the reader will be able to create his own controllers with the Raspberry PI.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 100

Veröffentlichungsjahr: 2021

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



PLC Programming

with the Raspberry Pi

and the OpenPLC Project

ModbusRTU and ModbusTCP examples using the Arduino Uno and the ESP8266

Josef Bernhardt

●This is an Elektor Publication. Elektor is the media brand of Elektor International Media B.V.PO Box 11, NL-6114-ZG  Susteren, The NetherlandsPhone: +31 46 4389444

●All rights reserved. No part of this book may be reproduced in any material form, including photocopying, or storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication, without the written permission of the copyright holder except in accordance with the provisions of the Copyright Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licencing Agency Ltd., 90 Tottenham Court Road, London, England W1P 9HE. Applications for the copyright holder's permission to reproduce any part of the publication should be addressed to the publishers.

●Declaration

The Author and the Publisher have used their best efforts in ensuring the correctness of the information contained in this book. They do not assume, and hereby disclaim, any liability to any party for any loss or damage caused by errors or omissions in this book, whether such errors or omissions result from negligence, accident or any other cause.

●British Library Cataloguing in Publication DataA catalogue record for this book is available from the British Library

●ISBN 978-3-89576-469-1 PrintISBN 978-3-89576-470-7 eBook

●© Copyright 2021: Elektor International Media B.V.Translation: Carmen Jacquemijns Editor: Jan BuitingPrepress Production: D-Vision, Julian van den BergElektor is part of EIM, the world's leading source of essential technical information and electronics products for pro engineers, electronics designers, and the companies seeking to engage them. Each day, our international team develops and delivers high-quality content - via a variety of media channels (including magazines, video, digital media, and social media) in several languages - relating to electronics design and DIY electronics. www.elektormagazine.com

Contents

Preface

Introduction

Chapter 1 • Installing the Raspberry Pi 4

1.1 Hardware description

1.2 Installing the operating system

1.3 Installing the VNC Viewer

1.4 Installing the File Transfer Software WinSCP

1.5 Installing the openplcproject runtime

Chapter 2 • OpenPLC Editor Installation

2.1 Download and Installation

2.2 Raspberry Pi pin descriptions

2.3 Additional Hardware I/O Test Board

2.4 Additional 24 V PLC Board hardware

Chapter 3 • The OpenPLC Editor

3.1 Description of the OpenPLC Editor

3.2 Ladder Logic Example (LD)

3.3 Function Block example (FBD)

3.4 Instruction List example (IL)

3.5 Structured Text examples (ST, SCL)

3.5.1 Variable

3.5.2 Control structures

3.5.3 Conversion operators

3.5.4 Standard function blocks according to IEC 61131-3

3.5.5 First ST program example

3.5.6 ST example for controlling a conveyor belt

3.5.7 Defining arrays with the OpenPLC Editor

3.5.8 Defining structures with the OpenPLC Editor

3.5.9 Combining structures with arrays using the OpenPLC Editor

3.5.10 Definition of ENUMs

3.6 Sequential Function Chart example (SFC)

Chapter 4 • OpenPLC and the Modbus

4.1 Testing PLC programs with Modbus TCP

4.2 Visualization of PLC programs with AdvancedHMI

4.3 Visualization of PLC programs via the Internet

Chapter 5 • Modbus I/O modules

5.1 Modbus RTU module with the Arduino UNO

5.2 Modbus TCP module with the ESP8266 and WLAN

5.3 Web server application with the ESP8266 I/O module

Chapter 6 • Bibliography

6.1 Web links

6.2 Modbus commands for the ESp8266 I/O module

6.4 Circuit diagrams and layouts

6.4.1 Circuit diagram for the test board with buttons and LEDs:

6.4.2 Circuit diagram for the test board with 24V input outputs:

6.4.3 Circuit diagram for the ESP8266 board with 24V input outputs:

Preface

This book is intended to provide readers with a practical introduction to using the Raspberry Pi computer as a PLC (programmable logic control) for their projects.

The project is indebted to programmers Edouard Tisserant and Mario de Sousa. They started the "Matiec project" after the introduction of IEC standard 61131-3 in 2003. This made it feasible to translate the programming languages introduced in the standard into C programs.

Later, when the Raspberry Pi became increasingly popular, Thiago Alves started the "openplcproject". He extended the editor from the "Beremiz" project and wrote a runtime library and a web interface for the Raspberry Pi and the PC. From then on, it was possible to write programs on the PC and install them on the Raspberry Pi.

Many Raspberry Pi users are now able to realize their own controls and regulation systems using their own hardware. The hardware and software are also excellent for training purposes because it abides by the IEC standard.

Beginners will also learn everything about installation and programming in the five programming languages in order to build their own control systems.

In a later chapter, the visualization with AdvancedHMI is discussed to display processes on the screen.

Circuits with the Arduino and ESP8266, which are necessary for Modbus, are also explained.

I wish you lots of success in reading and using the book.

Bad Abbach, May 2021Josef Bernhardt

Introduction

Programmable logic controllers (PLCs) have revolutionized industrial control technology. PLCs have been used primarily in industrial control systems and home automation since their invention by Richard E. Morley about 50 years ago.

Here is the definition of "PLC" according to EN61131-3:

"A PLC is a digitally operating electronic system for use in industrial environments with a programmable memory for internal storage of user-oriented control instructions to implement specific functions such as logic control, sequence control, timing, counting, and arithmetic functions to control various types of machines and processes through digital or analog input and output signals."

The Raspberry Pi is perfectly suitable for an application as a PLC because of its architecture with the GPIO connector, as well as its low price.

Various ready-made PLCs based on the Raspberry Pi are available on the market.

A big advantage of PLC programming is that the programmer does not have to learn the hardware details of I/O lines. The analog and digital outputs and inputs are like variables. This is also possible with modules that are connected to the Raspberry Pi via a network using a protocol such as Modbus-TCP.

Another advantage of PLC programming is the inter-compatibility of PLC systems. Programs for a PLC from manufacturer "A" can generally be used for PLCs from manufacturer "B" without much effort.

Figure 0.1: Raspberry Pi PLC Unipi 1.1.

Figure 0.1 pictures a PLC with 24V inputs and relay outputs attached to a Raspberry Pi.

Most PLC systems support graphical and textual programming languages. The "openplcproject" fully supports the IEC 61131-3 standard, which defines basic software architecture and programming languages for PLCs.

Figure 0.2: Overview OpenPLC.

The system consists of a runtime component, which is basically the software installed on the Raspberry Pi. This executes the PLC program. The program editor is installed on the PC under Windows or Linux to write the PLC program according to the IEC 61131-3 standard.

The following PLC languages are supported:

Programming language

Abbreviation

Ladder Logic

LD

Function Block

FBD

Instruction List

IL

Structured Text

ST

Sequential Function Chart

SFC

Figure 0.3: IEC programming languages.

Graphical languages KOP and FUP are translated to ST by the Matiec compiler.

Chapter 1 starts with the installation of the runtime component on the Raspberry Pi. After downloading the installation program, you will create a micro SD card with the operating system. After commissioning, you will install the PLC Runtime and perform the first test.

Next, you will deal with the editor and its user interface in Chapter 2. You'll get to download a finished example and translate it into a program for transferring to the Raspberry Pi.

In Chapter 3 you start programming with the PLC editor from "openplcproject". You will create your programs in various programming languages, translate, and upload them to the Raspberry Pi for testing.

Visualization should not be neglected in the process, and Chapter 4 examines the AdvancedHMI project which allows you to visualize processes running on the PLC via Modbus, on a PC.

Chapter 5 examines the possibility of communicating with external modules. You'll be using the popular Modbus/RTU protocol for Arduino UNO and the Modbus/TCP protocol for ESP8266 via WLAN. Also, circuits and layouts for this hardware are presented.

All program examples can be downloaded from the author's website. The links to the website are in the Appendix under "Web Links".

Chapter 1 • Installing the Raspberry Pi 4

1.1 Hardware description

The Raspberry Pi is now a well-known minicomputer, which, thanks of its low price, is widely used by hobbyists and industrial companies alike.

Figure 1.1: The Raspberry Pi 4.

The RPi 4 has enough interfaces to be used as a PLC. In addition to standard interfaces such as HDMI, USB, Ethernet, and audio, it has a 40-pin GPIO connector strip to connect to the outside world. Relays, buttons, switches, etc. can be connected to this connector via suitable interfaces. Hardware aspects are not discussed further for now — the Raspberry Pi website is host to several detailed tutorials about this minicomputer.

If you are looking for a more compact solution, you could also use the Raspberry Pi Zero W. After a first test by the author, everything turned out to work fine. If you can tolerate the lengthy installation process which takes several hours, the "W" is a good, low-priced alternative to the Raspberry Pi 4.

Figure 1.2: Raspberry Pi Zero W.

To use the Raspberry Pi as a PLC, first install the operating system, which can be found on the Raspberry.org website. Link: Raspberry Pi OS – Raspberry Pi.

1.2 Installing the operating system

Download the Raspberry Pi Imager here. This is a simple and quick way to install the operating system on a Micro SD card. There is also a video about this on YouTube. Link:

https://www.youtube.com/watch?v=J024soVgEeM

After downloading, change to this directory and start the imager.

Link: https://downloads.raspberrypi.org/imager/imager_1.5.exe

Figure 1.3: Raspberry Pi Imager launched.

After clicking on "Install", the installation of the Imager program will commence. The Imager is used to install our Micro SD card.

Figure 1.4: Raspberry Pi Imager Setup.

With a click on the checkbox "Run Raspberry Pi Imager" the program launches after successful installation.

Select the Raspberry Pi OS (32-bit) as the operating system. Then select the drive where the Micro SD card is connected. Here, that's drive G:

Figure 1.5: Raspberry Pi Imager OS selection.

Click the "Write" button to launch the installation.

Figure 1.6: Raspberry Pi Imager startup.

Confirm the security prompt with "YES".

Figure 1.7: Writing to the SD card using the Raspberry Pi Imager.

Now the operating system is downloaded and written to the micro SD card. This can take about 30 minutes, depending on the computer. After the signal that writing to the card has been completed, exit the Imager with "CONTINUE".

Documentation for installation and usage can also be found here. Link: Raspberry Pi Documentation

The next step is to set up the Raspberry Pi. Insert the programmed Micro SD card into the Raspberry Pi. Next, plug in a monitor, keyboard, and mouse for the first setup of the Raspberry Pi.  Now connect the 5V power supply to the Raspberry Pi. The operating system should boot.

After the initial start, the operating system prompts for the country and time zone selection. Enter your details here. Now the settings are installed. After this, the password is requested. The default username is "pi", and the password is "raspberry".

If there is no Ethernet connection, set up the network access via WLAN. In the upper right corner between the Bluetooth and the speaker icon, click on the WLAN icon. Select your WLAN network and enter the access code. After a few seconds, the connection to the home or office WLAN is established. Continue with the installation of the updates. This can take several minutes. After this, a reboot is performed. When you click on the WLAN icon, you will also see the IP address. Make a note of it for later use with VNC and the PLC software, which is yet to be installed. Here, the IP is: 192.168.178.89.

Later, when the Raspberry Pi is used as a PLC, it will be easier to access it through VNC Viewer.

Follow: Menu → Settings → Raspberry Pi Configuration. Next, under Interfaces, the VNC Viewer can be enabled.

1.3 Installing the VNC Viewer