We used JavaScript and the Python language in this book. You do not always need to write complex programs to control GPIO. You can access GPIO using simple BASH shell commands. You will need to use the sysfs interface for this; sysfs is a virtual filesystem created by kernel to export information and control of subsystems and hardware devices. So, if you modify the control files in this filesystem, you change the actual hardware parameters.
Check the BeagleBone GPIO map diagram that we studied in Chapter 3, Blinking External LED
s. It has the mapping of pin numbers with GPIO names. The P8_10
pin is the GPIO
pin with number 68. It is given as gpio2[4]
in the BeagleBone System Reference Manual. This means that P8_10
is the fourth pin in the gpio2
bank. The BeagleBone processor has four banks of 32 GPIO
pins each—gpio0
, gpio1
, gpio2
, and gpio3
. Numbers 0-32 are given to gpio0
and 33-64 numbers are given to the gpio1
bank. So, the fourth pin in the gpio2
bank is actually the 68th GPIO
pin. Thus, P8_10
gets converted to GPIO number 68. This conversion works for all the GPIO
pins. We will need this number when dealing with GPIO on BASH.
Attach an external LED to P8_10
as we did in Chapter 3 for the blinking exercise. Write this shell program in Cloud9 or use the vi editor. Save it as blink.sh
and run it from the Cloud9 IDE or in the shell using the sudo chmod 755 blink.sh; sudo ./blink.sh
command:
#!/bin/sh echo 68 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio68/direction while(true) do echo 1 > /sys/class/gpio/gpio68/value sleep 1 echo 0 > /sys/class/gpio/gpio68/value sleep 1 done