heimcontrol.js icon indicating copy to clipboard operation
heimcontrol.js copied to clipboard

gpio input not working

Open kratostav opened this issue 11 years ago • 7 comments

Gpio input shows as down. It doesnt go up. raspberry pi revision 0000d

kratostav avatar Oct 15 '14 14:10 kratostav

What’s the output of ls /sys/devices/virtual/gpio? Without more info I’d suspect that the Pin isn’t exported, because, well, apparently the GPIO plugin doesn’t do that. So a manual gpio export [pin] in (where [pin] is the BCM pin number [why!?]) should fix it. Of course this really should be done by the plugin, or at least documented better.

tjanson avatar Oct 15 '14 17:10 tjanson

ls gives: pi@schretterpi ~ $ ls /sys/devices/virtual/gpio gpiochip0 pi@schretterpi ~ $

gpio export (command not found?? pi@schretterpi ~ $ gpio export pin 17 in -bash: gpio: command not found

Why is there a gpiochip0 only? Output is working properly

kratostav avatar Oct 15 '14 18:10 kratostav

got it working with pi@schretterpi ~ $ echo 17 > /sys/class/gpio/export pi@schretterpi ~ $ echo in > /sys/class/gpio/gpio17/direction

gpio

but why i have to do this manually?

kratostav avatar Oct 15 '14 18:10 kratostav

I’m not familiar with this part of the code. Looks like it was simply forgotten. I’ll look into it.

tjanson avatar Oct 15 '14 21:10 tjanson

Maybe it works if you change line 80 in plugins/gpio/index.js (https://github.com/ni-c/heimcontrol.js/blob/master/plugins/gpio/index.js#L80) from

gpio.setDirection(parseInt(item.pin), "input", function(err) {

to

gpio.open(parseInt(item.pin), "input", function(err) {

I have no time to test it now, but i think this could be the problem.

ni-c avatar Oct 16 '14 08:10 ni-c

I'm working on a fix. I'll rewrite the pi-gpio library.

Seems drastic, but it's overdue. Switching the underlying export mechanism from quick2wire's gpio-admin to Wiring Pi's gpio should improve lots of things including this issue, because its export can be called multiple times, whereas gpio-admin export errors if called on an open pin. (See rakeshpai/pi-gpio#24.)

tjanson avatar Oct 16 '14 09:10 tjanson

Here’s what I’ve been working on: tjanson/heimcontrol.js@ad79484f1ccd8cb130512be2df0e9868bbae7cb6 (which uses a rewritten version of pi-gpio, which uses a wrapper of Wiring Pi gpio util).

Feel free to give it a try. I’ll write a PR once I have some feedback here: rakeshpai/pi-gpio#25.

tjanson avatar Oct 19 '14 17:10 tjanson