Comments (9)
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?
from onoff.
var Gpio = require('onoff').Gpio,
pir = new Gpio(3, 'in');
pir.read(function(value) {
console.log(value);
});
++++++++++++++++++++
always returns null value
+++++++++++++++++++++++
IR SENSOR: http://www.ebay.in/itm/331669024235?aff_source=Sok-Goog
with python it works fine
from onoff.
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);
});
from onoff.
yes it raspi, with the above code value is always 1.
even when we have an object
++++++++++++++++++++
working python code is
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.IN)
count = 0
while True:
i=GPIO.input(3)
if i==1:
print "Obstacle detected ",count
count += 1
time.sleep(0.1)
thanks for your help
from onoff.
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
from onoff.
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.
the above code reads current value correctly. i need to run the program continuously and if value is 1 (intruder alert) i need to print and continue sensing.....how to modify the program
thanks for your help
from onoff.
Good that you have it working now :)
To perform a task at regular intervals, setInterval
can be used. For example, to read the sensor every 100 milliseconds, try the following:
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.
from onoff.
thanks a lot
from onoff.
You're welcome :)
Have fun with onoff.
from onoff.
Related Issues (20)
- Problem using watch function with relay HOT 10
- Initialize GPIO without change pin status. HOT 6
- GPIO not working in a worker_thread - nodejs 14.15 HOT 2
- EACCES: permission denied, open '/sys/class/gpio/export' as superuser HOT 2
- Cannot run on non Rpi system HOT 1
- TypeError: writeSync is not a function HOT 4
- Raspberry Pi GPIO control in electron App HOT 8
- My computer does not have a /sys/class/gpio directory, but has /dev/gpiochip* HOT 1
- Interrupt misfire HOT 3
- Raspberry 4 - malloc(): corrupted top size HOT 3
- Error: EPERM: operation not permitted, write HOT 4
- Does not work with Compute Module 4. HOT 2
- Event is fired multiple times
- Superb library - I am running on Node v20 HOT 2
- Pi 5 Compatibility issues HOT 9
- Compatibility with ppp asked?
- RPI 5 gpio numbers HOT 2
- fs error HOT 8
- Newer version of epoll
- Button.watch spams endlessly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onoff.