Create Control Program on IG21 with Structured Text
Summary
In this article, we will go through how to set up a control program on the IG21. Before you go through this article, please:
Purchase the recommended book and go through the instructions:
PLC Controls with Structured Text (ST): IEC 61131-3 by Tom Mejer
Learn more about Structured Text here
Control not currently supported on the IG41.
Structure Text Overview
The IG is a fully functional, cloud-managed PLC that allows users to develop programs using industry standard IEC 61131-3 language. Programs are developed on a central dashboard, and run locally on the device. This allows flexibility in remote management and program auditing, while ensuring that all control functionally happens locally onsite without dependencies on external connectivity.
Structured Text is an IEC 61131-3 language for programmable logic controllers. It provides high level, textual programming that is easy and simple to use and deploy.
Pre-Reading on Structured Text
Instructions below after you purchase PLC Controls with Structured Text (ST): IEC 61131-3 by Tom Mejer:
Data Types - Page 14 and 15 of the book by Tom Mejer Antonsen
Data Type Conversion - Page 50 of the book by Tom Mejer Antonsen
IF/Else Statements - Pages 53-57 of the book by Tom Mejer Antonsen
Timers = Pages 90-91 of the book by Tom Mejer Antonsen
How and where to access PLC programs on the IG
When in the Industrial section, select Automation. On this page, the programs and gateways with programs can be viewed and drilled into. This is also where new programs are created.

When creating a new program, select either Ladder Logic or Structured text:

This page allows you to write programs in Structured Text, view past revisions, and compile and deploy code. Samsara Structured Text Development Environment:

The development environment includes the program list in the left pane, text editor in the right pane and controls in the upper right. To save code, press the Save button in the upper right hand corner. The program will be saved for future use in the programs list. Once the code is compiled, select Deploy to run the program on the IG. For adding variables to the program, see Set up Local Variables and Set up Program Variables
When program is running, it can be stopped or started from the development environment or the program summary page.

Structed Text Example 1:
if fill > 0.0 then
pump1out := 1.0; pump2out := 1.0;
elsif fill < 0.0 then
pump1out := 0.0;
pump2out := 0.0;
end_if;

Structured Text Example 2:
var
ons : BOOL := false;
end_var
if tanklevel > highSP then
if ONS = true then
fill := -0.1;
ONS := false;
end_if;
fill := fill - 0.1;
elsif tanklevel < lowSP then
if ONS = false then
fill := 0.1;
ONS := true;
end_if;
fill := fill + 0.1;
end_if;
