OpenWrt Forum Archive

Topic: Q: Are GPIOs available on WL-520gu?

The content of this topic has been archived on 12 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm wondering about how to access the gpios on the WL-520gu.  This thread says "4 gpio’s available on the board: Power LED, wifi LED, EZsetup button and reset button" but provides no information about how to access them:  http://mightyohm.com/blog/2009/02/build … g-control/

In this openWrt thread, on 2008-03-30, Bartman007 says "I have patches that properly detect it and map the button/led GPIOs correctly. Hopefully I'll commit that tomorrow", but no more information is given: https://forum.openwrt.org/viewtopic.php?id=15102

Here, in a thread not related to the WL-520gu (so the pin number might differ), someone says "the first prerequisite is that u must have gpioctl package installed" and then you can turn on and off with "gpioctl set 0" and "gpioctl clear 0": https://forum.openwrt.org/viewtopic.php?id=16828

I opkg installed gpioctl and rebooted, but when I do "gpioctl set 0" I get "Error whilst opening /dev/gpio".  "ls /dev" shows that there is no /dev/gpio.  There is nothing in /etc/config or /etc/init.d relating to gpio.  There is /etc/init.d/leds, which refers to /sys/class/leds, but that doesn't exist.

What do I need to do to enable and turn on and off the gpios on this router?

lizby, why not just use the on-board serial pins to talk to a uC?

>lizby, why not just use the on-board serial pins to talk to a uC?

I could do that, and plan to do it for another project, but for this one, I just need a single on/off to trigger an event at various times.  The wireless led would be perfect for that, since I already have cat6 where I need it and don't intend to use wireless (tho client bridge would be very nice).

What about "tapping" off the resistor that goes to the LED? Does it show up in /proc/diag ?

Dave

Ok, for output, the gpioctl command has a form of "gpioctl set|clear ioNumber".  The action is somewhat counter-intuitive on this router because "clear" turns on i/o0 (the power led), but turns off i/o1 (the wireless led), while "set" does the opposite.

So, "gpioctl clear 0" turns the power led +on+, and "gpioctl set 0" turns the power led +off+ and "gpioctl clear 1" turns the wireless led +off+, and "gpioctl set 1" turns the wireless led +on+.  I would have expected that "set" would turn an led on and "clear" would turn it off, but the hardware may invert the signal at some point.

For input, gpioctl has a form of "gpioctl get ioNumber".  When the power led is on, "gpioctl get 0" returns "Pin 0 is LOW" (consistant with the command of "gpioctl clear 0" turning it on.  When the wireless led is on, "gpioctl get 1" returns "Pin 1 is HIGH".

I haven't tried finding the input pin numbers of the EZsetup button and the reset button because I'm afraid openWrt or something below openWrt may be monitoring them (and I don't need inputs).

Excellant suggestion, kupesoft--I didn't know about /proc/diag/led.  It contains two files (hmm, 0-byte files--maybe they're something else--or, as is said, everything in Linux is a file), power and wlan.  They act like files in that cat /proc/diag/led/power or /wlan returns the status of the LED (1 for on, 0 for off--regardless of the fact that when the power led is on, gpio #0 is low).  Doing "echo 1 > /proc/diag/led/wlan" will turn the wlan light on, and "echo 0 > /proc/diag/led/wlan" will turn it off.  The same syntax works for power--it isn't inverted like the gpio setting. 

So I will be able to get out my multi-tester and see which led pin is high, and tap off of that to get the single controlled high/low that I want.  I don't intend to use wireless, so there should be nothing causing unplanned settings and resettings on the wlan led.

Addendum:  didn't need the multitester--plus is marked on the board.  But the tester shows 3.25 volts with respect to ground on the plus side of the led whether or not it is on, and the same on an led which is off, but 1.2 volts on the low side of an led which is on, so the led is switched on the low side.  If you take off from the low side, high (>2 volts) will indicate that the led is off, and low will indicate that the led is on.  I may have to condition the signal (or find another take-off point) to get true (not inverted) logic, and to get a true 0 volts reading.

The point immediately under the minus leg of the led goes from 3.25 volts when the led is off to .25 when it is on--inverted but a good enough swing to provide what I need.  A very precise soldering job, tho.

(Last edited by lizby on 7 Dec 2009, 04:27)

lizby, just solder a joint at the beginning the SMD resistor (probably ~200-300 ohms) before the LED. Use a multimeter to figure out where/what you want. I wouldn't draw too much current, though. Maybe there's a better way, but I don't have that board.

The discussion might have continued from here.