Explanation
First, we wanted to use /bin/sh
to interpret this file. By default, the sysfs files for particular pins are not created until we export them. We echoed 68 to the /sys/class/gpio/
export file. This is a request to kernel to export the control of GPIO numbered 68 to the user space. After this command, the /sys/class/gpio68
folder gets created with the control files in it. Now, we can interact with these control files that will actually change the pin state. As we have attached an output LED to the P8_10
pin, we set the direction to out. As regular GPIO steps, we have to set the direction of P8_10
as output. Then, we can turn it on/off by writing 0/1
in the special sysfs file, /sys/class/gpio/gpio68/value
. We created an infinite loop using while
(true
), and in the loop, we write 0
and 1
to the sysfs file after a second. When we write 1
on this file, the LED attached to P8_10
will turn on. After a second, we write 0
on this file, which turns the LED off. You can get more information in the kernel documentation of the gpio sysfs interface at https://www.kernel.org/doc/Documentation/gpio/sysfs.txt. This way of accessing GPIO is possible on any Linux system (including Android).