Codesys YouTube RoadMap 13feb24
Codesys YouTube RoadMap 13feb24
CODESYS
Tohid Alizadeh
1 Introduction 8
1.1 Creating a first project . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Exporting and Importing projects . . . . . . . . . . . . . . . . . 9
1.3 Declaring constant variables . . . . . . . . . . . . . . . . . . . . . 9
1.4 Declaring Array type variables . . . . . . . . . . . . . . . . . . . 9
1.5 Creating Global variable list . . . . . . . . . . . . . . . . . . . . . 9
1.6 How to create and use Function blocks in the project . . . . . . . 10
1.7 Protecting the project with password . . . . . . . . . . . . . . . . 10
1.8 Uploading and downloading the source project to PLC . . . . . . 10
4 Structured Text 15
4.1 Hello ST (the simplest example) . . . . . . . . . . . . . . . . . . 15
4.2 Using Set and Reset instructions in ST . . . . . . . . . . . . . . . 15
4.3 Self-holding program in ST . . . . . . . . . . . . . . . . . . . . . 15
4.4 Using For loop instruction in ST . . . . . . . . . . . . . . . . . . 15
4.5 Using TON and CTU instructions in ST . . . . . . . . . . . . . . 16
4.6 Declaring and using ”Structure” in the structured text (ST) pro-
gramming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1
4.7 IF-ELSEIF instruction in Structured text programming . . . . . 16
4.8 Using CASE instruction in ST . . . . . . . . . . . . . . . . . . . 16
4.9 Using While-Do loop instruction in ST . . . . . . . . . . . . . . . 16
4.10 Using Repeat-Until loop instruction in ST . . . . . . . . . . . . . 16
4.11 Using Jump (JMP) instruction and comments in ST . . . . . . . 16
4.12 Using Return instruction and comments in ST . . . . . . . . . . 17
4.13 Using SHift Left (SHL) and SHift Right (SHR) instructions in ST 17
4.14 Unit Conversion in Structured Text (ST) . . . . . . . . . . . . . 17
4.15 Creating and using function blocks in ST . . . . . . . . . . . . . 17
4.16 Creating and using Functions in Structured Text (ST) . . . . . . 17
4.17 R Trig and F Trig (Rising and falling edge detection) instructions
in Structured Text (ST) . . . . . . . . . . . . . . . . . . . . . . . 18
4.18 Using Hysteresis Function Block in Structured Text (ST) . . . . 18
7 Instruction List 26
7.1 Basics of Instruction List . . . . . . . . . . . . . . . . . . . . . . 26
2
8 Visualization 27
8.1 Displaying dynamic values (in the Text field) . . . . . . . . . . . 27
8.2 Controlling the visibility of objects . . . . . . . . . . . . . . . . . 27
8.3 Creating a vertical Bar display . . . . . . . . . . . . . . . . . . . 27
8.4 Controlling the movement (position) of objects . . . . . . . . . . 28
8.5 Creating momentary switches (NC and NO) . . . . . . . . . . . . 28
8.6 Using ComboBox integer to manipulate the value of an integer
variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
8.7 Using SpinControl to manipulate the value of an integer variable 28
8.8 Using Trace to display variables as graphs . . . . . . . . . . . . . 29
8.9 Working with images . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.10 Using the Frame element . . . . . . . . . . . . . . . . . . . . . . . 29
8.11 Enabling Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.12 VisuSymbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.13 Controlling the color of objects . . . . . . . . . . . . . . . . . . . 29
8.14 Text Display Animation . . . . . . . . . . . . . . . . . . . . . . . 30
8.15 Calling a Dialog Box (and using Date Picker) . . . . . . . . . . . 30
8.16 Combo Box Array . . . . . . . . . . . . . . . . . . . . . . . . . . 30
8.17 Getting User Input (Numeric value) in Visualization . . . . . . . 30
8.18 Saving and Loading Data Using Trace . . . . . . . . . . . . . . . 31
8.19 Rotate and Scale visualization elements . . . . . . . . . . . . . . 31
8.20 Adding/removing edges to/from polygon, polyline, and Bezier
curve elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
8.21 Switching between Visualizations . . . . . . . . . . . . . . . . . . 32
8.22 Navigating among Visualization windows using Combo Box In-
teger and Text List . . . . . . . . . . . . . . . . . . . . . . . . . . 32
8.23 Momentary versus Maintained switches - Convert a maintained
switch into a momentary one . . . . . . . . . . . . . . . . . . . . 33
8.24 Switching between Languages . . . . . . . . . . . . . . . . . . . . 33
8.25 Browsing web using Web Browser element . . . . . . . . . . . . . 33
8.26 Using Radiobutton . . . . . . . . . . . . . . . . . . . . . . . . . . 33
8.27 Color Management . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3
9.12 CFC programming example - Tank Simulation . . . . . . . . . . 38
9.13 String Animation Example . . . . . . . . . . . . . . . . . . . . . 38
11 SoftMotion 42
11.1 Introduction to SoftMotion with CFC . . . . . . . . . . . . . . . 42
11.2 Analog clock simulation . . . . . . . . . . . . . . . . . . . . . . . 42
11.3 Using MC PositionProfile function block . . . . . . . . . . . . . . 42
11.4 Robotics - An introductory tutorial: Simulating SCARA-2 robot 43
13 Miscellaneous 47
13.1 Network Variables - Communicating between two CODESYS PLCs 47
13.2 Node-RED - PLC to PLC communication using Node-RED and
OPC UA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
13.3 Node-RED - Installing Node-RED, importing missing nodes, and
communicating between Node-RED and CODESYS through OPC
UA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
13.4 OPC UA - Configuring CODESYS PLC as an OPC UA Server . 48
13.5 Text List - Dynamic Text . . . . . . . . . . . . . . . . . . . . . . 48
13.6 An introduction to Recipes - Part 01 - Recipe management through
Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
13.7 Refactoring (Updating the name of a variable or an object in the
whole project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
13.8 Geographical distribution of channel viewers . . . . . . . . . . . . 49
4
14 Additional Resources 50
14.1 CODESYS online help and CODESYS Forum . . . . . . . . . . . 50
14.2 Facebook Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
14.3 CODESYS group YouTube Channel . . . . . . . . . . . . . . . . 50
14.4 Jakob Sagatowski YouTube channel . . . . . . . . . . . . . . . . 50
14.5 Gary Pratt YouTube channel . . . . . . . . . . . . . . . . . . . . 51
14.6 Brian Hobby YouTube channel . . . . . . . . . . . . . . . . . . . 51
14.7 SquishyBrained YouTube channel . . . . . . . . . . . . . . . . . . 51
14.8 Carlos Abner YouTube channel . . . . . . . . . . . . . . . . . . . 51
5
Foreword
CODESYS is becoming more and more popular in the industrial automation do-
main as one of the main brand-independent platforms for implementing indus-
trial automation projects. Over the last six years, I have created video tutorials
and uploaded them on my Youtube channel (www.youtube.com/@TohidAlizadeh)
to help my students, among others, understand the usage of CODESYS. I have
classified the videos using YouTub playlists to help the viewers find the video
that helps them in achieving a specific task easily. However, I have received
many requests from the audience to create a kind of road map for using the
video tutorials in a more organized way. Therefore, I am preparing this docu-
ment and will update it occasionally, to provide a guideline for using my video
lectures. This guideline will be heavily based on my published videos, but
eventually, it could be used as a reference to learn PLC programming using
CODESYS.
I will try to keep this document short and to the point, avoiding additional
explanations, and will keep it freely available!
Videos are categorized into 13 classes and the details about each class are pro-
vided in a chapter. I also have updated the thumbnails for the videos and
introduced color coding to distinguish between the videos. In the image shown
on the next page, you can see how the color coding is considered.
Please don’t forget to SUBSRIBE and share the videos to support me.
6
Color coding used in the video thumbnail for each chapter
7
Chapter 1
Introduction
8
based application. Follow this video tutorial to learn more details and the steps
you need to take to add a visualization to the project as well. After watching
the video you should learn how to create an empty project, where to develop
the code and how to insert a very simple visualization, and then how to compile
and run the code in the Simulation mode.
Click here to watch the video on YouTube
9
the project. In this video, you will learn how to create the Global variable list
and call the variables in the program.
Click here to watch the video on YouTube
10
Chapter 2
11
2.4 Set/Reset or Latch/Unlatch instructions in
Ladder logic
In this video, you will learn how the Set/Reset or Latch/Unlatch coil instructions
can be used in Ladder logic.
Click here to watch the video on YouTube
12
2.9 TOF (timer off-delay) function block in Lad-
der logic
In this video, you will see how to use the TOF (off-delay timer) function block
in CODESYS.
Click here to watch the video on YouTube
13
Chapter 3
14
Chapter 4
Structured Text
15
4.5 Using TON and CTU instructions in ST
In this video, you will learn how to use the TON and CTU instructions (func-
tions) in the structured text.
Click here to watch the video on YouTube
16
4.12 Using Return instruction and comments in
ST
In this video, you will learn how to use the Return instruction in ST.
Click here to watch the video on YouTube
17
4.17 R Trig and F Trig (Rising and falling edge
detection) instructions in Structured Text
(ST)
In this episode, I will show you how to use the edge detection instructions in
the structured text (ST) in CODESYS. First I will explain the way in which
these instructions operate, and then using an example, I will explain how these
instructions could be used. I have also created a simple visualization for the
example project. After watching the video, you are asked to extend the project
and introduce additional features.
Click here to watch the video on YouTube
18
Chapter 5
19
5.3 Implicit variables in Steps
In this video, you will learn about the Implicit variables in the SFC. You will
learn how to use two kinds of implicit variables (state and time) available for the
Steps in SFC. Everything is explained through the traffic light control system
example.
Click here to watch the video on YouTube
20
Chapter 6
Continuous Function Chart (CFC) is a language similar to FBD but with greater
flexibility. It is not a standard PLC programming language, but quite useful
and popular.
Click here to watch all the videos on YouTube in a Playlist
21
6.4 Selector element in CFC programming
In this short video, you will learn how to use the Selector element in the CFC
programming environment. The selector is an element in CFC that helps to
separate the fields of a structure variable.
Click here to watch the video on YouTube
22
that one could become TRUE only if the other one is False. A typical example
would be the elevator: The door of the elevator should not be opened while the
cabin is moving, and the cabin should not move while the door is open. In the
video, I also show how to implement the same function block using the CFC
programming language.
Click here to watch the video on YouTube
23
array. I have used FIFO 16 in this example, but you can use whichever fits your
needs. The FIFO function block has several inputs and three outputs.
I have used a slider to determine the value of the input data and buttons to
read or write the data into the array. Since FIFO is not provided by CODESYS,
you need to download (from oscat.de) and install the OSCAT library and add
it to the project, as described in the video. You can also use this function block
using another programming language such as FBD or ST, just like the other
function blocks.
Click here to watch the video on YouTube
24
input string.
Click here to watch the video on YouTube
25
Chapter 7
Instruction List
Instruction List (IL) is a textual standard PLC programming that is not widely
used these days, mostly due to its very basic way of writing commands.
26
Chapter 8
Visualization
27
vertically.
Click here to watch the video on YouTube
28
8.8 Using Trace to display variables as graphs
In the HMI panels or visualization screens, you may need to display some process
variables as graphs. Trace is one of the elements which is used for this purpose.
In this video, you will learn how to use the Trace element, and how to configure
it to display the variables as a graph, changing over time.
Click here to watch the video on YouTube
8.12 VisuSymbols
In this video, you will learn how to include the VisuSymbols in the visualization
of CODESYS, which would save you time later.
Click here to watch the video on YouTube
29
8.14 Text Display Animation
In this short video, you will learn how to use the text display animation in the
visualization of the CODESYS. The basic idea is to change the font size of the
text in the display, which could be associated with an integer variable. The
font size is one of the properties of the text, which is visible when you have the
Expert view checked. In this simple example, a Pulse timer is used to generate
the clock pulse, and the MOD operator is used to keep the value of the size
below a given value.
Click here to watch the video on YouTube
30
new value into a variable. Different options are explained in the video.
Click here to watch the video on YouTube
31
element in the visualization toolbox, and left-click in the visualization window.
For each left mouse click, one edge will be added. To stop, do a right mouse
click. In order to remove one edge from any of those elements, you need to hold
the CTRL and Shift keys down and do a left-mouse click. With each click, one
edge will be removed. In this way, you can create your desired visualization
elements easily.
Click here to watch the video on YouTube
32
8.23 Momentary versus Maintained switches -
Convert a maintained switch into a mo-
mentary one
In this video tutorial, you will learn to convert maintained or stationary switches
into momentary ones which behave like pushbuttons. You can do this by chang-
ing the ”element behavior” property of the switch from ”Image Toggler” to
”Image Tapper”.
Click here to watch the video on YouTube
33
8.27 Color Management
In this video tutorial, you will learn to control the color of visualization elements
during the runtime, in the visualization, using sliders to determine the Red,
Green, Blue, and transparency, separately. To do so, you need to get this
information in the form of Bytes, then combine them with each other, using the
pack bytes to dword function from the CAA Memory library, and obtain a value
for the color variable. I have explained this in another video tutorial with the
title of packing/unpacking bytes to dword. Check that out if you need further
clarification 6.15.
Click here to watch the video on YouTube
34
Chapter 9
PLC programming
examples
In this chapter, the PLC programming examples, created using different stan-
dard PLC programming languages are collected.
Click here to watch all the videos on YouTube in a Playlist
35
9.3 Simple LD programming example - using
On-delay timers
In this video, you will learn how to use the On-delay timers, through a very
simple example, using LD programming language. On-delay timers are the
most commonly used timers in PLC programming.
Click here to watch the video on YouTube
36
9.7 Structured Text (ST) programming exam-
ple - Traffic light control
In this video, you will learn how to develop a simple PLC program using Struc-
tured Text (ST) programming language. The example system is the traffic light
control in an intersection, where there are one north-south and one east-west
traffic light set. The code in LD is provided. Four on-delay timers are used to
create the sequence.
Click here to watch the video on YouTube
I think I have provided enough explanations in the video, if you need more,
you can refer to Jamal directly. Here is the updated Dropbox link:
Click here to download the project
37
9.10 SFC programming example- Traffic light
control in the intersection
In this video, you will learn how to develop a PLC program using Sequential
Function Chart (SFC) programming language. Creating the project, adding
Steps and Transitions, creating Parallel branches, Adding different types of
Actions, and determining a background image in the visualization are covered
in this video. Everything is explained through the traffic light control system
at an intersection.
Click here to watch the video on YouTube
38
Chapter 10
In this chapter, you can find samples of course projects done by undergraduate
students at the department of robotics and mechatronics of Nazarbayev Univer-
sity. A brief explanation and demonstration are provided to give you an idea of
what could be done with CODESYS.
Click here to watch all the videos on YouTube in a Playlist
39
10.3 Sample project 03 - Postal mail sorting -
open source code
The source code for this project is released now! You can get the source code
by following the link in the first comment.
In this video, I will explain to you in brief one of the course projects for the
industrial automation course, to give you a sense of what you can do with
CODESYS in the simulation mode. The project is about sorting items in a
postal station.
Click here to watch the video on YouTube
40
10.7 Sample project 07 - Computer Vision with
Python and CODESYS
In this video, I am demonstrating a course project for an industrial automation
course, done by three undergraduate students at Nazarbayev University (NU).
They have simulated a computer vision scenario using Python, CODESYS, and
UaExpert.
The aim is to have a conveyor belt on which bottles will be transported. There
is a simulated proximity sensor to detect that a bottle has reached a specific
position, where there is also a camera located. Then the camera is used to
take a photo of the bottle and provide it to Python code which is written to
determine whether there is a label attached to the bottle or not. If there is no
label, then the bottle will be ejected, otherwise, it will continue moving on the
conveyor, as you see in the example demos.
Click here to watch the video on YouTube
41
Chapter 11
SoftMotion
42
are considered as delta time or the time difference between going from the last
position to the current one. The position can be dealt with as absolute or rel-
ative. The main input to the function block, apart from the ”Axis” input, is
the TimePosition, which is of the ”SM3 Basic.MC TP REF” type. In the visu-
alization, an element is provided to determine the inputs to the function block
through the operator. The example provided here is a simple one, just to show
how the function block could be used and accessed through the visualization.
Click here to watch the video on YouTube
43
Chapter 12
Debugging and
Troubleshooting
This chapter includes videos created for debugging, monitoring, and troubleshoot-
ing.
Click here to watch all the videos on YouTube in a Playlist
44
12.3 Debugging the code in the structured text
(ST) in ST
In this video, you will learn the basics of debugging in the Structured Text
programming environment in CODESYS.
Click here to watch the video on YouTube
45
12.7 Visualization Issue - Resolution 02
Here is a solution to the visualization issue of the latest version of CODESYS
(3.5.7), thanks to my student Roman Kruchinin, who found it on CODESYS
forum. You do not need to have the older versions installed and switch back
to those versions.
Click here to watch the video on YouTube
46
Chapter 13
Miscellaneous
This chapter contains videos that can’t directly be categorized in the previous
chapters.
Click here to watch all the videos on YouTube in a Playlist
47
13.3 Node-RED - Installing Node-RED, import-
ing missing nodes, and communicating be-
tween Node-RED and CODESYS through
OPC UA
Node-REd is a relatively new platform that is becoming very popular in the
field of industrial IoT, or IIOT. It provides an environment to develop graphical
flow-based applications and establish industrial communications.
In this video, you will learn about Node-RED and how to install it on your
computer at first. Then, I demonstrate how to create a new project in the
Node-RED environment, how to import nodes for OPC UA and dashboard,
how to create your first flow, and establish the communication between Node-
RED and CODESYS.
Click here to watch the video on YouTube
48
13.6 An introduction to Recipes - Part 01 - Recipe
management through Visualization
In this video tutorial, you will learn Recipes, how to add them to a project, and
how to manage them through visualization.
Click here to watch the video on YouTube
49
Chapter 14
Additional Resources
In this chapter, you can find a list of additional resources for learning CODESYS.
50
a complete course containing 18 parts on his channel. I strongly recommend
watching his videos.
51