gpio - talk to your Raspberry Pi's gpio headers
- demo using LED: http://www.youtube.com/watch?v=2Juo-CJ6eu4
- demo using RC car: http://www.youtube.com/watch?v=klQdX8-YVaI
Installation
Get node.js on your Raspberry Pi
On Raspbian, you can simply run apt-get install nodejs
,
otherwise, compile it
Usage
This library is an npm package, just define "gpio" in your package.json dependencies or
npm install gpio
Note: you must be running as root or have the proper priviledges to access the gpio headers
Standard setup
var gpio = ; // Calling export with a pin number will export that header and return a gpio header instancevar gpio4 = gpio;
Header direction "in"
If you plan to set the header voltage externally, use direction in
and read value from your program.
var gpio = ;var gpio4 = gpio;
API Methods
// sets pin to highgpio4;
// sets pin to low (can also call gpio4.reset())gpio4;
// Since setting a value happens asynchronously, this method also takes a// callback argument which will get fired after the value is setgpio4;gpio4;
// unexport program when donegpio4;
EventEmitter
This library uses node's EventEmitter which allows you to watch for value changes and fire a callback.
// bind to the "change" eventgpio4; // you can bind multiple eventsvar { console; };gpio4; // unbind a particular callback from the "change" eventgpio4; // unbind all callbacks from the "change" eventgpio4; // you can also manually change the direction anytime after instantiation gpio4;gpio4;
Example
Cycle voltage every half a second
var gpio = ;var gpio22 gpio4 intervalTimer; // Flashing lights if LED connected to GPIO22gpio22 = gpio; // Lets assume a different LED is hooked up to pin 4, the following code // will make that LED blink inversely with LED from pin 22 gpio4 = gpio; // reset the headers and unexport after 10 seconds
Controlling an RC car
Source code here: https://github.com/EnotionZ/node-rc