JamesBarwell / rpi-gpio.js

Control Raspberry Pi GPIO pins with node.js
MIT License
657 stars 116 forks source link

write errno: -22 #79

Open xyboox opened 6 years ago

xyboox commented 6 years ago

Hi, I was trying to test the examples and seems like I'm stuck with this error: GPIO Setup ERROR: { Error: EINVAL: invalid argument, write errno: -22, code: 'EINVAL', syscall: 'write' }

Here's my code: `// GPIO var gpio = require('rpi-gpio');

var pin     = 4;
var delay   = 2000;
var countIO = 0;
var max     = 3;

gpio.setup(pin, 'out', on);

function on (err) {
    if (err) {
        logger.info('GPIO Setup ERROR: %O', err);
        return;
    }
    if (countIO >= max) {
        gpio.destroy(function() {
            logger.info('Closed pins, now exit');
        });
        return;
    }

    setTimeout(function() {
        gpio.write(pin, 1, off);
        countIO += 1;
    }, delay);
}

function off() {
    setTimeout(function() {
        gpio.write(pin, 0, on);
    }, delay);
}`

I'm using node v8.9.0 on a Raspberry Pi Zero User is added to gpio group.

Any idea about what's wrong? Thanks!

LE: I just saw that actually pin 4 ( one I'm trying to use ) is mapped to 7. So I change it in my code to 7. No I have another error: GPIO Setup ERROR: %O { Error: EBUSY: resource busy or locked, write errno: -16, code: 'EBUSY', syscall: 'write' }

thecodershome commented 6 years ago

Can you upload your debug log? Try adding DEBUG=rpi-gpio before your command

filiptc commented 5 years ago

Same thing happening here. GPIO (pin 2) interaction is fine via BASH. Debug output:

> var pomise = gpiop.setup(2, gpio.DIR_OUT)
      .then(() => gpiop.write(2, false))
      .catch(e => { console.log(e); });
undefined
>   rpi-gpio seen hardware revision 8322; using pin mode v2 +0ms
  rpi-gpio set up pin NaN +8ms
  rpi-gpio export pin NaN +5ms
{ [Error: EINVAL: invalid argument, write] errno: -22, code: 'EINVAL', syscall: 'write' }
filiptc commented 5 years ago

I switched to PIN 7 (GPIO4), which works fine. I guess SDA0 GPIO2, is not usable for some reason.