SYSFS interface

The GPIO SYSFS interface allows one to control IO pins using files under the /sys directory.

When the system boots, all GPIO pins are owned by the kernel. They won't show up in the sysfs system until they are 'exported'. In order to export them, echo the pin number (for example 16 for the RED LED) to the file /sys/class/gpio/export:

$ echo 16 > /sys/class/gpio/export

This will result in the pseudo-files for pin 16 showing up under /sys/class/gpio/gpio16 as:




You can set the direction to either 'in' or 'out':

$ echo out > /sys/class/gpio/gpio16/direction

And then set the pin value with:

$ echo 1 > /sys/class/gpio/gpio16/value

$ echo 0 > /sys/class/gpio/gpio16/value

The first echo should turn the LED off, the second on.

You can stop using a pin as GPIO by 'unexporting' it:

$ echo 16 > /sys/class/gpio/unexport

This will make /sys/class/gpio/gpio16 disappear.

You will need to apply the Bifferboard kernel patch to get this functionality. See this page for details of GPIO pin numbers.