Arduino OPTA PLC – Structured Text (ST)

Structured text (ST) programming is a programming language that is part of the IEC standard and is used in the Arduino Opta PLC. This programming language allows you to write code in a structured and organized manner, making it easier to understand and maintain. With structured text programming, you can create complex and sophisticated programs by combining statements, functions, and variables. Artificial intelligence (AI) can be easily used with structured text (ST). We will demonstrate how to use AI to get a sample program for quick modifications in our application. The Opta PLC provides high flexibility and control of your applications.
Arduino OPTA PLC - Structured Text (ST)

The Arduino Opta PLC supports structured text programming as one of the five programming languages in the IEC standard and Arduino C++. This lets you choose the programming language best suits your needs and preferences. Arduino C++ is a widely used programming language in the Arduino community and offers a vast library of functions and resources. Whether you program in structured text, Arduino C++, or any other language, the Arduino Opta PLC provides a powerful platform for developing automation and control applications. Its versatility and compatibility with different programming languages make it popular among developers and engineers.

In the following sections, we will explore how to start a new project in the Arduino Opta PLC and how to map the physical I/O in the PLC. These steps are essential for setting up the foundation of your project and ensuring proper communication between the PLC and the external devices.

The entire Arduino Opta IoT PLC Series is located here.
Previously in this series, we have discussed the following:
Opta Introduction Video
Arduino Opta IoT PLC Cutting Edge HardwareVideo
Arduino Opta Software InstallationVideo
Arduino Opta IoT PLC Quick Start Ladder LogicVideo
Easy Steps to Establish Communication between Arduino Opta IoT PLCVideo
Arduino PLC IDE Workspace: Unleash the Power!Video
Programming with the Arduino OPTA PLC – Ethernet PortVideo
Arduino OPTA PLC – Ladder Diagram First ProgramVideo
Arduino OPTA PLC – Instruction List (IL) First ProgramVideo
Arduino OPTA PLC – Function Block Diagram (FBD)Video
Note: A post is usually associated with each video. This will provide additional details and links discussed.

Start a new project

Our project will create a stop-stop circuit with two lighted pushbutton switches using structured text (ST) programming. When the green LED pushbutton is selected, the green LED light will turn on. This will remain on until the red-led push button is selected. When the green LED is on, the red LED is off, and vice versa. The CPU green LED will be on if the Arduino OPTA PLC is executing its program. Open your computer’s Arduino PLC Integrated Development Environment (IDE) software.
Opta New FBD Program
Start a new project by selecting “New Project” on the main software screen.
Opta New FBD Program
A second method of starting a new project is to select “New Project” from the main menu | File.
Opta New FBD Program
The third method is to choose the icon for a new project.
new st project
The new project window will now be displayed. Enter the name of the project in the dialog box. This will be the name of the Program stored on your drive. We will leave the default directory as it is. Ensure that the Opta 1.0 PLC is selected for the target. Select OK.
input and output naming for st program
This will now create and save your program file for the Opta PLC.

Mapping physically I/O in the OPTA PLC

The Opta has physical inputs and outputs we must map before using them in our project. In the workspace window, select the Resources tab at the bottom. Under local IO mapping, you will see all of the physical inputs and outputs on this controller.
input and output naming for st program
Select programmable inputs. The programmable inputs mapping will be displayed. We can assign a variable to each input we intend to use in our structured text program. Under IO type, we can select digital (default) or analog. The analog resolution can also be selected for the inputs.
input and output naming for st program
Select relay outputs that display the relay outputs mapping.
input and output naming for st program
We can once again assign a variable to the relays that we will use in our structured text program.
Select LED Outputs, which display the LED outputs mapping.
input and output naming for st program
These are the status lights on the Opta CPU unit. We will make these represent the relays in our Program. Assign a variable name to the LED output that we will use. The Opta PLC also has a front LED that can be different colors. We will assign the green output to indicate that the Opta PLC code is scanning.

Now that all of our mapping is complete, we can save the Program using the icon on the main page. We can also save the Program using the main menu | File | Save Program.

Wiring the Inputs and Outputs

We can now physically wire the two lighted pushbutton switches to the inputs and the LEDs of these switches to the outputs.
Arduino Opta Wiring
Here is the wiring diagram of the Arduino OPTA PLC.
Arduino Opta Wiring
The positive 24-volt DC signal is wired to one side of the green normally open switch contact. It is also wired to one side of the red normally closed switch contact. The other side of the switches are wired to input 1 and 2, respectively. The positive 24-volt DC signal is wired to one side of the switch lamps. Relay outputs are provided on the Arduino OPTA PLC. The other side of the switch LED lights are wired to one side of the relay for each switch. Green will be output one, and red will be output two. The other side of the relay output contacts of the PLC will be wired to the 0-volt DC signal. This completes the wiring of the PLC.

Tasks in the Opta PLC

To access the tasks in your project, navigate to the project tab and locate the tasks folder. You will see the list of IOs we have just mapped for this project.
st new program
Expand the folder by clicking on the plus sign next to it. The tasks are categorized into Fast, Slow, Background, and Init. To configure the tasks, right-click on any four task folders and select task configuration.
Arduino Opta PLC Tasks
Your programs will be executed within the designated task folders. The Fast Task folder will execute your programs cyclically every ten milliseconds. (100 times per second) This can be changed by changing the set period to yes. You can then enter a value in the period column in milliseconds. The majority of programs will be placed in this folder. The Slow and Background task folders will also scan cyclically. They are both set at a fixed period of 100 and 500 milliseconds. (10 times per second and two times per second) These tasks are ideal for functions like math equations, etc. The Init or Initialize task folder sets variables or conditions in the PLC after it powers up. It will run for a single scan. Select OK to close the task configuration window.

Starting a new Structured Text Program

Select | Project | New Object | New Program from the main menu to start a new program.
st new program
You can also do this by right-clicking on the project name and selecting the new Program under the add heading. The new program window will be displayed.
st programming
We will use a structured text (ST) in our example.
Select ST. Name and assign the new Structured Text program to the fast task folder. The program name cannot have spaces.
Select OK.
st structure
Our new structured text program will now be displayed in the work area. This Program also appears under the fast task folder and the project as a structured text symbol.
ST Programming Example
In the help menu, you will find all of the operators and their parameters that can be used for this structured text programming. Save the Opta PLC program.

Programming our Structured Text (ST)

Structured text (ST) is a high-level programming language widely used in programmable logic controllers (PLCs). It is a text-based language used to write programs for industrial control systems. One of the advantages of ST is that it is easy to learn and understand, making it a popular choice for many engineers and developers.
ST Programming Example
Generative artificial intelligence (AI) can be used to create sample programs using ST. This is because ST is a structured language that follows a set of rules and guidelines, making it an ideal candidate for machine learning algorithms. ChatGPT is a powerful AI tool that can be used to generate code in ST for a Start Stop circuit.
We can ask ChatGPT, “Write a structured text plc program for a start-stop circuit.”

Sure, I can provide you with a basic example of a structured text PLC program for a start-stop circuit. Keep in mind that the specific syntax and structure may vary depending on the PLC brand and model you are using. In this example, I'll use a generic syntax based on IEC 61131-3 standard.

Arduino OPTA PLC - Structured Text (ST)

Explanation:

StartButton is a boolean input representing the start button.
StopButton is a boolean input representing the stop button.
MotorOutput is a boolean output controlling the motor.
MotorRunning is an internal boolean variable indicating whether the motor is currently running.
The program checks the status of the start and stop buttons. If the start button is pressed and the motor is not already running, it starts the motor by setting MotorOutput to TRUE and updating the MotorRunning flag. If the stop button is pressed and the motor is running, it stops the motor by setting MotorOutput to FALSE and updating the MotorRunning flag.

Please note that the specific syntax and structure may vary depending on the PLC programming environment you are using. Make sure to adapt the code to the programming language and conventions supported by your PLC.

The response can give us an understanding of how structured text (ST) works. As our ST program, we will copy this directly into our Arduino PLC IDE software.
ST Programming Example
We can now modify the program for our application. Our input and output variables have already been defined. There is a local variable window to define the motor running.
Arduino OPTA PLC - Structured Text (ST)
We can now modify the code for our conditions to start the motor. (GreenOutput)
ST Programming Example
We can now modify the code for the conditions to stop the motor. The StopButton is wired normally closed (NC), so we will modify this condition.
ST Programming Example
The CPU LED green light can now be added to our program.
ST Programming Example
ST programming must account for all variables. We will now add an INIT program to initialize the variables. You will see that since the outputs are not set until the input signals and internal bit match, this must be set upon powering up the PLC.
ST Programming Example
Our initial startup of the PLC will turn the Red Output and Red LED Output on and the Green Output and the Green LED Output off.
Save the Program by using the icon on the main menu or selecting “Save project” from the main menu | File.

Download the ST program to the Opta PLC.

Select setup communication from the main menu | On-Line. In the device link manager window, select Modbus TCP and then select activate.
Arduino Communication Modbus TCP
Select properties.
Arduino Communication Modbus TCP
We can now enter the IP address we established in the following post. Programming the Arduino OPTA PLC – Ethernet Port Our communication method with the OPTA PLC is now set.
Arduino Communication
Select the connect button.

We will now see that our computer is connected to the Opta PLC controller.
Arduino OPTA PLC - Structured Text (ST)
Select the download icon on the main menu. Since we didn’t compile the project first, the PLC IDE prompts us before downloading. Select Yes.
Arduino OPTA PLC - Function Block Diagram (FBD)
The output window will display the status of the download operation.
Arduino OPTA PLC - Structured Text (ST)
When this has finished, the bottom right side of the software will show you that the PLC IDE and controller programs are the same.

Monitoring the ST Logic and Variables

Select the live debug mode on the main screen. This will show you the status of the inputs and outputs on the ST (Structured Text).
Arduino OPTA PLC - Structured Text (ST)
Select the watch icon on the main menu. This will display the watch window. We can enter and select the variables (tags) we want to monitor.
Arduino OPTA PLC - Function Block Diagram (FBD)
Watch the video below to see how to create structured text programs with the Arduino Opta IoT PLC.

Arduino Opta PLC – IoT and Industry 4.0 Enabler
Arduino Opto IoT PLC Series
Opta – Frequently Asked Questions (FAQ)

Finder OPTA 8A Series – Tutorials
Datasheet
Quickstart Sheet

Arduino Opta Hardware
Arduino PLC IDE
Arduino Software Download Page
(Arduino IDE, PLC IDE, PLC IDE Tools)

Watch on YouTube: Arduino OPTA PLC – Structured Text (ST) First Program

If you have any questions or need further information, please get in touch with me.
Thank you,
Garry


If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLCs are not challenging to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, decimals, Hexadecimal, ASCII, and Floating points.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available for free download. The link is included when you subscribe to ACC Automation.

Leave a Comment