/node-rpio

Raspberry Pi GPIO library for node.js

Primary LanguageObjective-C

node-rpio

This is a node.js add-on which wraps around Mike McCauley's bcm2835 library to allow mmap access via /dev/mem to the GPIO pins.

If you want something more featureful then for now you should check out James Barwell's rpio-gpio.js. The reason for me writing this module instead of using James' is that his uses the /sys interface which is too slow for my requirements.

Install

Easily install the latest via npm:

$ npm install rpio

API

var rpio = require('rpio')

// Enable a pin and mark as read-only
rpio.setInput(11)

// Enable a pin and mark as read-write
rpio.setOutput(12)

// Read value of pin
console.log('pin 11 is set to ' + rpio.read(11))

// Set pin high (i.e. write '1' to it)
rpio.write(12, rpio.HIGH)

Simple demo

/*
 * Simple demo to flash pin 11 at 100Hz (assuming it's routed to an LED).
 */
var rpio = require('rpio')

// Set the pin for write mode
rpio.setOutput(11)

// Set the pin high every 10ms
setInterval(function() {
  rpio.write(11, rpio.HIGH)
}, 10)

// Set the pin low every 10ms, offset by 5ms.
setTimeout(function() {
  setInterval(function() {
    rpio.write(11, rpio.LOW)
  }, 10)
}, 5)

## Authors and licenses

Mike McCauley wrote src/bcm2835.{cc,h} which are under the GPL.

I wrote the rest, which is under the ISC license unless otherwise specified.