Raspi-io: Error: Unknown pin "null"

348 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

Your issue wasn't with any of your code, or a naming issue. You unfortunately chose poorly for which pin to use. P1-17 isn't able to accept an input, as it is dedicated 3.3v out. Choose another pin, and you should be fine.

Any pin reserved for I2C or Serial can't be used for regular GPIO function within Johnny Five, along with the dedicated power and ground pins which can't be used for IO, ever. As long as you avoid these ports, you'll be fine. A good resource on Raspberry Pi pinouts is here.