Controlling GPIOs in OpenWrt
This is a small guide to control GPIOs on OpenWrt.
First of all, you may need to unload other modules that could be using the GPIOs you want. In particular, if you want to use a GPIO which is connected to a led you’ll probably need to unload
# rmmod leds_gpio
Every GPIO will have an entry in
/sys/class/gpio. If you don’t see the GPIO that you want to use then it has not been configured yet. You do so by writing the GPIO number in the export file, for example:
# echo 26 > export
Then a directory for that gpio will appear, in my case
gpio26. In this directory we find the files we need to control this gpio.
You want to write out to the
direction file to use it as an output, or
in to use it as an input:
# echo out > direction
# echo in > direction
The value file is used to – you guessed it – set or get the status of the GPIO:
# echo 0 > value
# echo 1 > value
# cat value
active_low file is similarly used to negate the value when it’s… well, active low!