You are on page 1of 10

Application example  09/2016

SIMATIC IOT2000 I²C


example LED
SIMATIC IOT2020, SIMATIC IOT2040
Warranty and liability

Warranty and liability

Note The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any eventuality. The Application
Examples do not represent customer-specific solutions. They are only intended
to provide support for typical applications. You are responsible for ensuring that
the described products are used correctly. These Application Examples do not
relieve you of the responsibility to use safe practices in application, installation,
operation and maintenance. When using these Application Examples, you
recognize that we cannot be made liable for any damage/claims beyond the
liability clause described. We reserve the right to make changes to these
Application Examples at any time without prior notice.
If there are any deviations between the recommendations provided in these
Application Examples and other Siemens publications – e.g. Catalogs – the
contents of the other documents have priority.

We do not accept any liability for the information contained in this document.
Any claims against us – based on whatever legal reason – resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this Application Example shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life,
body or health, guarantee for the quality of a product, fraudulent concealment of a
 Siemens AG 2016 All rights reserved

deficiency or breach of a condition which goes to the root of the contract


(“wesentliche Vertragspflichten”). The damages for a breach of a substantial
contractual obligation are, however, limited to the foreseeable damage, typical for
the type of contract, except in the event of intent or gross negligence or injury to
life, body or health. The above provisions do not imply a change of the burden of
proof to your detriment.
Any form of duplication or distribution of these Application Examples or excerpts
hereof is prohibited without the expressed consent of the Siemens AG.

Security Siemens provides products and solutions with industrial security functions that
informa- support the secure operation of plants, systems, machines and networks.
tion In order to protect plants, systems, machines and networks against cyber
threats, it is necessary to implement – and continuously maintain – a holistic,
state-of-the-art industrial security concept. Siemens’ products and solutions only
form one element of such a concept.
Customer is responsible to prevent unauthorized access to its plants, systems,
machines and networks. Systems, machines and components should only be
connected to the enterprise network or the internet if and to the extent necessary
and with appropriate security measures (e.g. use of firewalls and network
segmentation) in place.
Additionally, Siemens’ guidance on appropriate security measures should be
taken into account. For more information about industrial security, please visit
http://www.siemens.com/industrialsecurity.
Siemens’ products and solutions undergo continuous development to make them
more secure. Siemens strongly recommends to apply product updates as soon
as available and to always use the latest product versions. Use of product
versions that are no longer supported, and failure to apply latest updates may
increase customer’s exposure to cyber threats.
To stay informed about product updates, subscribe to the Siemens Industrial
Security RSS Feed under http://www.siemens.com/industrialsecurity.

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 2
Table of contents

Table of contents
Warranty and liability ................................................................................................... 2
1 Task ..................................................................................................................... 4
1.1 Overview............................................................................................... 4
2 Application Example ......................................................................................... 5
2.1 Connecting I2C-board to SIMATIC IOT2000 ....................................... 5
2.2 Configure Jumpers on PCF8574 IO Expansion Board to set
address ................................................................................................. 5
2.3 Wire 3 LEDs to the PCF8574 IO Expansion board .............................. 6
2.4 Program the Application Example in Eclipse ....................................... 8
3 Checklist ............................................................................................................. 9
4 Related links ..................................................................................................... 10
5 History............................................................................................................... 10
 Siemens AG 2016 All rights reserved

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 3
1 Task

1 Task
1.1 Overview
Introduction
This application example shows how to execute a program using an I2C Bus to
enlighten 3 LEDs. This sample includes addressing an I2C-bus (PCF8574 IO
Expansion Board) and sending 1 byte (3 bits used for the 3 LEDs) to the bus to
power the LEDs.

Goals
After working through this document you will know how to
 Connect an I2C-bus (PCF8574 IO Expansion Board) to the SIMATIC IOT2000
 Configure Jumpers on PCF8574 IO Expansion Board to set address
 Wire 3 LEDs to the I2C-bus (PCF8574 IO Expansion Board)
 Initialize a byte in C/C++
 Addressing an I2C-bus in C/C++
 Writing a byte on the addressed I2C-bus
 Siemens AG 2016 All rights reserved

NOTICE Precondition!
To use this sample it is required that the Initial Operation in the Document
“Setting up the SIMATIC IOT2000” has been executed once.

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 4
2 Application Example

2 Application Example
This chapter describes how an application can be created with the Intel System
Studio IoT Edition.
For learning purposes, a basic I2C-bus example will be implemented in C/C++ that
is switching 3 LEDs connected to an I2C bus (PCF8574 IO Expansion Board)

2.1 Connecting I2C-board to SIMATIC IOT2000


Connecting the PCF8574 IO Expansion Board to the SIMATIC IOT2000

Connect the PCF8574 IO Expansion Board to the SIMATIC IOT200 as follow:


 Siemens AG 2016 All rights reserved

2.2 Configure Jumpers on PCF8574 IO Expansion Board to


set address
Jumper configuration
As we are using only one expansion Board we can set all jumpers to the value 0. If
required, use the Jumpers to change the address of the expansion board. There
are 3 solder jumpers: A0, A1 and A2. Each one of these is used to hardcode the
address. If the jumper A0 is switched to the + side the lowest bit is set with a value
of 1, A1 sets the middle bit with a value of 2 and A2 sets the high bit with a value of
4. The final address is 0x20 + A2 + A1 + A0. So for example if A2 is shorted and
A0 is shorted, the address is 0x20 + 4 + 1 = 0x25. If only A1 is shorted, the
address is 0x20 + 2= 0x22.

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 5
2 Application Example

2.3 Wire 3 LEDs to the PCF8574 IO Expansion board

Table 2-1
No. Action
1. Connect 3 LEDs to the expansion board as follow:
 Siemens AG 2016 All rights reserved

2. Example picture

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 6
2 Application Example
 Siemens AG 2016 All rights reserved

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 7
2 Application Example

2.4 Program the Application Example in Eclipse


Create a new project and insert the code
Create a new project in Eclipse as described in “SIMATIC IOT2000 Getting
Started”
Table 2-2
No. Action
1. Create a new project, here it is called “IOT_I2C_LED”

2. Insert the code in the *.cpp file


#include <iostream>
#include "mraa.hpp"

using namespace std;

int main()
{

uint8_t LED = 0;

mraa::I2c* i2c;
i2c = new mraa::I2c(0);
 Siemens AG 2016 All rights reserved

i2c->address(0x20); //set address of I2C-Slave (0x20: A0=0; A1=0; A2=0;)

while(1)
{
LED = 0x2; //PIN 0-7 on expansion board (0=GND; 1=VCC)
(B00000010)
i2c->writeByte(LED); //write/send byte to (0x20)

usleep(200000); //wait for 0.2s

LED = 0x5; //PIN 0-7 on expansion board (0=GND; 1=VCC)


(B00000101)
i2c->writeByte(LED); //write/send byte to (0x20)

usleep(200000); //wait for 0.2s


}
return 0;
}
3. Build the project (Ctrl+B)
4. Change storage location as described in “Getting Started”
5. Transfer and run the project to the SIMATIC IOT2000 by press the green “RUN”
Button
6. The connected LEDs are now powered on as the byte “LED” is set (If 0 = ON, if 1
=OFF)
7. In this example LED 1 and LED 3 are ON while LED 2 is OFF
Byte:(00000010)=(0x2) after a delay of 0.2s the Byte will change to
(00000101)=(0x5) now LED 1 and LED 3 get switched OFF and LED 2 gets
switched ON.

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 8
3 Checklist

3 Checklist
This chapter contains a Checklist which summarizes all important steps in this
application example.

Table 3-1
No. Action
1. Connecting I2C-board to SIMATIC IOT2000
2. Configure Jumpers on PCF8574 IO Expansion Board to set address
3. Wire 3 LEDs to the PCF8574 IO Expansion board
4. Program the Application Example in Eclipse
 Siemens AG 2016 All rights reserved

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 9
4 Related links

4 Related links
Table 4-1
Topic
\1\ SIMATIC IOT2000 forum
www.siemens.com/iot2000-forum
\2\ SIMATIC IOT2000 Setting Up
https://support.industry.siemens.com/tf/ww/en/posts/155642/
\3\ SIMATIC IOT2000 Getting Started
https://support.industry.siemens.com/tf/ww/en/posts/155643/

5 History
Table 5-1
Version Date Modifications
V1.0 09/2016 First version
 Siemens AG 2016 All rights reserved

V1.0 02/2017 Corrected picture in table 2.1. LEDs were upside down

SIMATIC IOT2000 I2C Example


Version 1.0, 09/2016 10

You might also like