rakeshpai/pi-gpio

GPIO-Admin and Read [Solved]

Closed this issue · 4 comments

I understand GPIO-Admin is recommended for x reasons.. my question relates to working without it or at least not having to worry about it.

When I try the read example

var gpio = require("pi-gpio");

gpio.open(16, "output", function(err) {     // Open pin 16 for output
    gpio.read(16, function(err, value) {
        if(err) throw err;
        console.log(value);    // The current state of the pin
        gpio.close(16);                     // Close pin 16
    });
});

It returns Error: ENOENT, open '/sys/devices/virtual/gpio/gpio23/value'.

Fixed by gpio-admin export 23

But then I need to un-export it to change its value..? I'm thinking of getting around this by just firing the export/un-export commands in my node.js app but it seems a bit cumbersome just to get the value so I'm guessing theres something I'm missing.. is there?

I saw that open/close are aliased to .export/.unexport which makes me think I'm not missing something but yeah, a bit confused at this point.

I read the code, and see that it's already doing what I was going to do.. (exec(gpio-admin..)).. so clearly it's my fault somewhere, I'll try find out where and why.

Edit Still can't figure out why this isn't working, tried with a new user, fresh gpio-admin, nodejs, npm etc.. install and nothing. Must be a pretty deep issue on my pi, time for a fresh raspbian and hopefully it will be resolved.

Resolved, was an issue on my part - special perms acting up.

Really enjoying pi-gpio though, great work!

Can you explain your permissions error? I'm running as root as getting that error.

gpio-admin: failed to change group ownership of /sys/devices/virtual/gpio/gpio23/direction: No such file or director

So close but i don't know how to fix it :(

Did you install gpio-admin as described in the Readme?

You could also just give this branch a try, which does not use gpio-admin.

I got it! My problem was that i installed nodejs via apt-get install nodejs. I had to reinstall nodejs using a debian specific branch from github(https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager). Whatever i got from apt-get was the culprit. Once i reinstalled nodejs, I was able to require modules correctly. I then reran quick2wire gpio-admin and did an nmp install pi-gpio.

Anyways now i can directly access my gpio pins from nodejs! So freaking cool!