Thursday, March 21, 2013

GPIO on Beaglebone- Blinking LEDs

The first program that we wrote, was the famous "Hello World" of the embedded universe, .i.e. blinking of a led connected to a GPIO port. Access to GPIO ports is provided through the sysfs interface on Angstrom. To blink an led we must:

  1. Look up GPIO number of the pin in the Beaglebone reference manual. For example, pin 3 on P8 is connected GPIO1_6. To obtain the GPIO number we must multiply the port number by 32 and add the pin number. So GPIO1_6 would be 1x32 + 6 = 38
  2. Next we must export this pin, so that it is accessible from user space.
     echo 38 > /sys/class/gpio/export  
  3. Set the direction of the pin as output
     echo out > /sys/class/gpio/gpio38/direction  
  4. Write values to the 'value' file
     echo 1 > /sys/class/gpio/gpio38/value  
The above steps were followed to blink an led from the terminal. The same was then converted into a C program using C file operations (fopen, fprintf)

No comments:

Post a Comment