Using GPIOs with scripting languages
Having the possibility to manage the GPIO lines in a scripting language in an easy manner allows us to have a powerful tool to speed up simple tasks involving these peripherals. That's why in this section, we're going to see how the GPIO lines can be managed in both PHP and Python scripting languages in a manner similar to what we did in C.
However, in order to keep the code simple, we suppose that the GPIO lines gpio24
and gpio91
have been exported in some way already. For example, we can properly set them up with the following well-known commands:
root@wb:~# echo 24 > /sys/class/gpio/export root@wb:~# echo in > /sys/class/gpio/gpio24/direction root@wb:~# echo falling > /sys/class/gpio/gpio24/edge root@wb:~# echo 91 > /sys/class/gpio/export root@wb:~# echo in > /sys/class/gpio/gpio91/direction root@wb:~# echo falling > /sys/class/gpio/gpio91/edge
Now the GPIO lines are ready to be used by the next two programs that are going to use their...