Jan 2, 2015

GPIO with Node.js in Pidora

So you have node.js running on a raspberry pi (if not see earlier post), I guess next you want to do some physical computing, and get some LEDs blinking.

In order to do physical computing, you need a library to access GPIO. Luckily, there is no shortage of   libraries for GPIO on npm. Without spending too much time, I have tried a few of them and for no particular reason, I have chosen to use wiring-pi.  wiring-pi is actually bindings to the WiringPi , a well known C library for GPIO.

Pidora actually includes WiringPi so you can actually start using it right away. It does come with a command line utility called gpio. However, the wiring-pi npm package does check out and compile its own copy of the library so if you do not already have it installed on your raspberry pi, do not worry.

Because wiring-pi needs git to retrieve WiringPi,  you need git to be available on your raspberry pi. First install it using

yum install git

Now you are ready to install wiring-pi

npm install wiring-pi

If you have followed my earlier post for installing node.js, you probably have a second node installation that came with pidora. In some cases, gyp conflicts with this obsolete one and installation of the wiring-pi may fail. To fix remove gyp and try to install wiring-pi again.

yum remove gyp
npm install wiring-pi

Since blinking LEDs were mentioned, here is a sample code that I have used, which is the example code from wiring-pi Github repository with a small change.

Read more →