JamesBarwell / rpi-gpio.js

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

pin turn off during the 'read' operation. #24

Closed roccomuso closed 7 years ago

roccomuso commented 9 years ago

This is my code:

exports.get = function(pin){ // perchè il file functions.js è incluso esternamente

gpio.setup(pin, gpio.DIR_IN, read_state);

function read_state() {
        gpio.read(pin, function(err, value) {
            var state = (value) ? "on": "off"; // The current state of the pin (true: on or false: off)
            console.log("The value is: "+state);
            return {response_code: 200, new_state: stato, path: "/toggle"};
        });
}
gpio.destroy();

};

When i call exports.get(11) it actually turns off the gpio 11 and print 'the value is: off'.

Why is turning off the Pin? o.O

JamesBarwell commented 9 years ago

The code example is buggy, in that you're running setup and then immediately (before read_state is called) running destroy.

But I'm going to leave this open and have a go at re-creating it because I still wouldn't expect it to turn the pin off.

JamesBarwell commented 7 years ago

I can't re-create this. After running the (fixed) code, it sets up with a value 'on'. The read operation doesn't change its state.

The new version 0.8.0 of the module allows you to explicitly set the pin into a high or low state so perhaps you may want to use that in order to setup the pin in the desired state.