Configuring a Raspberry Pi to Talk to Delcom USB With Node.js

Took a little digging, but I have Node.js 0.10.24 and Node-Hid successfully installed and talking to my Delcom USB indicator.  I wanted to take a minute to document the steps I took.  Before following the steps in this article, make sure you have your Raspberry Pi hooked up to the network.

Getting the OS Ready

Start by updating all your packages:

sudo apt-get update
sudo apt-get dist-upgrade

You will need a couple of additional packages required by node-hid, a node library used to communicate with USB HID devices like the Delcom USB Indicator:

sudo apt-get install libudev-dev libusb-1.0-0-dev

Node.js Install

As least as I write this you cannot get Node.js 0.10.x using apt-get. Instead, you have to install it yourself. Here’s the steps I used for node 0.10.24:

sudo mkdir /opt/node
wget http://nodejs.org/dist/v0.10.24/node-v0.10.24-linux-arm-pi.tar.gz
tar xvzf node-v0.10.24-linux-arm-pi.tar.gz
sudo cp -r node-v0.10.24-linux-arm-pi/* /opt/node

You’ll also have to put node into your path and set NODE_JS_HOME by editing your profile. Open up the profile:

sudo nano /etc/profile

Put the following right before you see “export PATH”:

NODE_JS_HOME="/opt/node"
PATH="$PATH:$NODE_JS_HOME/bin"

Once you reboot, you can verify the node installation by issuing the following command:

node -v

It should print out v0.10.24 on your console.

Node-Hid and Test Project

Now it’s time to create a little node project to test things out. This example will set things up in a directory called ~/nodetest:

mkdir ~/nodetest
cd ~/nodetest
npm install node-hid

You can then use nano to create a js file to execute with node:

nano test.js

Here’s the code:

var hid = require('node-hid');

var devices = hid.devices();

console.log('Devices:')
console.log(devices);

Once you plug in the Delcom device, you can run the app to find it as follows:

node test.js

You should see output like this:

[ { vendorId: 4037,
    productId: 45184,
    path: '0001:0005:00',
    release: 32,
    interface: 0 } ]

If you have multiple USB HID devices attached, they will appear in the list as well. The one with the vendorId given above is the Delcom device.

One More Thing

I prefer to write code on my Mac using Webstorm.  I get access to my Raspberry Pi console using ssh and transfer files with help from the netatalk AFP client installed as follows:

sudo apt-get install netatalk

Rolled Up My Sleeves and Got Raspberry Pi Booting

So it appears that my mistake was paying a little extra for the kit.  I reformatted the SD card, downloaded the new out of the box software (NOOBS), copied it onto the SD card, powered up the Pi and about 30 minutes later it was booting just fine into Raspbian Linux.  I’ve got to pick up a supported USB WiFi device today so I can get it onto the network.  I can then start testing some code.  Fun!

My First Bite of Raspberry Pi Not So Tasty

Got home late last night, ate dinner and sat down to boot up my new Raspberry Pi. I bought it as part of a kit that included a power supply, a case and an 8GB SD card with Raspberry Pi New Out of Box Software (NOOBS) installed. Plugged it in and booted to a kernel panic that indicates a problem with the boot device. Not exactly unexpected, but certainly disappointing. Tonight I’ll reformat the card and burn the NOOBS image onto it so I can try again.  Wish me luck!

I Hope I Like Raspberry Pi

Recently, we spun up a new team at Blinds.com to work on a critical add-on called Blinds Tracker for both our production web platform and our soon-to-be-released Autobahn platform.  In addition to being the Product Owner I am also handling DevOps tasks.  One of the fun things I did for the Autobahn team was to put up a physical build light from Delcom that glows green when all is well, blinks blue when a build is underway and flashes red when the build is broken.  I built the necessary utility in .NET and so the light has to be plugged into a Windows laptop that sits off in a corner polling TeamCity from time to time.

Once I had the new project building on TeamCity I decided I wanted a build light for it too.  Besides being a stop on the company tour, it provides a nice visual indication of the project’s health for me, the other team members and stakeholders that can see it from across our open floor plan office.  It’s a different team so I didn’t want to share the Autobahn build light; When it turns red, it should be because Autobahn is broken.  The teams don’t sit in the same area so I can’t really plug a second light into the existing laptop either.

Sounds simple right?  All I have to do is purchase a Delcom visual indicator, grab an old Windows laptop, install my utility and hook it up.  Unfortunately, we don’t have any unused laptops around so I’d have to requisition one.  I jokingly discussed it with one of the developers on the team and he said, “well, you’ve been working with Node.js.  Why don’t you just get it up on a Raspberry Pi.”

So in typical geek fashion I set out to save a few hundred bucks by spending some indeterminate hours of my personal time putting together a Node.js build light application for Raspberry Pi.  I’m lazy so I ordered the Raspberry Pi B (512MB Ram, 2 USB Ports, HDMI and Ethernet), a USB Wifi dongle, a micro USB power supply, an 8gb SD card and a clear case from Amazon.  I also ordered a tri-color USB visual indicator from Delcom.  It will all arrive at the house early next week.  In the meanwhile, I’m going to start building a Node.js website to configure settings and a TeamCity poller that will eventually drive the light.  I think I can get it setup to work on any platform that supports HID so it will likely work on various flavors of Linux, Mac and PC in addition to the Raspbian Linux distribution for Raspberry Pi.  It will be an open source project and I’ll put the source up on Github.  Should be fun.