Toggling an LED on Pandaboard using GPIO
From OMAPpedia
Contents |
[edit] Abstract
In this guide, I will describe how to toggle an LED using the GPIO on Pandboard step by step. This guide targets beginners who are just getting started on the Pandaboard.
[edit] Prerequisites
- You should have Ubuntu running on Pandaboard. If you have not completed that step or have problems, please follow the guide at this link: [1]
- Have an LED.
[edit] GPIO on the Pandaboard
Please download the Pandaboard reference manual from here:reference manual
There are two expansion headers J3 and J6 which contain the GPIO(s). I have used the J6 expansion header.So, how are the pins numbered? For this look at figure-1 below:
Figure-1: Expansion Headers on the Pandaboard
The numbering is same for both the headers. Let us take the J6 header. The top row of J6 header will contain odd numbered pins while the bottom row will contain the even numbered pins. The first pin on the top row(enclosed within a rectangle in the above figure) will always be Pin-1. Now, if you go refer pages 42-44 of the above manual, you will get more information about the different GPIO available on the pandaboard. Now let us refer table-11 on Page 44. This table explains the numbering of the pins on the expansion header J6 and the primary as well as secondary function of each pin on it. So, we know that pin-7 on J6 is the digital ground and pin-9 on J6 can also be used as GPIO. Pin-9 uses GPIO-38.
[edit] Steps
- Make sure that your kernel supports GPIO by typing the following commands in the terminal:
$ grep GPIOLIB /boot/config-`uname -r`
The output after running the above command should be as shown below:
CONFIG_ARCH_REQUIRE_GPIOLIB=y CONFIG_GPIOLIB=y
Now run the following command in the terminal:
$ grep GPIO_SYSFS /boot/config-`uname -r`
The output after running the above command should be as shown below:
CONFIG_GPIO_SYSFS=y
- Place the LED on J6 header such that cathode of LED is in pin-7 and anode of LED is in pin-9.
- Now let us light that LED!
Write the following commands in your terminal:
$ sudo su $ cd /sys/class/gpio $ echo 38 > export $ cd gpio38 $ echo "high" > direction
You should get the output as shown below:
Figure-2: Led OFF
Figure-3: Led ON
[edit] Headline text
References