Linux Tutorial For Intel® Galileo Gen 2

Version 7

     

    One might mistakenly think that the Intel® Galileo Gen 2 as only an advanced, more powerful version of Arduino Uno that happens to be layered on top of a Linux system.

    There’s actually more to it than that and hopefully, this tutorial will show the bigger and more complex view of the Linux core underneath.

     

    (If you haven’t already, take a look at the Galileo Gen 2 Getting Started Guide. This is a basic overview of the Galileo Gen 2 board and a good starting point before going further on this tutorial.)

     

    Here is  a video of the completed project.

     

     

     

     

    Beyond the Uno

     

    The Intel® Galileo Gen 2 includes much of the Arduino Uno’s functionality. Similar to an Uno, it can create a wide variety interactive objects that use input sensors and various outputs. After exploring the many possibilities of using the “Arduino part” of the  Intel® Galileo Gen 2 this way, one might start to wonder: what is the next step?

     

    Perhaps you want to write more complex programs using your favorite scripting language like python or javascript. Maybe you’re interested in computer vision or want to have full control over the board and find out more about the inner workings. By accessing to the Linux core, all these will be possible to achieve.

     

    This tutorial will cover the basics of working with Linux by making a simple program that logs button presses. While the example is not very useful, it will help familiarize you with Linux as applied to the Intel® Galileo Gen 2

     

     

    Linux Versions for Intel® Galileo Gen 2

     

    The Linux system is very flexible can be tailored to fit specific purposes. Each distribution or version can have a drastically different features, interfaces, and architecture. There are a large number of customized versions made for the Intel® Galileo Gen 2, many made by other users. We will discuss the 3 major versions and the images from which they install.

     

    SPI-Image

    This version is pre-installed and does not need an SD card, but has limited functionality.  For instance, it does not have drivers for a wifi module and will not retain any loaded Arduino sketches after reboot.

     

    It is accessed by simply powering up the board.

     

    “SD-Card” Image

    This version requires an SD card and provides features that the SPI-Image does not. It has the wifi drivers, OpenCV, ALSA, and Node.js to name a few.

     

    This version can be downloaded from the  Intel® Galileo Gen 2 Document and Download page with installation instructions found here. Installation is pretty straight forward - extract the archive onto the SD card and power up the board.

     

     

    Iot Devkit Image

    This version has more interesting features and will be the focus of the tutorial. It is  easier to make network connections, there are more tools for development, and it supports OpenCV for python. (More information here.)

     

    Installation is a bit more complex, but the following tutorial will show the process.

     

    Debian and custom images

    These versions are user generated and each has its own advantages and installation methods. Information about Debian can be found here. Information about customizing Linux can be found here.

     

     

     

    Step A. Install the Iot Devkit Image

     

    A micro-SD is required and must be bigger than 1GB and smaller than 32GB. The downloads and detailed install instructions can be found here. For this tutorial, we will use a Windows application, Win32 Disk Imager, to make installation easier.

     

    When finished loading, insert the micro SD card into Intel® Galileo Gen 2, connect the USB cable, and power supply. If configured correctly, it should show up as Removable Disk.

     

     

    Fig_1.PNG

     

     

    Step B. Accessing the Linux Shell

     

    The Linux Shell is a command-line interface for controlling the Linux system. Commands entered here can, for instance, install software, manipulate the file system, or access debug messages.

     

    If using Windows, we recommend installing Putty, a program that enables to SSH and establish serial communication. SSH is a widely used protocol for accessing Linux shell (see this for more details) and the serial communication is another way of accessing shell and can act as a Arduino serial monitor). If you’re using Linux or Mac OS you can directly use SSH, and screen if you need serial.

     

    There are 4 major ways of connecting to Intel® Galileo Gen 2’s Linux shell

     

    1) Using the UART header

     

    An FTDI cable or FTDI breakout can be used to access a very powerful feature on the Intel® Galileo Gen 2 board, the UART headers. It is very stable way of accessing the shell since the port is used to transmit messages, even if the system is just booting.

     

    Plug the 6-pin header to the Intel® Galileo Gen 2 board; the black cable to the “GND” side. 2) Plug the USB to computer and power it up. Install the driverif necessary and then access the serial port using Putty or other methods mentioned above. (Hint: The COM port can be discovered with Arduino IDE, just like an Arduino board)

     

    Fig_2.PNG

     

    2) Using ethernet direct connection

     

    This method only requires an ethernet cable between the Intel® Galileo Gen 2 board and your computer. Ethernet cables are more common than an FTDI converter.

     

    Plug one end of the ethernet cable to Intel® Galileo Gen 2, and the other to your computer. Upload the following sketch(GetIP) to Intel® Galileo Gen 2 through Arduino IDE:

     

                void setup() {

      Serial.begin(9600);

      //It’ll not continue until you send an ‘a’ through the serial monitor

      while(Serial.read()!='a'){

        Serial.println("hello");

        delay(1000);

      }

      //Display ifconfig result to serial monitor

      system("ifconfig > /dev/ttyGS0");

    }

     

    void loop() {

     

    }

     

    Note that there is a special command used in this sketch, system(cmd). It executes the Linux command supplied. This is a rather useful function that allows the Arduino sketch to control the underlying Linux core.

     

    The “ifconfig” command will output the status of all network devices attached, including the IP address.

     

    “/dev/ttyGS0” represents the Arduino serial port on Intel® Galileo Gen 2. Using it will channel the output to the serial port and will display the result to Arduino serial monitor.

     

    Fig_3.PNG

     

    From the output you can see the IP address associated with the ethernet device. Use it to access the Linux Shell. Use Putty to access the shell. If you’re using Linux or Mac OS, you may need to get a static IP for your computer. Check how to do it using this article for Linux or this article for Mac.

     

    Fig_4.PNG

     

    If connecting to the Intel® Galileo Gen 2, an authorization key prompt will appear. Click “Yes”.

     

    Fig_5.PNG

     

    If prompted for a username, just type “root”.

     

    Fig_6.PNG


    If using Linux or Mac OS, type “SSH root@ip_address”. If the command prompt changes similar to the following, then it is working.

     

    Fig_7.PNG

     

    3) Wired connection to a router

     

    This method is very similar to the ethernet direct connection method and is also an easy for the Intel® Galileo Gen 2 to connect to internet. This method requires computer connected to an easily accessible router, either through wifi or wired connection.

     

    Plug Intel® Galileo Gen 2 to the router. Follow step 2 - 4 from the ethernet direct connection method.

     

    Note that if the router doesn’t use DHCP, this method will not work.

     

    4) Using a wifi card

     

    The Intel® Galileo Gen 2 has a mini-PCI slot that is used to connect a wifi card. Not only is the physical connection much cleaner, but the wifi card has a bluetooth module incorporated.

     

    Though almost any mini PCI wifi card should technically work, the Intel® Galileo Gen 2 has pre-installed drivers for Intel® Centrino® Wireless-N 135 and Intel® Centrino® Advanced-N 6205 adapters.

     

    Note that this method requires that one of the three previous methods be successfully attempted in order to work.

     

    Plug the wifi card into Intel® Galileo Gen 2. You can follow Sergey’s guide for making the physical connection. Get access to the shell using one of the three previous methods and use it to configure the wireless connection. Type “Connmanctl” in shell, which will change the prompt to “connmanctl>”.

    This is an interactive utility for managing connectivity devices in Iot Devkit Image.

    Fig_8.PNG


    Note: You can type “help” to see a brief instruction list. Type “enable wifi” to enable the wifi adaptor.

     

     

    Fig_9.PNG

     

     

    Type “scan wifi” and wait for it to finish, after which it will report “scan completed for wifi”

     

     

    Fig_10.PNG

     

     

    Type “services” to see the available access points.

     

    Fig_11.png

     

     

    Type “agent on” if your wireless network is protected.

     


    Fig_12.png

     

    Type “connect WIFI_ID” to connect to the network. Here “WIFI_ID” is the long string after every access point name. Pressing the Tab key will help autocomplete.

     

    Fig_13.png

     

    The shell will prompt for a network password.

     

    Fig_14.png

     

    The connection should now be ready. Type “exit” to leave connmanctl, and then “ifconfig” to see the IP address associated with wifi.

     

    Fig_15.png

     

    If used, the ethernet cables can now be disconnected.

     

     

    SSH to Intel® Galileo Gen 2 by the IP of wifi.

     

    Each time Intel® Galileo Gen 2 boots up, it should automatically connect to the wifi network with the same IP. If SSH cannot be established, use the sketch (GetIP) to find out its IP address.

     

    If using the “Wired Connection to A Router” or “Using a Wifi Card” approach and the router is connected to internet, type “ping google.com” in the shell to see if Intel® Galileo Gen 2 is already connected to internet.

     

     

    Fig_16.PNG

     

    Step C. Transfer files to Intel ® Galileo Gen 2

     

    When accessing the shell through SSH (so all the methods above except UART connection), files can be copied between the computer and Intel® Galileo Gen 2 with the utility scp.

     

    If using Linux or Mac OS, scp should be there already. In Windows you can get pscp (which is on the same website as Putty). Make sure to include it in the system PATH once it is downloaded since it cannot be used outside its folder.

     

    Let’s create a python script in your computer:

     

    from datetime import datetime

     

    #Get current time, if Intel® Galileo Gen 2 is connect to internet

    #It should automatically get the real time

    n=datetime.now()

    res=n.strftime("%d/%m/%y %H:%M:%S")

     

    #Append time to log file located in home directory of Intel® Galileo Gen 2

    f=open("/home/root/buttonLog.txt","a+")

     

    f.write(res+"\n")f.close()

     

    Save it as “recordTime.py”.

     

    Open a terminal in your computer, navigate to where the file was saved, and then type the following command “scp ./recordTime.py root@galileo_ip:~/” (or “pscp ./recordTime.py root@galileo_ip:/home/root/” if you’re using Windows and pscp).

     

    Note: If using pscp in Windows, use “/home/root/” instead of “~/”

     

     

    Fig_17.PNG

     

     

    This command will copy recordTime.py to the home directory of Intel® Galileo Gen 2. The home directory of the current user is represented by “~”, equivalent to “/home/root/” in the case of Intel® Galileo Gen 2. This is a good place to store user generated files.

     

    To test if the script works, SSH to Intel® Galileo Gen 2 and type “python ~/recordTime.py”. Repeat this a few times, and then type “cat ~/buttonLog.txt”. The command “cat” is a convenient way to display everything in the file to the terminal.

     

    Fig_18.PNG

     

    As a good practice, you should always create/modify files in your computer and copy to Intel® Galileo Gen 2, instead of making modifications directly inside Intel® Galileo Gen 2. So you don’t lose your work if Intel® Galileo Gen 2 fails.

     

    Step D. Use Arduino sketch to execute scripts

     

    Time to build some electronics, wire a button to pin12 on Intel® Galileo Gen 2

     

    Parts list:

    1 push button

    1 10k ohm resistor

    1 breadboard

    3 jump wires

     

     

    Copia di intel_ep1_linux_tutorial (4 of 7).jpg

     

     

          Make sure to connect the resistor to GND, and button to 5V. Upload this sketch through Arduino IDE:

     

    int btnPin=12;

    boolean oldState;

     

    void setup(){

      pinMode(btnPin, INPUT);

    }

    void loop(){

      boolean newState=digitalRead(btnPin);

      if(newState==HIGH && oldState==LOW){

        system("python ~/recordTime.py");

        delay(100);

      }

      oldState=newState;

      delay(30);

    }

     

    As before, the system(cmd) function executes system commands. This time the button state will call it.

     

    Each time the button is pressed, the time is recorded into the log file.

     

    To copy the log file from the Intel® Galileo Gen 2 to the host machine, type the following command: “scp root@galileo_ip:~/buttonLog.txt ./” (“pscp root@galileo_ip:/home/root/buttonLog.txt ./” with Windows).

     

    Last thoughts


    This guide gives some basic information about the benefit of accessing Linux shell in Intel® Galileo Gen 2; preparing a system image; accessing the shell in 4 different ways; examining the workflow of copying a python script into Intel® Galileo Gen 2 through scp (or pscp); running an Arduino sketch; and retrieving files from Intel® Galileo Gen 2.

     

    There is definitely much more that can be done with Intel® Galileo Gen 2 and the Linux shell, but this provides an entry point. Continue to explore the Intel® Galileo Gen 2 and the possibilities it presents!