Talk to your Single Board Computer's gpio pins
This plain JavaScript module is generic and only rely on system's sysfs.
Please consider other (more mature) gpio libraries out there which support better your hardware,
For instance, of you're looking for a reliable way to communicate with the Raspberry Pi using JavaScript, check out the wiring-pi JavaScript library. It provides direct bindings to the fully-featured Wiring Pi C library.
But if you want/need a generic lightweight module, this one can be used as fallback.
Following hardware was reported to work (with some limitations or workarounds)
Get node.js for your SBC, If using Debian or deviates (Raspbian for RPi), you can simply run: sudo apt-get install nodejs
otherwise, install from node or compile it
This library is an npm package, just define "gpio" in your package.json dependencies or
npm install gpioNote: you must be have proper privileges to access the GPIO headers (or run node as root).
…If you plan to set the header voltage externally, use direction in and read value from your program.
var gpio = require("gpio");
var gpio4 = gpio.export(4, {
direction: gpio.DIRECTION.IN,
ready: function() {
}
});// sets pin to high
gpio4.set();// sets pin to low (can also call gpio4.reset())
gpio4.set(0);// Since setting a value happens asynchronously, this method also takes a
// callback argument which will get fired after the value is set
gpio4.set(function() {
console.log(gpio4.value); // should log 1
});
gpio4.set(0, function() {
console.log(gpio4.value); // should log 0
});// unexport program when done
gpio4.unexport();This library uses node's EventEmitter which allows you to watch for value changes and fire a callback.
……Demos on Raspberry Pi:
No open issues yet, or sync has not completed.