rpgpio v0.0.7
#rpgpio A very simple library to program the raspberry pi gpio
IN DEVELOPMENT, USE AT YOUR OWN RISK, NO PIN VALIDATION
##Prequisites
- nodejs and npm
##Install npm i rpgpio
##Examples https://github.com/btinoco/raspberry-pi
##API THIS API IS IN DEVELOPMENT
To instantiate rpgpio
var gpio = require('rpgpio');
The first thing you want to do before writing or reading a pin is to set it up.
gpio.setup(pin_number, direction (gpio.IN or gpio.OUT), callback(error, data));
To write to a pin, you must set it up first (see example above) and then write to the pin
gpio.write(pin_number, value (1-on or 2-off), callback(error, data));
To read a pin, you must set it up first (see example above) and then read the pin
gpio.read(pin_number, callback(error, data));
To export a pin
gpio.export(pin_number, callback(error, data));
To unexport a pin
gpio.unexport(pin_number, callback(error, data))
To check if a pin has been exported
gpio.exported(pin_number, callback(error, data));
To get the direction of the pin
gpio.direction.get(pin_number, callback(error, data));
To set the direction of the pin
gpio.direction.set(pin_number, callback(error, data));
To get the list of exported (in and out) pins
gpio.list();
##Examples
Setting up and writing to a pin. When writing you can send a 1 for on and a 0 for off
var gpio = require('rpgpio'); var pin = 12; gpio.setup(pin, gpio.OUT, function(error, data){; if(error) return console.error(error); gpio.write(pin, 1, function(error, data){ console.log(error || data); }); });
Setting up and reading a pin
var gpio = require('rpgpio'); var pin = 12; gpio.setup(pin, gpio.IN, function(error, data){; if(error) return console.error(error); gpio.read(pin, function(error, data){ console.log(error || data); }); });