SimpleRpiGpio
Very simple class to Raspberry PI's GPIO port usage
Installation
You can install the library with NPM:
$ npm install git://github.com/jvcalderon/SimpleRpiGpio
Now you only need to require SimpleRpiGpio in your project:
var gpio = require('SimpleRpiGpio');
In Raspberry PI, only root can use GPIO pin. You have to install quick2wire-gpio-admin to use the library without sudo. if you haven't yet installed this library, you can do it as follows:
$ git clone git://github.com/quick2wire/quick2wire-gpio-admin.git
$ cd quick2wire-gpio-admin
$ make && sudo make install
$ sudo adduser $USER gpio
Library methods
Method | Parameters | Description |
open | (pinNumber, direction [out|in]) | Open a GPIO pin by using the pin number. This action is needed before read or write |
openAll | (direction [out|in]) | Open all GPIO pins with same direction (out or in) |
out | (pinNumber, action [0|1]) | Sends signal to Rpi's GPIO pin number |
getGpioNumber | (pinNumber) | Get the GPIO number associated to pin number |
Usage
First you need to open the pins needed to write (out) or read (in). For example:
gpio.open(7, 'out'); //to open GPIO4 (pin number 7)
Use method openAll if you need open all pins for write or read:
gpio.openAll('out'); //for write
Now, you can send a signal (0 for low voltage - false, 1 for high voltage - true) by out method:
gpio.out(7, 1); //HV - true
If you need more information about Raspberry Pi's GPIO usage, you can read Cómo usar los pines GPIO de la Raspberry PI (in spanish)