In this guide, I will describe how to do GPIO Programming on the MinnowBoard step by step. This guide is for new users who are just getting started with the MinnowBoard.
For information on 'Setting up a microSD card', 'Booting Angstrom' etc, please refer here
GPIO on the MinnowBoard
The MinnowBoard provides a variety of GPIO(General Purpose Input Output), some with a dedicated purpose. For the purpose of this guide, I will be concentrating only on GPIO(s) which are on the J9 expansion header as shown in Figure - 1 . Please refer the table below to find out how are the GPIO(s) actually referenced in the kernel and their default modes as well as values. Unless otherwise stated the GPIO(s) on J9 expansion header are rated at 3.3V and can source/sink a maximum of 10mA. Also, it can be seen from the table that the GPIO(s) are by default set to be used in INPUT mode and have PULL-UP resistors enabled.
|Sr. No.||GPIO||Reference Number in the kernel*||Default Mode||Default Value|
|*For example GPIO-3 on J9 header will be referenced as gpio-244 in kernel|
As you can see from Figure -1, there are a total of ten pins on the J9 header out of which 8 pins can be used as GPIO. The remaining two pins are GND and 3.3V as mentioned in the table.
The GPIO(s) are accessible via the user space in Linux at the location below on the filesystem:
There is one directory per GPIO, named as shown below(as an example only two GPIO(s) are shown here):
Inside each one of those directories, there are files named "direction” and “value” as shown in Figure - 2. The former is for configuring the mode of GPIO as input(“in”) or output(“out”) while the latter is for the value('1' for HIGH and '0' for LOW) if used in output mode.
Selecting the correct LED
• To make sure that you do not damage the GPIO pins on the MinnowBoard, please use a LED whose rating should not exceed 3.3V/10mA:
• If you have an LED that is higher than the above mentioned ratings, please refer the refer the link below to select an appropriate current limiting resistor:
This is an optional section which you can read for further understanding. In a nutshell, we are trying to access the on board USER LED(s) via userspace in Linux. To be more precise we are using the sysfs interface. sysfs is a virtual filesystem which translates the hardware devices and busses attached to the system(board in our case) into a file system hierarchy that can be accessed from userspace. sysfs is generated by the kernel and always mounted at /sys. As discussed earlier, trigger for D11 and D12 LEDs has to be changed to make them function as USER LEDs. I would describe 'trigger' as the API used to link a LED to an 'event' in kernel space. Here, 'event' could be microSD card or Ethernet activity, heartbeat, power etc. To understand this better, take LED D11 for example. The trigger for D11 has been set by default to heartbeat. So, to use it as an USER LED, we have to change the trigger for it to 'none' as shown in Figure - 3 below:
Please refer the Figure - 4 below to see the connections:
Only the pins on the J9 expansion header are used in this case. Connect the anode of the LED to the resistor(I am using a 330 ohms resistor) which in turn is connected to pin 3(GPIO) and connect the cathode of the LED to pin 2(GND) . You can purchase the male-female type hookup/jumper wires used for connections from the link below:
• Now let us toggle that LED!
GPIO - 3 is referenced as 244 in the kernel. Since, it is set to be used in INPUT mode by default, we need to change its mode to OUTPUT. Type the following command in your terminal to accomplish this:
echo out > /sys/class/gpio/gpio244/direction
Now we are ready to toggle the LED. Type the following commands in your terminal as shown in Figure - 5(First one is for turning ON and latter for OFF):
echo 1 > /sys/class/gpio/gpio244/value echo 0 > /sys/class/gpio/gpio244/value
You should get an output as shown below: