Grafcet DIN EN 60848 on the SIEMENS IOT2020 and IOT2040¶
Read here how to use the Grafcet engine on the Siemens IOT2020/2040 and then download a Grafcet chart into the device.
You need Grafcet-Studio version 184.108.40.206 or newer!
How does it work?¶
As with the Raspberry Pi, a Python3 script is started and subsequently the IOT can be programmed via Grafcet-Studio using the Grafcet standard. The communication between Grafcet-Studio and the IOT is also realized via the MQTT protocol. See also the description for the Raspberry Pi.
The combination of IOT2020/IOT2040 and Grafcet Studio offers the following possibilities:
- Creation of Grafcet logic (step chain) with Grafcet Studio
- Download the Grafcet logic to the IOT (this only takes 1 second)
- Monitoring (debugging) of the Grafcet logic
- Any sensors and actuators that can be addressed via Python can be used also with the Grafcet logic (= no restrictions).
- The IOT can be addressed via the local network or via the Internet (MQTT makes it possible).
Further advantages of Grafcet Studio:
- Visual programming and debugging of the IOT.
- Simple and reduced user interface (UI) in Grafcet Studio (= simple usage).
- Use of the standard Grafcet DIN EN 60848: This standard is part of the curriculum of many technical professions in Germany.
- The documentation in Grafcet is at the same time the control program.
- Simulator integrated: You can simulate the Grafcet logic before transferring the Grafcet to the Device without hardware.
- Highly convenient development: The program can be transferred to the device within 1 second and runs autonomously there.
- Modern development environment: Vector-oriented UI based on Microsoft Windows Presentation Foundation (WPF).
- Target cross-platform: The created control program can be used without changes in another system (S7 PLCs from Siemens, Arduino Due, Raspberry Pi).
- The Python script allows all available shields to be used in the Grafcet logic.
- It is possible to add Python commands to the Grafcet logic. Example: If a certain event occurs in the Grafcet logic, an e-mail could be sent via Python.
- Several instances of the Grafcet engine can be created in the Python script, which are independent of each other. These different instances can communicate with each other if required.
- The Grafcet runtime (Grafcet engine) is free of charge for the device. Only the editor (Grafcet-Studio) has to be purchased (e.g. IoT-Edition for 99€ + VAT).
- Grafcet-Studio can be connected to a virtual system/machine in simulator mode. Thus the Grafcet can be checked very efficiently. See YouTube video
- Grafcet Studio Pro Edition or IoT Edition or Grafcet Studio Demo version
- IOT2020 or IOT2040 with Python3. (Python3 is already pre-installed on the IOT)
Installation of the operating system¶
- Download of the operating system (image). Link.
- Copy the image to an SD card (min. 16 GB). For writing the image you can use the Win32 Diskmanager.
- Download PuTTY. With this tool you can remote control the IOT via the SSH protocol. Link.
- Download an FTP program. This allows you to copy files from your PC to the IOT. Download link from FileZilla. 5.
- Insert the SD card and turn it on
For the setup of the SIEMENS IOT there is also a PDF from Siemens: Link.
The IP address of the IOT is preset to 192.168.200.1. You should therefore set your network card to the same subnet, e.g. 192.168.200.10. Tip: Connect a USB network adapter. The IP address of this adapter can then be set independently of your standard network card.
Enable MQTT Broker¶
If the connection with PuTTY is established, you can log in as "root". Then start the setup program by entering iot2000setup:
In the menu Software->Manage Autostart Options you can enable the option Auto start Mosquitto Broker:
After the reboot, the MQTT Broker is available. In Grafcet-Studio you can simply enter the IP address of the IOT2000 in the Device settings.
In the network settings you should set the new IP address to dhcp. Then the IOT receives a suitable IP address from the DHCP server in your local network. Via the log files of the router you can find out which IP address was assigned.
Installation of the MQTT Client¶
The Grafcet engine (Python3 script) communicates with Grafcet Studio via MQTT. Therefore the library "paho-mqtt" must be installed. This library is used by the Grafcet engine. Connect via PuTTY and enter the following command:
pip3 install paho-mqtt
Installing the Grafcet Engine (Python script)¶
Download the following ZIP file:
In the ZIP file you will find these files:
- grafcet_IOT2000.py = An instance of the Grafcet engine is created and used here.
- GrafcetEngineRuntime.py = Grafcet-Engine as Python code. The example grafcet_IOT2000.py uses this library.
|1||Import the Grafcet engine.|
|2||Creating a Grafcet Engine Instance.|
|3||Set MQTT connection. The 2nd and 3rd parameters must match the setting in Grafcet Studio.|
|4||In the loop: Editing the Grafcet logic.|
Note: This example script lacks access to the hardware inputs and outputs. The Grafcet engine provides functions (read_... and write_...) to write the Grafcet inputs and read the Grafcet outputs. So that the Grafcet logic can use the hardware inputs and outputs, the states (values) of the inputs must be written cyclically to the Grafcet inputs. And the states of the Grafcet outputs must be written to the hardware outputs. The description of the functions can be found here.
Set up the device in Grafcet-Studio¶
How to add the device in Grafcet Studio:
|1||Display the Grafcet Engine window and press the Plus button.|
|2||Select as Device: "Grafcet Engine MQTT".|
|3||Enter a name of your choice. This name will then appear later in the selection list|
|4||Press OK button|
|5||IP address of the IOT2000. The MQTT Broker (Mosquitto) must then be started on the IOT.|
|6||Topic1 is any identifier that must be identical in the Python script.|
|7||Topic2 is any identifier that must be identical in the Python script.|
In case of connection problems please check the following:
- Is the IOT2000 accessible via the IP address? PC and IOT must be in the same subnet. Example: IOT-IP: 192.168.2.118, PC-IP= 192.168.2.101
- Is the Mosquitto MQTT Broker on? After switching on in IoT2000Setup the IOT must be restarted.
- Is the Python script started?
- Is Topic1 and Topic2 identical in the Python script and in Grafcet Studio?
- Do IOT and Grafcet Studio use the same MQTT broker?