pi-gpio icon indicating copy to clipboard operation
pi-gpio copied to clipboard

Switch to Wiring Pi GPIO utility

Open tjanson opened this issue 11 years ago • 14 comments

  • switched to GPIO utility (via tjanson/pi-gpioutil) (see #25)
  • automatic export/direction change on read/write (see exportMode param)
  • 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.

tjanson avatar Oct 31 '14 22:10 tjanson

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?

pierreprinetti avatar Jan 18 '15 22:01 pierreprinetti

@qrawl, @gausie Have you been using it so far without errors? Maybe we could get this merged after all.

tjanson avatar May 04 '15 20:05 tjanson

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.

rakeshpai avatar May 06 '15 07:05 rakeshpai

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.

pierreprinetti avatar May 06 '15 07:05 pierreprinetti

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.

rakeshpai avatar May 06 '15 10:05 rakeshpai

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 fs calls for speed (as opposed to the exec calls of WiringPi’s gpio which pi-gpioUtil uses) – not sure if that’s really of practical concern, but it’s certainly the tried-and-true way.

tjanson avatar May 06 '15 10:05 tjanson

seems to be working fine on Model B+, Revision: 1.2...

risingtiger avatar May 06 '15 17:05 risingtiger

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.

risingtiger avatar May 07 '15 15:05 risingtiger

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 :)

tjanson avatar May 07 '15 15:05 tjanson

Sure thing. I'll have a bit of time later today to jump in on it.

risingtiger avatar May 07 '15 15:05 risingtiger

@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.

risingtiger avatar May 13 '15 16:05 risingtiger

Would love to see this merge. :) Anyone still working on it?

ccarterc avatar Sep 12 '15 04:09 ccarterc

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?

rally25rs avatar Feb 27 '16 14:02 rally25rs

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.

tjanson avatar Feb 28 '16 18:02 tjanson