-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to read value from IR obstacle sensor #48
Comments
On which type of system are you having the issue, a Raspberry Pi? If it is a Raspberry Pi, is it GPIO3 on pin 5 of the GPIO header? Can you post a link to a description of the IR obstacle sensor being used? Can you post the code which has the issue? |
var Gpio = require('onoff').Gpio, pir.read(function(value) { with python it works fine |
I'm assuming that we're talking about a Raspberry Pi here and that GPIO3 is Pin 5 on the GPIO header. The read completion callback is passed two arguments, err and value. Try with the following code: var Gpio = require('onoff').Gpio,
pir = new Gpio(3, 'in');
pir.read(function(err, value) {
if (err) {
throw err;
}
console.log(value);
}); |
yes it raspi, with the above code value is always 1. thanks for your help |
There are multiple ways of numbering the pins on the Raspberry Pi GPIO header. The above Python program uses the BOARD numbering system. There is also the BCM numbering system. onoff uses the BCM numbering system. The above Python program IS NOT USING GPIO3, IT'S USING GPIO2 Please look at this image of the GPIO header: http://www.raspberrypi-spy.co.uk/wp-content/uploads/2012/06/Raspberry-Pi-GPIO-Layout-Model-B-Plus-rotated-2700x900.png Is it correct that the IR obstacle sensor is connected to GPIO2, which is pin 3 on the GPIO header? If this is correct, please try with the following program: var Gpio = require('onoff').Gpio,
pir = new Gpio(2, 'in');
pir.read(function(err, value) {
if (err) {
throw err;
}
console.log(value);
}); EDIT: Modified the program to use GPIO2 |
yes, thanks a lot changing to use GPIO 2 in code works fine. sorry for the trouble. i am new to this and programming as well. |
Good that you have it working now :) To perform a task at regular intervals, var Gpio = require('onoff').Gpio,
pir = new Gpio(2, 'in');
setInterval(function () {
pir.read(function(err, value) {
if (err) {
throw err;
}
console.log(value);
});
}, 100); I'm going to close this issue now as the initial issue has been resolved. |
thanks a lot |
You're welcome :) |
hi
im not getting correct value when using read(err,value) or readSync functions.
im using Gpio 3 for IR sensors output
pls help
thanks in advance
The text was updated successfully, but these errors were encountered: