JamesBarwell / rpi-gpio.js

Control Raspberry Pi GPIO pins with node.js
MIT License
658 stars 115 forks source link

Cannot open pin for read #53

Open javirs85 opened 7 years ago

javirs85 commented 7 years ago

Im running raspi Model B Rev 2 512MB, I installed the module and succesfully opened a pin for writing on it. Succesfully made a LED blink. Then I try to open a port for reading and I get and error

{ Error: EINVAL: invalid argument, write errno: -22, code: 'EINVAL', syscall: 'write' }

This the relevant part of the code.

var gpio = require('rpi-gpio');
server.listen(8080, function() {
    console.log('Servidor corriendo en http://localhost:8080');

    gpio.setup(7, gpio.DIR_OUT, control);
    gpio.setup(6, gpio.DIR_IN, control);
});

function control(err)
{
    if(err)
        console.log("Control function: " + err);
    else
        console.log('ok');
}

Any clue ??

javirs85 commented 7 years ago

Ok, error was that pin 6 i GND. GPIO6 is actually mapped to pin 22. Setting 22 solved the isue.

Is there a way to name pins in a form other than the physical pin? I´m using a custom expansion board and this is hell :(

thecodershome commented 7 years ago

There is a fork of this repo that has MODE_RAW. https://github.com/timelapseplus/node-linux-gpio

javirs85 commented 7 years ago

sorry, I'm new to github, how can I choose to install the forked version?

and.. what's the mode RAW ? in the link u sent me there is nothing about it.. :(

thecodershome commented 7 years ago

To install the forked repo run npm install timelapseplus/node-linux-gpio or npm install timelapseplus/node-linux-gpio --save to add the repo to your dependencies. Since the package name was changed you will need to use var gpio = require('linux-gpio') instead of var gpio = require('rpi-gpio').

If you use gpio.setMode(gpio.MODE_RAW) you can "attempt" to use any channel.

function getPinRaw(channel) {
        return channel + '';
    };
javirs85 commented 7 years ago

can you gimme an example of "channel" ?

thecodershome commented 7 years ago

gpio.setup(7, gpio.DIR_OUT)

Take a look at this, https://pinout.xyz/pinout/pin3_gpio2 It should help with picking channels.

thecodershome commented 7 years ago

By default this library uses the physical pin values, MODE_RPI.

javirs85 commented 7 years ago

My pi is 1 rev 2, I only have 26 pins so the graph is not fitting my setup. Anyhow, what's the raw name I have to enter to access GPIO6 ?