In this chapter, we will start our journey towards Internet of Things (IoT) with Python and the Intel Galileo Gen 2 board. Python is one of the most popular and versatile programming languages. You can use Python to create multiplatform desktops and Web, mobile, and scientific applications. You can work with huge amounts of data and develop the complex algorithms that are popular in Big Data scenarios with Python. There are thousands of Python packages, which allow you to extend Python capabilities to any kind of domain you can imagine.
We can leverage our existing knowledge of Python and all of its packages to code the different pieces of our IoT ecosystem. We can use the object-oriented features, which we love from Python. in code that interacts with the Intel Galileo Gen 2 board and the electronic components connected to it. We can use the different packages that make it possible for us to easily run a Web server and provide a RESTful API. We can use all the packages that we already know to interact with databases, Web services, and different APIs. Python makes it easy for us to jump into the IoT world. We don't need to learn another programming language, we can use the one we already know and love.
First, we will learn about the features included in the Intel Galileo Gen 2 board. We will:
Understand the Intel Galileo Gen 2 board and its components
Recognize the Input/Output and the Arduino 1.0 pinout
Learn about the additional expansion and connectivity capabilities
Understand the buttons and the LEDs found in the board
Check and upgrade the board's firmware
We want to bring our ideas to life, easily. We want to be able to display a happy birthday message on a screen when we clap our hands. We want to collect huge amounts of data from the real world. We want to create wearables that keep track of all our activities during an entire day. We want to use the data to perform actions and interact with real-world elements. We want to use our mobile devices to control robots. We want to be able to determine whether the weather is hot or cold based on the data retrieved from a temperature sensor. We want to make decisions based on the values collected from a humidity sensor.
We want to measure how much of our favorite beverage is there in the cup and display the information on an LCD dot matrix display. We want to analyze all the data collected by things that are connected to the Internet. We want to become makers in the Internet of Things era by leveraging our existing Python programming skills.
We will use Python as the main programming language to control the different components connected to an Intel Galileo Gen 2 board, specifically Python 2.7.3. However, before we can become makers, it is necessary to understand some of this board's features.
After we unbox an Intel Galileo Gen 2, we will find the following elements:
The Intel Galileo Gen 2 board
A 12 VDC (Volts direct current), 1.5 A (Amperes) power supply
The following image shows the front view for an unboxed Intel Galileo Gen 2 board:

Let's have a look at the front view of the board for a few minutes. We will notice many familiar elements, such as an Ethernet jack, host USB port, and many labeled pins. In case we have previous experience with an Arduino UNO R3 board, we will easily realize that many elements are in the same locations as in that board. In case we have previous experience with embedded systems and electronics, we will easily realize that the board provides the necessary pins (SCL and SDA) to talk with the devices that support the I2C bus. In case we don't have any previous experience, we will learn what we can do with all these pins in the examples included in the forthcoming chapters.
The next image shows the graphical representation of the Intel Galileo Gen 2 board in the Fritzing open source and free software. As you might notice, the graphical representation includes only the important pieces of the board and all the things we can wire and connect, with the necessary labels to help recognize them easily. We will use the Fritzing diagrams to illustrate all the wirings that we must do in order to complete each sample project through the book.

Tip
You can download the latest version of Fritzing from http://fritzing.org/download/. Fritzing runs on Windows, Mac OS X and Linux. You will find the Fritzing sketches for all the examples included throughout the book in files with an FZZ extension (*.fzz
) as a part of the code files that you can download for this book. The files are saved with Fritzing 0.92. Thus, you can open the sketches in Fritzing, check the breadboard view, and make any changes to it based on your needs.
The next image shows the electronic schematic representation of the Intel Galileo Gen 2 board, that is, the symbolic representation of the board to make it easy to understand the interconnections of the electronic circuits related to the board. The electronic schematic is also known as circuit diagram or electrical diagram. The symbol includes all the pins provided by the board shown as connectors. We can easily recognize the many labels that appear on the board as labels for each connector in the symbol. Fritzing allows us to work with both the breadboard and the electronic schematic representation.

Tip
When you open the Fritzing file for each sample included in the book, you will be able to easily switch from the breadboard view to the schematic view by clicking on either the Breadboard or the Schematic buttons located at the top of the main Fritzing window.
The next image shows the system block diagram for the Intel Galileo Gen 2 board. The diagram is a part of the content included in the Intel Galileo Gen 2 design document: http://www.intel.com/content/dam/www/public/us/en/documents/guides/galileo-g2-schematic.pdf.

