I've a problem with using node.js for RaspberryPi GPIO Programming. I am using the onoff library. This is my code:
var Gpio = require('onoff').Gpio,
led = new Gpio(20, 'out'),
button = new Gpio(18, 'in', 'both');
button.watch(function (err, value) {
if (err) {
throw err;
}
led.writeSync(value);
});
function exit() {
button.unexport();
}
process.on('SIGINT', exit);
The problem is that the attached button never triggers. When I use Python to read the button's value it works. I have already tried other node.js libraries like rpi-gpio, pi-gpio and wiring-pi. None of them worked for me. I'm using an Raspberry PI B+ with the latest Raspbian installed. Any ideas?
Maybe you could ensure you are connecting it to proper pins, as the GPIO and PIN numbers are not the same.
http://data.designspark.info/uploads/images/53bc258dc6c0425cb44870b50ab30621
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With