Chiliboard/Using GPIO and LED
Using GPIOs and LEDs
Chiliboard has two built-in user LED's, and a lot of unused pins that can be used as general-purpose input/output lines (GPIO).
User leds can be controlled by /sys/class/leds directory, and are visible as led0 and led1 subdirectories. By default led0 uses heartbeat trigger. To turn on the led1, type:
echo 1 > /sys/class/leds/led1/brightness
and to turn off
echo 0 > /sys/class/leds/led1/brightness
GPIO lines can be controlled from the user space via the directory /sys/class/gpio.
For example, to set the GPIO1_8 pin to 1 do:
- Calculate the index of the pin as 1*32+8 = 40 and export it to the gpio subsystem using:
echo 40 > /sys/class/gpio/export
- In the /sys/class/gpio will be created gpio40 directory representing selected pin.
- Set the direction of the line:
echo out > /sys/class/gpio/gpio40/direction
- Then the value of the line
echo 1 > /sys/class/gpio/gpio40/value