The Intel Galileo Gen 2 board is an Arduino certified embedded computer that we will use to develop and prototype our IoT projects. The board is based on Intel architecture and uses an Intel Quark SoC X1000 system on a chip, known as SoC or application processor. The SoC is a single-core and single-threaded application processor that is compatible with the Intel Pentium 32-bit instruction set architecture (ISA). Its operating speed is up to 400 MHz. The following image shows the SoC, located approximately at the center of the board. The following page provides detailed information about the Intel Quark SoC X1000: http://ark.intel.com/products/79084/Intel-Quark-SoC-X1000-16K-Cache-400-MHz

On the right-hand side of the CPU, the board has two integrated circuits that provide 256 MB of DDR3 RAM (short for Random Access Memory) memory. The operating system and Python will be able to work with this RAM memory. As it happens in any computer, RAM memory loses its information after we turn off the board. Thus, we say that RAM is volatile, as the data stored in it is lost when the memory isn't powered. The following image shows the DDR3 memory chips.

In addition, the board provides access to the following onboard memories:
512 KB embedded SRAM (short for Static Random Access Memory).
8 MB Legacy SPI NOR Flash, non-volatile memory. Its goal is to store the board's firmware and sketches.
11 KB EEPROM (short for Electrically Erasable Programmable Read-Only Memory). It is non-volatile and we can store data in it for our own purposes.
The board provides the following I/O pins:
14 digital I/O pins
Six PWM (short for Pulse Width Modulation) output pins
Six analog input pins
The board is hardware and software pin-compatible with Arduino shields designed for the Arduino Uno R3. The 14 digital I/O pins numbered from 0 to 13 are located in the upper-right corner of the board and they also include the adjacent AREF and GND pins, as in the Arduino Uno R3. The pins configuration is also known as Arduino 1.0 pinout.
Tip
Shields are boards that we can plug on top of the Intel Galileo Gen 2 board to extend its capabilities. For example, you can plug a shield that provides two high current motor controllers or a shield that adds an LED matrix.
As it happens in the Arduino Uno R3, we can use six of these digital I/O pins as PWM (Pulse Width Modulation) output pins. Specifically, the pins labeled with a tilde symbol (~) as a prefix to the number have this capability: pins ~11, ~10, ~9, ~6, ~5 and ~3. The following are the pins that compose the header from left to right:
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
TX->1
RX<-0
The next image shows the 14 digital I/O pins and the six PWM output pins labeled with a tilde symbol (~) as a prefix for the number. The first two pins, starting from the left are for the two I2C bus lines: SCL (Serial CLock) and SDA (Serial DAta). The last two pins, starting from the left, labeled TX->1 and RX<-0 are the UART 0 port pins. A UART port stands for Universal Asynchronous Receiver/Transmitter.

The six analogous input pins numbered from A0 to A5 are located in the lower-right corner of the board, as in the Arduino Uno R3. On the left-hand side of the analog input pins, we can see the following power pins that compose the power header:
POWER
IOREF
RESET
3.3V
5V
GND
GND
VIN
The VIN pin in the power header provides the input voltage that is supplied to the board through its power jack. The power supply included in the box provides 12V. However, the board can operate with an input voltage ranging from 7V to 15V. The board also provides support to Power over Ethernet, also known as PoE, this passes the electrical power to the board along with data on the Ethernet cable.
The following screenshot shows the power pins, also known as power headers, and the six analog input pins:

The board includes a jumper labeled IOREF that allows us to select between a 3.3V or 5V shield operation and provides voltage-level translation to all the I/O pins. Based on the jumper position, the board can work with either a 3.3V or 5V Arduino shield. By default, the IOREF jumper is set to the 5V position, and therefore, the initial setting allows us to work with 5V shields. The following screenshot shows the IOREF jumper set to the 5V position.

Tip
The IOREF pin in the power header provides the operational voltage reference based on the IOREF jumper position. Thus, based on the IOREF jumper position, the voltage reference in the IOREF pin can be either 5V or 3.3V.
On the right-hand side of the board, there is a 6 pin, specifically 2x3 pin, ICSP (In-Circuit Serial Programming) header, labeled ICSP. The location of this header is also compatible with the Arduino 1.0 pinout. The following screenshot shows the ICSP header:
