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

Afkar Rafique afkar.ec at gmail.com
Wed Oct 14 22:07:46 EDT 2015


Thanks for the reply.

i have Create /etc/init.d/buttons and written below script:

#!/bin/sh /etc/rc.common
START=19
start() {
        /bin/umount /etc/config 2>/dev/null
        echo out > /sys/class/gpio/gpio16/direction 2> /dev/null
        echo 16 > /sys/class/gpio/export 2> /dev/null
        if [ "$(cat /sys/class/gpio/gpio16/value)" == "1" ] ; then
            echo "255" >
/sys/devices/platform/leds-gpio/leds/db120:green:status/brightness
        else
            echo "0" >
/sys/devices/platform/leds-gpio/leds/db120:green:status/brightness
        fi
}

and restart .

chmod +x /etc/init.d/buttons
/etc/init.d/buttons enable
/etc/init.d/buttons start

Now i am able to read the GPIO 16 value 1/0 based on GPIO state, but as
above script i have written to ON/OFF the Status LED based on GPIO value,
Status LED is not getting OFF even if GPIO16 value is "0".

Can anyone please help on this


On Thu, Oct 15, 2015 at 12:37 AM, Martin Blumenstingl <
martin.blumenstingl at googlemail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20151015/97ba4375/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list