1

I've setup my Raspberry Pi 2 Model B v1.1 with Node.js v8.7 and installed the rpi-gpio module.

I used Node shell (REPL) to test the module, and it worked like a charm. But when I put the same 3 lines of code in app.js and try a node app.js I get the following error. Code added below for reference.

Error:

/home/pi/PiClient/node_modules/rpi-gpio/rpi-gpio.js:358
        return currentPins[channel] + '';
                          ^

TypeError: Cannot read property '7' of undefined
    at getPinRpi (/home/pi/PiClient/node_modules/rpi-gpio/rpi-gpio.js:358:27)
    at Gpio.read.input (/home/pi/PiClient/node_modules/rpi-gpio/rpi-gpio.js:266:19)
    at Object.<anonymous> (/home/pi/PiClient/test.js:5:6)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)

Code:

var gpio = require('rpi-gpio');
gpio.(7, gpio.DIR_IN);
gpio.read(7, function (err, val) {
   console.log(err, val);
});

1 Answer 1

1

Looking at the documentation and your code it looks like you may not have called the SETUP method correctly:

var gpio = require('rpi-gpio');

gpio.setup(7, gpio.DIR_IN, readInput);

function readInput() {
    gpio.read(7, function(err, value) {
        console.log('The value is ' + value);
    });
}

Looking at your code the second line is:

gpio.(7, gpio.DIR_IN);

which looks to me like you are missing the method name after the first '.'

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.