IoT with Intel Galileo - WordPress.com · Intel Galileo The Intel® Galileo Gen 2 development board...

Post on 19-Jun-2020

23 views 0 download

Transcript of IoT with Intel Galileo - WordPress.com · Intel Galileo The Intel® Galileo Gen 2 development board...

IoT with Intel GalileoGerardo Carmona

makerobots.tk

OutlineWhat is Intel Galileo?

Hello world! In Arduino

Arduino and Linux

Linux via SSH

Playing around in Linux

Programming flexibility

How GPIOs works

Challenge 1: Bash script

makerobots.tk

What isIntel Galileo?

makerobots.tk

Intel GalileoThe Intel® Galileo Gen 2 development board is a microcontroller board based on the Intel® Quark™SoC X1000 application processor, a 32-bit Intel® Pentium® brand system on a chip (SoC). It is the first board based on Intel® architecture designed to be hardware and software pin-compatible with shields designed for the Arduino Uno* R3.

This platform provides the ease of Intel architecture development through support for the Microsoft Windows*, Mac OS*, and Linux* host operating systems. It also brings the simplicity of the Arduino integrated development environment (IDE) software.

From Intel website, Galileo overview

makerobots.tk

Intel Galileo

Intel Galileo Gen 2 Intel Galileo Gen 1

makerobots.tk

Intel Galileo Gen 1

5 V input

Micro SD slot

SD card LED, powerLED and Reset button

Ethernet

RS-232 USB client USB Host

Digital pins, some PWM, Serial, I2C and others

Power pins & analog pins

Quark SoC X1000

Reboot

RAM memory

Pin 13 LED

makerobots.tk

Intel Galileo Gen 2

Ethernet port

6 pin FTDI header

USB device port USB host port Pin 13 LED, Power LED and SD card LED

Digital pins, some PWM, Serial, I2C and others

RAM memory

Quark SoC X1000

Power pins & analog pins

Reset button (sketch)

7 to 15 V input

Micro SD Card slot

Reboot Linux button

makerobots.tk

Hello world! In Arduino

makerobots.tk

Hello World! - ArduinoBefore we can program our Intel Galileo board we need to do some setup steps, like installing drivers, software, etc.

Refer to “Installing Intel Galileo.pdf” in my webpage for more details.

makerobots.tk

Hello World! - ArduinoOpen Arduino IDE.

Open file under:

“File >> Examples >> 01.Basics >> Blink“ menú

Go to menu “Tools >> Boards >> Galileo Gen 2”

Then “Tools >> Serial port >> COMx” and select corresponding COM port for your Galielo.

If you do not know which one it is, go to “Device manager” and look under COM and LTP ports.

Compile, Upload, New, Open, Save

makerobots.tk

Hello World! - ArduinoCode:

void setup() {// initialize digital pin 13 as an output.pinMode(13, OUTPUT);

}

// the loop function runs over and over again forevervoid loop() {digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage

level)delay(1000); // wait for a seconddigitalWrite(13, LOW); // turn the LED off by making the voltage LOWdelay(1000); // wait for a second

}

makerobots.tk

Arduino + Linux

makerobots.tk

Arduino + LinuxYou can combine the easy to use of Arduino and the power of an Operative System like Linux.

From the Arduino code you can make “system calls” to the Linux side using system command.

Example:

system(“ls > /dev/ttyGS0”);

System command

List of directories

Redirect output to…

Serial port

http://explainshell.com/

makerobots.tk

Arduino + LinuxWhat if I want to know my Galielo’s IP address?

makerobots.tk

Arduino + LinuxWhat if I want to know my Galielo’s IP address?

R: Using ifconfig. upload this program

void setup() {// Init serial comSerial.begin(9600);// Waits 5 seconds before printing itdelay(5000);// Gets network interface info and sends // it through the serial interfacesystem("ifconfig > /dev/ttyGS0");

}

void loop() {}

makerobots.tk

