## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = Programming GPIO pins on Intel Galileo ## multi-line description to be displayed in search ## description = ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= ## next.1.link= ## what level user is this tutorial for ## level= IntermediateCategory ## keywords = #################################### <> <> == 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: {{{#!python #!/usr/bin/python import sys import time def pins_export(): try: pin1export = open("/sys/class/gpio/export","w") pin1export.write("3") pin1export.close() except IOError: print "INFO: GPIO 3 already exists, skipping export" fp1 = open( "/sys/class/gpio/gpio3/direction", "w" ) fp1.write( "out" ) fp1.close() def write_led( value ): fp2 = open( "/sys/class/gpio/gpio3/value", "w" ) fp2.write( str( value ) ) fp2.close() pins_export() while True: print "on" write_led( 1 ) time.sleep( 1 ) print "off" write_led( 0 ) time.sleep( 1 ) }}} See [[http://www.malinov.com/Home/sergey-s-blog|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 [[IntelGalileo/HydroGalileoInitialInstall|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 }}} ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE