we are using rpi-gpio and node.js to read/write to raspberry version 1 pins.
we have a led connected to gnd (pin 3) and gpio4 (pin 7).
using write works perfectly:
gpio.setup(7, gpio.DIR_OUT, write);
function write() {
gpio.write(7, true, function(err) {
if (err) throw err;
console.log('Written to pin');
});
}
although using the read function
gpio.setup(7, gpio.DIR_IN, readInput);
function readInput() {
gpio.read(7, function(err, value) {
console.log('The value is ' + value);
});
}
leads to the following behavior:
1) the led is turned off 2) the status of the gpio pin is always true
setting the the port to "true" so the led is light makes no difference. when reading the pin the led is off and pin is true.
the same but inverse is with pin 11, 12 - led is off and pin false.
using a listener for value changes on the specific pin works ... although i really want to read the pin-value on demand!
For writing, you set the GPIO pin as an output (which is good). But when you try to 'read' you set the GPIO pin as an input which changes the mode of the pin. So try to remove:
gpio.setup(7, gpio.DIR_IN, readInput);
From the Raspberry Pi forum:
Five of the 17 available GPIO lines are pulled high by default (the rest are pulled low). The numbers are GPIO0/2, GPIO1/3, GPIO4, GPIO7 and GPIO8.