Getting access to GPIOs
Now let's look at how we can get access to GPIOs using both the command line (using Bash) and then using the C language.
Bash
Now it's time for an example. A very simple usage is the following one, where we use the gpio91
of the Wandboard to turn an LED on and off. The circuitry is reported in the following figure:
To control the LED, we must set the line as the output, so we should write out
in the /sys/class/gpio/gpio91/direction
file, but if we wish to set the LED to a precise state by default, it is better to write low
, as show here:
root@wb:~# echo low > /sys/class/gpio/gpio91/direction
Note
You can now observe that the low
value is the default for the out
setting, but the preceding setting increases the code readability since it states the intention of the developer exactly.
OK, the LED is still off and we can turn it on and off by writing 1
and 0
in the file value, as shown in the following commands:
root@wb:~# echo 1 > /sys/class...