Arduino + Linux

makerobots.tk

Linux via SSH

makerobots.tk

Linux via SSHSecure Shell is a encrypted network protocol that initializes sessions on remote machines.

We can connect to our Intel Galileo Linux-side using SSH. Follow the next steps (windows):

1) Connect your Intel Galileo to your local network

2) Get PuTTy o r any other SSH client, for PuTTY go to:

http://www.putty.org/

makerobots.tk

Linux via SSH

Open PuTTy and configure as shown

1

2 3

4

1. Select SSH2. Write Galileo’s IP

address3. Leave port as 224. Click Open

makerobots.tk

Linux via SSHThe following window opens

Type root as username and hit enter, no password is required

makerobots.tk

Linux via SSHNow you are inside Linux Yocto Project

https://www.yoctoproject.org/

makerobots.tk

Playing around withLinux

makerobots.tk

Playing around with LinuxNow we can create files, folders, navigate though the Linux file system.

You can use common Linux commands such as “ls”, “cd”, “cd ..”, “rm”, …

Create a folder and name it as “semanai”

makerobots.tk

Playing around with LinuxNow we can create files, folders, navigate though the Linux file system.

You can use common Linux commands such as “ls”, “cd”, “cd ..”, “rm”, …

Create a folder and name it as “semanai”

Navigate to the folder

$ mkdir semanai$ lssemanai

makerobots.tk

Playing around with LinuxNow we can create files, folders, navigate though the Linux file system.

You can use common Linux commands such as “ls”, “cd”, “cd ..”, “rm”, …

Create a folder and name it as “semanai”

Navigate to the folder

Create a file and name it hello.txt

$ mkdir semanai$ lssemanai

$ cd semanai

makerobots.tk

No nano editor =´(We will use vi editor, old school…

makerobots.tk

Playing around with LinuxNow we can create files, folders, navigate though the Linux file system.

You can use common Linux commands such as “ls”, “cd”, “cd ..”, “rm”, …

Create a folder and name it as “semanai”

Navigate to the folder

Create a file and name it hello.txt

$ mkdir semanai$ lssemanai

$ cd semanai

$ vi hello.txt

makerobots.tk

New fileWrite “Hello world” and save it

http://www.lagmonster.org/docs/vi.html

makerobots.tk

Vi editorTo start editing this file press “i” (insert mode).

Now you can type your text, after you finish, to save and exit file:

•Press escape key (exit editing mode)

•Type “:wq” (write and quit command)

makerobots.tk

Playing around with LinuxIf you want to display the content of a file in terminal type:

$ cat hello.txt

makerobots.tk

Programming flexibility

makerobots.tk

Programming flexibilityOne of the advantages of having a OS is that we can program using different programming languages.

We will make hello world in the following programming languages:

Bash

Python

C

Node.js

makerobots.tk

BashA shell script is a file containing one or more commands that you would type on the command line.

Create a file and name it hellobash.sh and write the following lines

Execute the file by typing:

#!/bin/bash#Author: Gerardo Carmonaprintf "Hello world! \n"

$ sh hellobash.sh

In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark (that is, "#!") at the beginning of a script.The program loader is instructed to run the program "/bin/sh" instead (usually this is the Bourne shell or a compatible shell), passing "path/to/script" as the first argument.

makerobots.tk

PythonCreate a file and name it hellopython.py and write the following lines

Execute the file by typing:

#!/usr/bin/python#Author: Gerardo Carmonaprint “Hello world!”

$ python hellopython.py

This is Python 2.x compatible only

makerobots.tk

CCreate a file and name it helloc.c and write the following lines

Compile file

Execute compiled file

//Author: Gerardo Carmona#include <stdio.h>int main(){

printf(“Hello world!\n”);}

$ gcc helloc.c –o hello

$ ./hello

makerobots.tk

Node.jsCreate a file and name it hellonode.js and write the following lines

Execute the file by typing:

