Posts: 2
Joined: Sat Jun 16, 2012 8:18 pm
Contact: Website

rpi-gpio.js - an asynchronous node.js GPIO module

Tue Jun 26, 2012 10:19 am

Hi all, I've written a node.js module to interface with the Rasperry Pi's GPIO pins. It is available here: https://github.com/JamesBarwell/rpi-gpio.js
or install with npm like this: npm install rpi-gpio

  • asynchronous interface for all pin operations
  • standard EventEmitter interface to listen to pin changes and more
  • support for addressing pins in either Raspberry Pi or BCM/SoC modes
  • auto-cleanup of exported pins
  • compatible with node.js versions 0.6.x and 0.8.x
  • npm package
  • jasmine tests
  • MIT licence
Hopefully others will find this useful. The GitHub page has various examples showing how to use it. I've tried to keep the interface as flexible as possible and stick to standard node.js conventions, so for example any errors should get passed up into your callbacks and be easily handled.

If there are any bugs or feature requests, please feel free to either let me know or create a pull request (with tests please!).


Posts: 1
Joined: Fri Jun 29, 2012 3:31 am

Re: rpi-gpio.js - an asynchronous node.js GPIO module

Fri Jun 29, 2012 3:39 am

What is performance like? Node.js is wonderful in many ways, but I'm a bit horrified at the amount of overhead it may have...

Posts: 2
Joined: Sat Jun 16, 2012 8:18 pm
Contact: Website

Re: rpi-gpio.js - an asynchronous node.js GPIO module

Tue Jul 03, 2012 7:46 pm

Hi, do you mean the performance of node.js in general? The only benchmark I've got at the moment is running the spec tests for my module. In each of the sets below, the first figure is provided by the 'time' command and the second is by the Jasmine test suite. Also, this is a bit unfair because my dev machine runs v0.8.0 and (due to the long compilation time!) I'm still on v0.6.19 on the R-Pi.

Dev machine (Ubuntu, 2.6ghz quad-core, 8gb RAM)
real 0m0.071s
Finished in 0.012 seconds

Rasperry Pi:
real 0m1.695s
Finished in 0.468 seconds

So with either result the R-Pi is a lot slower there. It's not a brilliant benchmark for real-world use though since it is surely CPU-bound and I would hope people aren't writing CPU intensive node.js apps. I don't know what you have in mind, but my plan is to run a web server that provides an API to control devices attached to the GPIO pins plus a static website that consumes the API. I imagine that most of the sluggishness would be in writing to the pins and initially hitting the filesystem on the SD card before the cache is warmed. So from what I've seen so far I'm not at all worried about the performance for that kind of use.

I would be interested to hear of other people's experiences and what kind of applications they're planning to run.


Return to “Other languages”

Who is online

Users browsing this forum: No registered users and 3 guests