Nodejs GPIO pin usage - gpio-admin: failed to change group ownership

I am trying to use nodejs on my Raspberry PI to read a value from a light sensor which is attached. I can get the reading out of a python program and can confirm my setup is correct.

Below is the program

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

gpio.open(12, "output", function(err) {     // Open pin 12 for output 
    gpio.read(12, function(err,value) {         // Set pin 16 high (1) 
        console.log(value);
        gpio.close(12);                     // Close pin 16 
    });
});

Below is the error message

pi@raspberrypi:~/Samples $ node GPIO.js
Error when trying to open pin 12
gpio-admin: failed to change group ownership of /sys/devices/virtual/gpio/gpio18/direction: No such file or directory

I had earlier installed pi-gpio module as shown below

pi@raspberrypi:~/Samples $ npm install pi-gpio

Upvotes: 2

Views: 1524

Answers (1)

v7d8dpo4
v7d8dpo4

Reputation: 1399

Make sure you are using the newest version of pi-gpio and gpio-admin.

The path for gpio in kernel since 3.18.x has been changed to /sys/class/gpio/. The old version of pi-gpio and gpio-admin only supported /sys/classes/virtual/gpio/. The newer version also supports /sys/class/gpio/.


Edit:

Run

npm update pi-gpio

If the problem still exists, build the newest version of gpio-admin yourself.

Choose a directory you want to put gpio-admin in, and run

git clone https://github.com/quick2wire/quick2wire-gpio-admin.git
cd quick2wire-gpio-admin

If src/gpio-admin.c has

int size = snprintf(path, PATH_MAX, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);

change it to

int size = snprintf(path, PATH_MAX, GPIO_CLASS_PATH "gpio%u/%s", pin, filename);

Then, run make

Then, run

make install

as root.

Upvotes: 1

Related Questions