[Documentation] [TitleIndex] [WordIndex

(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Programming GPIO pins on Intel Galileo

Description:

Tutorial Level: INTERMEDIATE

Intro

This should work with either the Yocto or Debian setup.

Set up

First we have to make sure the permissions are set up to allow users to manipulate GPIO. Edit /etc/udev/rules.d/99-gpio.rules (as root) and make it look like this:

SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys%p; chown -R root:gpio /sys/class/gpio; chmod -R 775 /sys%p; chmod -R 775 /sys/class/gpio'"

sudo groupadd -f --system gpio
sudo udevadm control --reload-rules

Command line test

echo -n "3" > /sys/class/gpio/export 
echo "out" > /sys/class/gpio/gpio3/direction 
echo "1" > /sys/class/gpio/gpio3/value

The LED on the board should turn on

echo "0" > /sys/class/gpio/gpio3/value

The LED should turn off

Control pins with Python

Here's a simple Python program to blink the LED:

   1 #!/usr/bin/python
   2 import sys
   3 import time
   4 
   5 def pins_export():
   6     try:
   7         pin1export = open("/sys/class/gpio/export","w")
   8         pin1export.write("3")
   9         pin1export.close()
  10     except IOError:
  11         print "INFO: GPIO 3 already exists, skipping export"
  12 
  13     fp1 = open( "/sys/class/gpio/gpio3/direction", "w" )
  14     fp1.write( "out" )
  15     fp1.close()
  16 
  17 def write_led( value ):
  18     fp2 = open( "/sys/class/gpio/gpio3/value", "w" )
  19     fp2.write( str( value ) )
  20     fp2.close()
  21 
  22 
  23 pins_export()
  24 while True:
  25     print "on"
  26     write_led( 1 )
  27     time.sleep( 1 )
  28     print "off"
  29     write_led( 0 )
  30     time.sleep( 1 )   

See Sergey's Blog for pin mapping.

I2C and PWM

It looks like the kernel needs to be compiled with i2c_std_mode = 1 in order to use I2C, PWM and some of the GPIO pins. If you've followed The Yocto install path, you should already be good.

If you've followed the Debian install method, go back to [IntelGalileo/HydroGalileoInitialInstall|the Yocto install]] tutorial. Once you've got the image bitbaked, do this:

$ cd ~/gaileo-debian
$ sudo mount -o loop loopback.img mnt-loop
$ sudo mount -o loop ~/devel_gal/meta-clanton_v0.7.5/yocto_build/tmp/deploy/images/image-full-clanton.ext3 image
$ sudo cp -r image/lib/modules mnt-loop/lib
$ sudo sh -c " cat image/etc/modules-load.d/auto.conf >> mnt-loop/etc/modules "
$ sudo umount image
$ sudo umount mnt-loop
$ sudo mount /dev/mmcblk0p1 sdcard
$ sudo rm sdcard/image-full-clanton.ext3
$ sudo cp loopback.img sdcard/image-full-clanton.ext3
$ sudo umount sdcard


2018-12-08 12:21