// Author: Gerardo Carmonaconsole.log("Hello world!");

$ node hellonode.js

makerobots.tk

How GPIOs Works

makerobots.tk

Galileo Gen 1 Pinout

makerobots.tk

Accessing GPIOsTo see a list of GPIOs type:

$ cat /sys/kernel/debug/gpio

http://bit.ly/1iHk5Ji

makerobots.tk

Accessing GPIOsYou will observe that Galileo Gen2 contains 79 GPIO ports.

Some of these pins are connected to the Arduino headers:

https://anandvetcha.wordpress.com/category/galileo/

GPIO Digital I/O--------------------------gpio11 pin0gpio12 pin1gpio13 pin2gpio14 pin3gpio6 pin4gpio0 pin5gpio1 pin6

GPIO Digital I/O--------------------------gpio38 pin7gpio40 pin8gpio4 pin9gpio10 pin10gpio5 pin11gpio15 pin12gpio7 pin13

makerobots.tk

Accessing GPIOsWhile the Intel Galileo, in essence, a very inexpensive Linux computer, there are a few things that distinguish it from laptop and desktop machines that we usually use for writing email, browsing the web, or word processing.

One of the main differences is that the Intel Galileo can be directly used in electronics projects because it has general purpose input and output pins right on the board.

It also lacks a video output to connect to a monitor

makerobots.tk

Virtual filesIn order to manage gpios you need to write some configurations to different virtual files.

They are a part of Linux’s virtual file system, which is a system that makes it easier to access low-level functions of the board in a simpler way.

For example, you could turn the LED on and off by writing to a particular section of the Intel Galileo memory, but doing so would require more coding and more caution.

makerobots.tk

Turning ON/OFF an LED

makerobots.tk

Accessing GPIOsLets turn On/Off pin 8, that’s gpio40. First we need to export gpio:

Above command will create “/sys/class/gpio/gpio40” folder.

$ echo -n “40" > /sys/class/gpio/export

makerobots.tk

Accessing GPIOsLets turn On/Off pin 8, that’s gpio40. First we need to export gpio:

Above command will create “/sys/class/gpio/gpio40” folder.

Set the direction of gpio40 to “out”.

$ echo -n “40" > /sys/class/gpio/export

$ echo -n "out" > /sys/class/gpio/gpio40/direction

makerobots.tk

Accessing GPIOsLets turn On/Off pin 8, that’s gpio40. First we need to export gpio:

Above command will create “/sys/class/gpio/gpio40” folder.

Set the direction of gpio40 to “out”.

Now we can turn on the LED and off:

$ echo -n “40" > /sys/class/gpio/export

$ echo -n "out" > /sys/class/gpio/gpio40/direction

$ echo -n "1" > /sys/class/gpio/gpio40/value$ echo -n “0" > /sys/class/gpio/gpio40/value

makerobots.tk

Accessing GPIOsLets turn On/Off pin 8, that’s gpio40. First we need to export gpio:

Above command will create “/sys/class/gpio/gpio40” folder.

Set the direction of gpio40 to “out”.

Now we can turn on the LED and off:

Unexport pin

$ echo -n “40" > /sys/class/gpio/export

$ echo -n "out" > /sys/class/gpio/gpio40/direction

$ echo -n "1" > /sys/class/gpio/gpio40/value$ echo -n “0" > /sys/class/gpio/gpio40/value

$ echo -n "40" > /sys/class/gpio/unexport

makerobots.tk

Challenge 1Make a script in bash that blinks 10 times an LED. Use LED located on Pin 8 on Arduino (gpio40).

makerobots.tk

Some helpFor cicle in bash:

for i in `seq 1 10`;do

# Printecho $i

done

Challenge 1:Make a script in bash that blinks 10 times an LED. Use LED located on Pin 8 on Arduino, gpio40 in Linux.

makerobots.tk

Thanks!

Time to recharge batteries!

makerobots.tk