pi-gpio
pi-gpio copied to clipboard
Switch to Wiring Pi GPIO utility
- switched to GPIO utility (via tjanson/pi-gpioutil) (see #25)
- automatic export/direction change on read/write (see
exportModeparam) - refactored pinMap, parameter parser, revision detection into separate modules
- readme updated; some examples; more tests
- (did not switch to native bindings (#26), but stayed with fs calls for read/write/{g,s}etDirection)
Let me know if any changes are required. Also: This passes all tests and works for me, but should still be tested manually.
Hello. I'm using this branch with my RPi A+. It seems to work so far. Is there something I could do to test it further and let it eventually merge into master?
@qrawl, @gausie Have you been using it so far without errors? Maybe we could get this merged after all.
Waiting for confirmation that someone has tested this. I don't have a Pi handy to test this on. Just one other person's confirmation would be good enough.
I've been using this branch with my A+ and although I haven't performed programmatic tests, I can say I haven't had any problems so far.
Awesome.
@tjanson Just looking through the code. Any reason you've used pi-gpioutil for some functions (like export, unexport), but not for others (read, write, etc.)? I don't have a problem with adding pi-gpioutil as a dep, but I'd rather the code be consistent with using pi-gpioutil or fs, but not both. And given the choice, I'd rather reduce deps than adding them.
It’s been a long time, let me try to remember.
- The purpose of this PR was mainly moving away from quick2wire gpio-admin (see #25).
- We had discussed moving to native bindings (see #26), but never implemented that.
- Until that is done, we should stay with
fscalls for speed (as opposed to theexeccalls of WiringPi’sgpiowhichpi-gpioUtiluses) – not sure if that’s really of practical concern, but it’s certainly the tried-and-true way.
seems to be working fine on Model B+, Revision: 1.2...
Great work tjanson on this branch. One suggestion on overloading the write and read method. Instead of passing a string type argument for 'force', why not pass an object. Something like:
write(23, 1, {exportMode: force}, callback);
This opens up flexibility for future additions and is more of a standard approach (at least in my experiences).
Just a thought. Looking forward to getting this merged in.
Yes, good point @risingtiger. I wasn’t very familiar with JS when I wrote that. There are probably other possible improvements too. I won’t implement that since I don’t have a Pi for testing at the moment (and other things on my mind). If you’re interested, feel free :)
Sure thing. I'll have a bit of time later today to jump in on it.
@tjanson I've pulled the gpioutil-fs-hybrid branch, overloaded the write/read methods with option objects and pushed back to my fork of pi-gpio here #37.
Hopefully we can get this all merged back to rakeshpai/pi-gpio soon.
Would love to see this merge. :) Anyone still working on it?
I just tried this branch on a Pi2 B+ and get the error:
ERROR [gpioUtil] exec failed: 'gpio export 26 out':
/bin/sh: 1: gpio: not found
ERROR [pi-gpio] failed to export pin 37
Edit:
Nevermind, I had to install WiringPI first, following the directions here: http://wiringpi.com/download-and-install/.
Edit 2:
OK, this runs without errors, but does not actually write values to the pins.
The node code:
gpio.write(37, 1);
opens gpio26 in "output" mode, but does not set the value to 1.
from a 2nd console:
> cat /sys/class/gpio/gpio26/direction
out
> cat /sys/class/gpio/gpio26/value
0
Also tested with a voltmeter. If I manually echo "1" > /sys/class/gpio/gpio26/value then I get voltage, but the JS call to .write(37, 1) does not have voltage.
Any ideas?
If varSysPath in line 15 of pi-gpio.js is "/sys/devices/virtual/gpio", then try changing that to the path you used: "/sys/class/gpio". I don’t have a Pi 2 (nor have I used this project in a while), but I guess this is the new location of the GPIO device.
Oh, this was in fact already filed as issue #45 by @alex-dacosta, and fixed (?) by https://github.com/rakeshpai/pi-gpio/commit/82ef7bddbb0af8edf03470023be71febeac6ed32 on master.