Git Product home page Git Product logo

Comments (9)

fivdi avatar fivdi commented on July 22, 2024

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.

m-devan avatar m-devan commented on July 22, 2024

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.

fivdi avatar fivdi commented on July 22, 2024

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.

m-devan avatar m-devan commented on July 22, 2024

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.

fivdi avatar fivdi commented on July 22, 2024

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.

m-devan avatar m-devan commented on July 22, 2024

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.

fivdi avatar fivdi commented on July 22, 2024

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.

m-devan avatar m-devan commented on July 22, 2024

thanks a lot

from onoff.

fivdi avatar fivdi commented on July 22, 2024

You're welcome :)
Have fun with onoff.

from onoff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.