node.jsraspberry-pimotion-detectionjohnny-five

Raspi-io: Error: Unknown pin "null"


I'm using the johnn-five and raspi-io packages for node and I'm trying to read the events created on a PIR motion sensor, but everytime I run the application, an error is thrown.

console

pi@raspberrypi ~/poc $ sudo node app.js 
1439476578608 Device(s) RaspberryPi-IO  
1439476578749 Connected RaspberryPi-IO  
1439476578825 Repl Initialized  
>> /home/pi/poc/node_modules/raspi-io/lib/index.js:316
      throw new Error("Unknown pin \"" + pin + "\"");
            ^
Error: Unknown pin "null"
    at Raspi._defineProperty.value (/home/pi/poc/node_modules/raspi-io/lib/index.js:316:17)
    at Raspi.pinMode (/home/pi/poc/node_modules/raspi-io/lib/index.js:327:47)
    at Motion.Controllers.PIR.initialize.value (/home/pi/poc/node_modules/johnny-five/lib/motion.js:27:17)
    at new Motion (/home/pi/poc/node_modules/johnny-five/lib/motion.js:180:10)
    at Board.<anonymous> (/home/pi/poc/app.js:9:16)
    at Board.emit (events.js:104:17)
    at process._tickDomainCallback (node.js:381:11)

package.js

{
  "name": "poc",
  "version": "0.0.1",
  "main": "app.js",
  "private": true,
  "dependencies": {
    "johnny-five": "0.8.86",
    "raspi-io": "3.3.4"
  }
}

app.js

var raspi = require('raspi-io');
var five  = require('johnny-five');

var board = new five.Board({
  io: new raspi()
});

board.on('ready', function() {
  var motion = new five.Motion({pin: 'PI-17'});

  motion.on('calibrated', function() {
    console.log('calibrated');
  });

  motion.on('motionstart', function() {
    console.log('motionstart');
  });

  motion.on('motionend', function() {
    console.log('motionend');
  });
});

However, the following code DOES seem to work:

snipped from another poc

var raspi = require('raspi');
var gpio = require('raspi-gpio');

raspi.init(function() {

  var input = new gpio.DigitalInput({
    pin: 'P1-17'
  });

  var logInput = function() {
    console.log('Input 17: ' + input.read());
    setTimeout(logInput, 1000);
  };

  logInput();

});

The Raspberry is a Rev. 2 model B.
The Motion detector I'm using is this one.
The cables are connected as follows (physical pin, taken from this schema)

Motion Sensor -> Pi  
1 GND ->  6 GND    
2 VDD ->  1 +3/V3 OUT  
3 OUT -> 11 GPIO17  

Any help would be greatly appreciated.


Solution

  • After more searching I came across this image.

    this image

    It provided me with more insight on the WiringPi Pin numbers, BCM GPIO naming and P1 naming.

    The pin GPIO0 on Pin 0 (BCM 17) seems to be throwing the error.

    I switched to using pin GPIO4 on Pin 4 (BCM 23).

    It doesn't really make sense why the 0 doesn't work, but for now, the poc I'm working on can progress again.