Raspberry Pi Piface Addon
Interface to the Raspberry Pi Piface board using Node.js. This addon shouldn't require any sudo or root privileges to run, as long as your user is in the "spi" group on your Pi (handled by the spidev-setup script).
Assuming a fresh Raspbian install, there are three steps to getting a project off the ground with piface-node.
It's not quite as easy to install Node.js on a Raspberry Pi as it is on other platforms, so you might need to dig around to find the newest available version for the Pi's architecture. At the time I write this, the latest available packaged build for Raspberry Pi is v0.10.21.
$ wget$ tar -zxvf node-v0.10.21-linux-arm-pi.tar.gz$ sudo mkdir /opt/node$ sudo cp -r node-v0.10.21-linux-arm-pi/* /opt/node
At this point, you probably don't need the node distribution files after installation, as the important stuff got copied into /opt/node. To free up disk space, I like to remove both the tarfile and the extracted files, but that's entirely your choice.
Add the Node.js path to your default profile. Use nano instead of vi if you like, but vi is old-school and awesome. If you want to impress your friends, learn how to use vi ;)
$ sudo vi /etc/profile
Add the following lines to the configuration file before the ‘export’ command.
Log out and back in again for the /etc/profile changes to take effect.
If this is the first time you've plugged in your Piface board, you'll need to update the modprobe configuration so that it loads the SPI driver. This will enable the driver on reboot.
$ sudo nano /etc/modprobe.d/raspi-blacklist.conf
Insert a hash (#) at the beginning of the line containing spi-bcm2708, so it reads:
...And reboot to make it take effect.
First, you'll need the C libraries, available here. Follow the "C" library installation, naturally.
The TL;DR version:
$ sudo apt-get update$ sudo apt-get install automake libtool git$ git clone$ cd piface/c$ ./autogen.sh && ./configure && make && sudo make install$ sudo ldconfig$ cd ../scripts$ sudo ./spidev-setup
$ mkdir ~/my_project$ cd ~/my_project$ npm install piface-node
I've intended this to be used with the full awesome power of Node's EventEmitter. You can easily wire up the physical I/O on the Piface with pretty much anything.
Here's a basic example of the usage, in lieu of actual documentation. There are also a few examples in the examples folder.
var pfio = ;pfio;pfio; // (pin, state)var foo = pfio; // (pin; returns state)pfio;
var pfio = ;pfio;var foo = pfio; // bit-mappedpfio; // that's binary 11111111, so it'll turn all outputs on.pfio;
Everything in the example application is modular and decoupled: most of the components don't even know that the other ones exist. They only communicate through the EventBus. All that example.js does is start up those modules. The example application watches for changes on the input pins, and echoes them to the output pins. Try it out by pressing the tactile switches.
$ cd node_modules/piface-node/examples$ node example.js