JSPM

  • Created
  • Published
  • Downloads 621
  • Score
    100M100P100Q100003F
  • License ISC / GPL

Raspberry Pi GPIO library

Package Exports

  • rpio

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rpio) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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)
  }, 5)
}, 10)

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.