Google Groups

RE : [beagleboard] Re: Using gpio


Boireau Laurent Feb 13, 2009 1:14 AM
Posted in group: BeagleBoard
Try the following under minicom, after logging as root to Angstrom.
Check if you have the following directory (that's a special Led driver patch : some versions of Angstrom demo have it, others don't). It is described here : http://article.gmane.org/gmane.linux.ports.arm.omap/8611 and loaded at boot (see log and /etc/init.d).
> cd /sys/class/leds/beagleboard::usr1
>ls
> more trigger
> echo none > trigger
That shoud break the connection between LED and mmc
Now :
> echo 1 > brightness
> echo 0 > brightness
Done !

If you don't have it, just use basic GPIO
> cd /sys/class/gpio
> echo 150 > export    (150 is usr1 LED, 149 is usr0 ... You can also access expansion port GPIO that way, say 168 for pin 24)
That should create directory /sys/class/gpio/gpio150, with all the access you want.
>cd /sys/class/gpio/gpio150
>echo "high" > direction
>echo "low" > direction
Or alternatively :
>echo "out">direction (set port as output)
>echo "1">value
>echo "0" value
Done !
If you want then to unmount the device, use unexport :
>cd /sys/class/gpio/
>echo 150 > unexport


While you're at it, you can also play with the user button :
>cd /sys/class/gpio
> echo "7" > export
> cd gpio7
>echo "in" > direction (set port as input)
> more value (should return 0 if usr button is not pressed, 1 if pressed ...).

A c program would do much the same, opening and writing (or reading) to the same files.

We definitely should set up some kind of beginners site with such simple or more complex exemples, with shell scripts and small C programs, demonstrating "hello world" capabilites, and basic interaction with LEDs, buttons, timers, interrupts, serial, SPI, I2C, PWM, interfacing a webcam, using the NEON or the DSP ... That would make starting applications (say robotics ...) with beagle much faster !! I do prefer learning by example rather than reinventing the wheel by parsing hundreds of pages of doc and googling around, even if the latter can't always be avoided ;-)
Have fun !!

    Laurent



-----Message d'origine-----
De : beagl...@googlegroups.com [mailto:beagl...@googlegroups.com] De la part de Tomi Valkeinen
Envoyé : vendredi 13 février 2009 08:12
À : Beagle Board
Objet : [beagleboard] Re: Using gpio



Hi,

On Thu, 12 Feb 2009, aero386 wrote:

>
>
> So I found the below code on
> http://blog.makezine.com/archive/2009/02/blinking_leds_with_the_beagle
> _board.html
>
>
> #!/bin/sh
> #
> # Blink the onboard LED
>
> GPIO=$1
>
> cleanup() { # Release the GPIO port
>  echo $GPIO > /sys/class/gpio/unexport
>  exit
> }
>
> # Open the GPIO port
> #
> echo $GPIO > /sys/class/gpio/export
>
> trap cleanup SIGINT # call cleanup on Ctrl-C
>
> # Blink forever
> while [ "1" = "1" ]; do
>  echo "high" > /sys/class/gpio/gpio$GPIO/direction
>  sleep 1
>  echo "low" > /sys/class/gpio/gpio$GPIO/direction
>  sleep 1
> done
>
> cleanup # call the cleanup routine
>
>
> ...it does not work on the beagle image I am running "2.6.28". I do
> not have the specified folders sys/class/gpio/gpio$GPIO/direction in
> the image. I was wondering if there was a simple fix or something. the
> only folders I have  are
>
> root@beagleboard:/# ls
> bin      dev      home     linuxrc  mnt      sbin     tmp      var
> boot     etc      lib      media    proc     sys      usr
> root@beagleboard:/# cd sys
> root@beagleboard:/sys# cd class
> root@beagleboard:/sys/class# ls
> bdi           i2c-adapter   mmc_host      scsi_generic  usb_device
> bluetooth     i2c-dev       mtd           scsi_host     usb_endpoint
> display       ieee80211     net           sound         usb_host
> firmware      input         regulator     spi_master    usbmon
> gpio          leds          rtc           thermal       vc
> graphics      mem           scsi_device   tty           vtconsole
> hwmon         misc          scsi_disk     ubi
> root@beagleboard:/sys/class# cd gpio root@beagleboard:/sys/class/gpio#
> ls
> export       gpiochip128  gpiochip192  gpiochip64   unexport
> gpiochip0    gpiochip160  gpiochip32   gpiochip96
> root@beagleboard:/sys/class/gpio# cd gpiochip160
> root@beagleboard:/sys/class/gpio/gpiochip160# ls
> base       label      ngpio      power      subsystem  uevent
> root@beagleboard:/sys/class/gpio/gpiochip160#
>
> So anyways I was just wondering what exactly that was all about.

Check Documentation/gpio.txt from kernel sources. It explains how the
sysfs interface works.

  Tomi