[OpenWrt-Devel] How to config GPIO and read the GPIO value in OpenWRT

Martin Blumenstingl martin.blumenstingl at googlemail.com
Wed Oct 14 12:37:13 EDT 2015

On Wed, Oct 14, 2015 at 12:19 PM, Afkar Rafique <afkar.ec at gmail.com> wrote:
> Could anyone please explain how i can configure and read GPIO value.
There's an article on the wiki which explains how to set a GPIO to a
specific value: [0]
If you want to read a GPIO value then you use direction "in" and then
simply cat to read the "value".

The only thing that you might have to do is doing a bit of maths to
get the correct GPIO number.
When you are trying to read GPIO #16 then it's GPIO #16 of a specific
chip -> /sys/class/gpio/ should contain a file gpiochipNNN.
What you do is take NNN (let's assume it's 456) and add your GPIO
number to it: 456 + 16 = 472 -> this is the number needef to "export"
the GPIO.

[0] http://wiki.openwrt.org/doc/hardware/port.gpio#software
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list