Skip to content
Bryan Hughes edited this page Sep 11, 2015 · 17 revisions

Raspi-io is a Firmata API compatible library for Raspbian running on the Raspberry Pi that can be used as an I/O plugin with Johnny-Five. The API docs for this module can be found on the Johnny-Five Wiki. Raspi IO supports the Model B Rev 1, Model B Rev 2, Model A+, Model B+, and Raspberry Pi 2 Model B,p but does not support the Model A.

Installation

npm install raspi-io

Usage

Using raspi-io inside of Johnny-Five is pretty straightforward, although does take an extra step compared to the Arduino Uno:

var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
  io: new raspi()
});

board.on('ready', function() {

  // Create an Led on pin 7 (GPIO4) on P1 and strobe it on/off
  // Optionally set the speed; defaults to 100ms
  (new five.Led('P1-7')).strobe();

});

The io property must be specified explicitly to differentiate from trying to control, say, an Arduino Uno that is plugged into the Raspberry Pi. Note that we specify the pin as "P1-7", not just 7. See the section on pins below for an explanation of the pin numbering scheme on the Raspberry Pi.

Note: This module is not intended to be used directly. If you do not want to use Johnny-Five, I recommend taking a look at Raspi.js, which underpins this library and is a little more straightforward to use.

Pin Mappings

The pins on the Raspberry Pi are a little complicated. There are multiple headers on some Raspberry Pis with extra pins, and the pin numbers are not consistent between Raspberry Pi board versions.

To help make it easier, you can specify pins in three ways. The first is to specify the pin by function, e.g. 'GPIO18'. The second way is to specify by pin number, which is specified in the form "P

-", e.g. 'P1-7'. The final way is specify the Wiring Pi virtual pin number, e.g. 7. If you specify a number instead of a string, it is assumed to be a Wiring Pi number.

Here is a table of the pin mappings on all of the support Raspberry Pi boards.

Model B Rev 1

P1 Header

Physical Pin Wiring Pi Pin Peripherals Peripherals Wiring Pi Pin Physical Pin
1 3.3V 5V 2
3 SDA0 5V 4
5 SCL0 GND 6
7 7 GPIO4 GPIO14/TXD0 15 8
9 GND GPIO15/RXD0 16 10
11 0 GPIO17 GPIO18/PWM0 1 12
13 2 GPIO21 GND 14
15 3 GPIO22 GPIO23 4 16
17 3.3V GPIO24 5 18
19 12 GPIO10/MOSI0 GND 20
21 13 GPIO9/MISO0 GPIO25 6 22
23 14 GPIO11/SCLK0 GPIO8/CE0 10 24
25 GND GPIO7 11 26

Model B Rev 2

P1 Header

Physical Pin Wiring Pi Pin Peripherals Peripherals Wiring Pi Pin Physical Pin
1 3.3V 5V 2
3 SDA0 5V 4
5 SCL0 GND 6
7 7 GPIO4 GPIO14/TXD0 15 8
9 GND GPIO15/RXD0 16 10
11 0 GPIO17 GPIO18/PWM0 1 12
13 2 GPIO27 GND 14
15 3 GPIO22 GPIO23 4 16
17 3.3V GPIO24 5 18
19 12 GPIO10/MOSI0 GND 20
21 13 GPIO9/MISO0 GPIO25 6 22
23 14 GPIO11/SCLK0 GPIO8/CE0 10 24
25 GND GPIO7 11 26

P5 Header

Physical Pin Wiring Pi Pin Peripherals Peripherals Wiring Pi Pin Physical Pin
1 5V 3.3V 2
3 17 GPIO28 GPIO29 18 4
5 19 GPIO30 GPIO31 20 6
7 GND GND 8

Model A+/B+/Raspberry Pi 2

P1 Header

Physical Pin Wiring Pi Pin Peripherals Peripherals Wiring Pi Pin Physical Pin
1 3.3V 5V 2
3 SDA0 5V 4
5 SCL0 GND 6
7 7 GPIO4 GPIO14/TXD0 15 8
9 GND GPIO15/RXD0 16 10
11 0 GPIO17 GPIO18/PWM0 1 12
13 2 GPIO27 GND 14
15 3 GPIO22 GPIO23 4 16
17 3.3V GPIO24 5 18
19 12 GPIO10/MOSI0 GND 20
21 13 GPIO9/MISO0 GPIO25 6 22
23 14 GPIO11/SCLK0 GPIO8/CE0 10 24
25 GND GPIO7/CE1 11 26
27 ID_SD ID_SC 28
29 21 GPIO5 GND 30
31 22 GPIO6 GPIO12/PWM0 26 32
33 23 GPIO13 GND 34
35 24 GPIO19/MISO1/PWM1 GPIO16 27 36
37 25 GPIO26 GPIO20/MOSI1 28 38
39 GND GPIO21/SCLK1 29 40
Clone this wiki locally