Failed to get GPIO output value in node.js

I have a problem using node.js to program the RaspberryPi GPIO. 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 starts. When I use Python to read the value of a button, 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 am using Raspberry PI B + with the latest Raspbian installed. Any ideas?

+4
source share
1 answer

Perhaps you can make sure that you connect it to the corresponding contacts, as the GPIO and PIN numbers do not match.

http://data.designspark.info/uploads/images/53bc258dc6c0425cb44870b50ab30621

+1
source

All Articles