November 26, 2016

Intel Galileo - Gen 2 - blink the onboard LED

The Galileo has a green LED labelled "L". On my board this is just to the right of the host USB connector

It turns out that this is connected to the same line that drives Arduino pin 13. On the Gen 2, this is driven by linux GPIO 7 (on the Gen 1 it was linux GPIO 39).

Python and wiring-x86

It is quite simple to make this LED blink using an arduino sketch, but that is boring and we are not going to talk about that here. I am not generally a Python fan, but I found a nice Python library (and well written too), called "wiring-x86".

It was a simple matter to clone this, change one line in one of the examples, and have that LED blinking, as follows:
git clone

make install
running install
running build
running build_py
creating build
creating build/lib
copying -> build/lib
running install_lib
copying build/lib/ -> /usr/lib/python2.7/site-packages
byte-compiling /usr/lib/python2.7/site-packages/ to wiringx86.pyc
running install_egg_info
Writing /usr/lib/python2.7/site-packages/Wiring_x86-1.0.0-py2.7.egg-info

Python 2.7.3 (default, May 12 2016, 08:33:18) 
[GCC 4.9.1] on linux2
I edit one line in examples/blink,py as follows:
#from wiringx86 import GPIOEdison as GPIO
from wiringx86 import GPIOGalileoGen2 as GPIO
A pruned down version of the script is:
import time

from wiringx86 import GPIOGalileoGen2 as GPIO

gpio = GPIO(debug=False)
pin = 13
state = gpio.HIGH

gpio.pinMode(pin, gpio.OUTPUT)

        gpio.digitalWrite(pin, state)
        state = gpio.LOW if state == gpio.HIGH else gpio.HIGH
I run this as python and it works like a champ! These Emutex dudes have more than a clue.

Blink via a bash script

It is instructive to look at the wiring-x86 sources. It shows a part of what is going on behing the scenes in the Galileo. Based on a study of what wiring-x86 does to blink the "L" LED, I wrote the following bash script.

echo -n 7 >/sys/class/gpio/unexport
echo -n 7 >/sys/class/gpio/export

echo -n 46 >/sys/class/gpio/unexport
echo -n 46 >/sys/class/gpio/export

echo -n 30 >/sys/class/gpio/unexport
echo -n 30 >/sys/class/gpio/export

echo -n 31 >/sys/class/gpio/unexport
echo -n 31 >/sys/class/gpio/export

echo -n low >/sys/class/gpio/gpio46/direction
echo -n low >/sys/class/gpio/gpio30/direction
echo -n in >/sys/class/gpio/gpio31/direction

echo -n strong >/sys/class/gpio/gpio46/drive
echo -n strong >/sys/class/gpio/gpio30/drive
echo -n hiz >/sys/class/gpio/gpio31/drive

echo -n 0 >/sys/class/gpio/gpio46/value
echo -n 0 >/sys/class/gpio/gpio30/value

echo -n low >/sys/class/gpio/gpio7/direction
#echo -n strong >/sys/class/gpio/gpio7/drive

while true
	echo -n 1 >/sys/class/gpio/gpio7/value
	sleep 0.3
	echo -n 0 >/sys/class/gpio/gpio7/value
	sleep 0.3
This does a fine job of blinking the LED also. Here it is clear that it is accessing the gpio via the linux "sysfs" interface, which I find quite byzantine. It certainly works, and this is exactly what python wiring-x86 and most likely the arduino libraries are doing.

You hopefully are asking why it is necessary to fiddle with GPIO 46, 30, and 31 also when we know that it is GPIO 7 that controls the LED. If you look at wiring-x86, you will find a set of tables for each pin. In this case the table of interest is GPIO_MUX_OUTPUT. This table provides for each pin, a list of other pins and the state they must be placed into to allow the pin to be used for GPIO. In some cases these control a pin multiplexor, in other cases they do other things. More about this elsewhere.

Feedback? Questions? Drop me a line!

Tom's Computer Info /