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 leds_gpio:
# 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

The active_low file is similarly used to negate the value when it’s… well, active low!

Reference: <linux source>/Documentation/gpio.txt


One thought on “Controlling GPIOs in OpenWrt

  1. Pingback: SPI over GPIO in OpenWrt | Randomcoderdude's blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: