The Siemens SIMATIC IOT2020 is an Internet-of-Things gateway designed for industrial operation. It has network capabilities, can make use of Arduino shields and can run both Linux and Arduino code.
Using the IOT2020, I am creating an expandable energy monitoring gateway, with configurable warnings and alarms, covering all the basics of getting the IOT2020 up and running.
These are the things you’ll need in order to get started with this IOT2020 project:
Software:
- Arduino IDE
- Fusion 360
- IOT2020 Software Image
Hardware:
- Siemens SIMATIC IOT2020
- microUSB cable
- 24V/2.5A power supply + female DC barrel jack connector
- microSD card
- FTDI cable or breakout board
- Arduino Proto Shield
- I2C LCD Display or equivalent
- USB Wifi dongle
Tools:
- 3D Printer
- Soldering Iron
- hobby knife
Go to the Siemens website and download the latest example image for the IOT2020 (2.1.3 at time of writing). This image is required to run the Linux operating system of the device.
Using a tool like Etcher, the image can be burnt onto a microSD card. Note you may have to change the extension from *.wic to *.img for Etcher to be able to use the image.
After flashing the image, insert the microSD card in the device.
Powering the unitThe unit supports a big range of input voltages: 9 to 36V DC
This can be achieved using a regular power supply with the help of a female barrel jack adapter, or using a DIN rail power supply.
ArduinoArduino IDETo load Arduino sketches on the IOT2020, the Arduino IDE is required.
Go to arduino.cc, download and install the latest version (1.8.2 at time of writing).
Once installed, support for the IOT2020 needs to be added, which boils down to adding support for the Galileo Gen2 board.
Go to Tools > Board > Boards Manager and search for “galileo”. Install the package.
To test the installation and verify Arduino code can be loaded onto the IOT2020, the “blink” sketch is a good place to start.
Load the sketch from File > Examples > 01. Basics > Blink and upload it to the IOT2020, making sure the following settings are set in the “Tools” menu:
- Board: Intel Galileo Gen. 2
- Programmer: AVRISP mkII
The “USER” LED should start blinking on the IOT2020, indicating the upload was successful and it is running the chosen Arduino sketch.
LinuxFTDIAn FTDI header is foreseen on the IOT2020, allowing the user to connect to the Linux potion of the device by means of serial connectivity.
In this example, I’m making use of the Sparkfun “Beefy 3” FTDI breakout board.
On OSX and Linux, it is possible to connect via the “screen” command, providing the correct device and baud rate are used:
Fredericks-Mac-mini:~ frederickvandenbosch$ screen /dev/tty.usbserial-DN018PFG 115200
Windows users would use PuTTY.
Once connected, the login prompt is presented. The default username is “root”, no password.
iot2000 login: root
root@iot2000:~#
A test command reveals the kernel name, version, etc …
root@iot2000:~# uname -a
Linux iot2000 4.4.18-yocto-standard #1 PREEMPT Thu Feb 2 07:22:31 CST 2017 i586 i586 i386 GNU/Linux
WifiNow that we’re connected, let’s configure the wifi in order to get rid of the FTDI breakout board.
Start by editing the wpa_wupplicant configuration file and providing the wireless network’s details.
root@iot2000:~# nano /etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1
network={
ssid="<your_ssid>"
psk="<your_passphrase>"
}
Save the file and edit the interfaces file next. At the end of the file, append the “wlan0” interface information as documented below.
root@iot2000:~# nano /etc/network/interfaces
# Wireless Interfaces
auto wlan0
iface wlan0 inet dhcp
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf
Save the file, plug in the USB WiFi dongle and reset the IOT2020.
Once booted, connect one last time using the serial connection, and request the IP information. If all went well, the “wlan0” interface should be up, with an IP address from the network.
root@iot2000:~# ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
inet 192.168.200.1/24 brd 192.168.200.255 scope global eth0
valid_lft forever preferred_lft forever
5: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
inet 192.168.0.194/24 brd 192.168.0.255 scope global wlan0
valid_lft forever preferred_lft forever
Try connecting via SSH using the IP address.
Fredericks-Mac-mini:~ frederickvandenbosch$ ssh root@192.168.0.194
The authenticity of host '192.168.0.194 (192.168.0.194)' can't be established.
ECDSA key fingerprint is SHA256:EIfpFu330zbMPSbWI74r7OMZovtYvzSj8hT5WRByD9s.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.194' (ECDSA) to the list of known hosts.
Last login: Fri Mar 31 16:32:48 2017
root@iot2000:~#
After confirming wireless connectivity is operational, remove the FTDI breakout board.
Custom LCD PanelIn order to add a local reporting element to the IOT2020, I modified an existing design to 3D print a custom panel capable of housing a 16×2 LCD display. Download link at the end of this post!
ModificationsThe original plate’s 3D model is available on the Siemens website and is free to download, but does require you to register for a free account first.
I imported the file into Fusion 360 and made following changes:
- added two tabs on the left side’s exterior to connect with the case
- made an opening for the LCD display
- added four tabs on the inside to snap LCD in place and hold it there
3D printing the panel requires support. I oriented the front side of the panel to lay on the printing bed, requiring the least amount of support material.
Once printed, the support material needs to be removed using pliers, and a bit of sanding paper helps smooth the surfaces. The LCD display can then be fitted.
With the LCD snapped into place, the wiring connections to the IOT2020 main board can be made, and the panel inserted back in the unit.
I’ve uploaded my version of the model to Thingiverse. Feel free to use it for your own project!
ConnectionsThe LCD display I’m using, uses an I2C backpack, drastically reducing the number of connections.
Four connections are required:
- 5V
- GND
- SDA
- SCL
Using a Proto Shield, clean connections can be made between the LCD and the IOT2020.
An Arduino library is required to control the LCD via I2C.
I found a library compatible with the Galileo here: https://github.com/marcoschwartz/LiquidCrystal_I2C
And even though the Arduino IDE might report is as incompatible, it does work as expected.
A quick Arduino sketch can be used to test the LCD:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
lcd.init(); // Initialize the lcd
lcd.backlight(); // Turn on backlight
lcd.setCursor(0,0); // Choose position.
lcd.print("Hello World!"); // Print a message to the LCD.
lcd.setCursor(0,1);
lcd.print("IOT2020 I2C LCD!");
}
void loop() {
}
After uploading the sketch to the IOT2020, the LCD displays the programmed text.
emonPi is an open-hardware energy monitoring solution based on the Raspberry Pi. It was originally launched as a Kickstarter around April 2015 and raised almost £25,000 with a £15,000 goal. It comes in different flavours, from board only to fully assembled device with custom aluminium enclosure. I have the board only, and will be using it in a combination with a Raspberry Pi Zero rather than the suggested Raspberry Pi 3.
The software side of thing is rather straightforward, as a Raspbian Jessie Lite image with all the emonPi software included is available for download.
The image offers a lot of software preconfigured and activated. It's good to take the time and disable whatever software components will not be required.
The filesystem needs to be made writeable first, in order to apply changes.
pi@emonpi:~ $ rpi-rw
Filesystem is unlocked - Write access
type ' rpi-ro ' to lock
Once that's done, the unused software components can be disabled.
pi@emonpi:~ $ sudo systemctl disable openhab.service
pi@emonpi:~ $ sudo systemctl disable nodered.service
pi@emonpi:~ $ sudo systemctl disable emonPiLCD.service
pi@emonpi:~ $ sudo systemctl disable apache2.service
This leaves the MQTT portion of the emonPi running, while disabling the rest.
When finished, the filesystem should be made read-only again.
pi@emonpi:~ $ rpi-ro
Filesystem is locked - Read Only access
type ' rpi-rw ' to unloc
MQTTUsing MQTTLens, it is possible to verify emonPi is sending out the monitoring values.
With following settings applied, we can subscribe to the broker:
- URL: tcp://<emonpi>:1883
- User: emonpi
- Password: emonpimqtt2016
- QoS: 2
Node-RED is a tool used to wire together different devices, APIs or online service in a visual way.
To start Node-RED on the IOT2020, the following command is used.
root@iot2000:~# node /usr/lib/node_modules/node-red/red &
It requires some time to start up, but once completed, the GUI can be accessed using a browser and pointing it to the IP address of the IOT2020 on port 1880.
Using various building blocks, different flows can be created.
In this particular case, the input is MQTT, which is then parsed, and the values fed to text files.
These two text files contain the monitoring values of each sensor. They are stored into files, in order to pass them to the Arduino side and be able to display these values on the LCD display.
Data sharing: Linux to ArduinoIt is possible to exchange data between the Arduino and Linux environments of the IOT2020.
Passing data from the Arduino to Linux side is done using the "system" command. From Linux to Arduino, is done using text files.
In the previous step, the sensor data was stored in text files. These can now be read from the Arduino side, for display on the LCD which was set up earlier.
The code to read both files and display the values on the LCD is the following:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
FILE *file;
int c;
LiquidCrystal_I2C lcd(0x27,16,2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
lcd.init(); // Initialize the lcd
lcd.backlight(); // Turn on backlight
}
void loop() {
String sensor1 = readFile("/home/root/emonpi_sensor1.txt");
String sensor2 = readFile("/home/root/emonpi_sensor2.txt");
lcd.clear();
lcd.setCursor(0,0); // Choose position.
lcd.print("Room 1:");
lcd.setCursor(8,0);
lcd.print(sensor1); // Print a message to the LCD.
lcd.setCursor(15,0);
lcd.print("W");
lcd.setCursor(0,1); // Choose position.
lcd.print("Room 2:");
lcd.setCursor(8,1);
lcd.print(sensor2); // Print a message to the LCD.
lcd.setCursor(15,1);
lcd.print("W");
delay(1000);
}
String readFile(const char* path){
// Based on https://raw.githubusercontent.com/MakersTeam/Galileo/master/Arduino-Examples/DataSharing.ino
String file_output;
file = fopen(path,"r"); // Read file from Linux side
if (file) {
while ((c = getc(file)) != EOF) { // Keep reading until the end of the file
if(c != 10) { // Detect if it is a new line character
file_output += (char)c; // Only the last line will be returned. Modify this for custom purposes.
}
}
fclose(file);
}
// Return the data read
return file_output;
}
Once the sketch is uploaded, the sensor data should be displayed!
Expanding on the current Node-RED flow, notifications can be added, should certain value thresholds be crossed. The cool thing about Node-RED is that these notifications could be anything from Twitter, e-mail, etc ...
An additional switch acts as a configurable threshold to trigger an email containing the actual value of the reading.
The proof of concept is up and running.
Using a single MQTT broker, running on the IOT2020, multiple emonPis could publish their data to it. Node-RED could then subscribe to the different topics and use the new data.
Additionally, a custom dashboard in Node-RED can also be used for live and historic data, making it possible to discover patterns over time.
It was my first time working with an IOT2020 or Galileo for that matter, and while the learning curve is a bit steep, I did enjoy using it.
The combination of Arduino and Linux in a single device is an interesting one, especially as data can be exchanged between both environments. Arduino is perfectly suited for hardware control, and combined with the Linux side, the programming possibilities increase drastically.
I aimed to created a decent "getting started" base with this project, covering the things I have learned in the process. Hopefully this post will help out others who are getting their feet wet with the IOT2020.
The project combines different skills from programming, to (a little bit of) hardware and even 3D modelling and printing.
Thank you to Hackster and the sponsors for giving me the opportunity to test the IOT2020!
Comments