My local hackerspace Sector67 held a 24 hour build fest this weekend. Late last week in preparation for the event a few of us purchased some Raspberry Pi‘s. If you’re not familiar with the Pi, it’s a credit card sized ARM based computer with a USB port, Ethernet port, GPU, HDMI and Composite video out that runs Linux for about $35. You can read more about it at the link above but the “overall real world performance is something like a 300MHZ Pentium 2, only with much, much swankier graphics.”
I bought 2 with the plan to install nodejs on them. I figured it’d be a super cheap way to create a web based controller people could use in other projects. I’m happy to say it only took me about 3 days to make this a reality. However it was pretty much 3 days of frustration that I’d like to keep the rest of you from having to experience so here’s the scoop.
I bought the bare bones Raspberry Pi for $35. When you buy the bare bones card you’re going to need some more hardware to make it run. Here’s a quick list:
1) Class 4 SD card from 4 gigs to 32 gigs in size. The Pi uses this for its boot device.
2) A 5v 700mA micro usb power supply.
3) A powered usb hub.
4) USB Mouse/keyboard.
5) A monitor with HDMI input or an HDMI to DVI converter if your monitor is DVI only.
6) An SD card reader/writer to image the SD card with the linux boot image.
My Pi’s arrived in the middle of the week along with the 2 32g SD cards I ordered off Amazon. I rooted around my junk hardware closet and dug out an extra USB keyboard/mouse and an old Blackberry phone power supply that was 5V/650mA micro USB. The one thing I realized I was missing was an SD card reader/writer. I made a quick search on the internet and found that my local Target claimed to have a $10 cheap-o reader in stock. Of course when I got there they didn’t have it but they did have a $20 Belkin universal media writer as well as a couple of powered USB hubs on closeout for $5 each. So I grabbed them and headed over to Sector67 to get things up and running.
The first order of business was to get the linux images on to my SD cards. I decided to do this from my Windows based laptop so I downloaded the latest Debian image from the Raspberry Pi download page. The actual release I picked up was the September 18th Raspbian “Wheezy” image. After downloading and unzipping the image I was left with an .img file I needed to get onto the SD cards. In order to facilitate this I needed a piece of imaging software called Image Writer for Windows. After downloading and installing this I was able to quickly image both my SD cards with the Raspbian .img file.
Here’s where I ran into my first problem. I have a Dell monitor with HDMI input but I didn’t have it at Sector. I had an HDMI cable with an HDMI to DVI converter but when I plugged it in all I got was a blank screen. I tried it with both Pi’s and both of them did the same thing. Ok fine, the Pi’s also have a composite video output so I tried that next. Same problem. For some reason when I plugged both the composite and HDMI/DVI in at the same time I suddenly got video out through the HDMI/DVI combo. If I unplugged the composite or the HDMI/DVI neither output would work. If I plugged them both back in then the HDMI/DVI would work. At least it allowed me to get working on the thing. Later on I switched to my HDMI monitor with a straight HDMI connection and everything was fine. However, I did experience some weirdness in that occasionally I would get a weird “puttering” sound through the HDMI audio. This happened on both Pi’s so I’m not quite sure what’s up with that.
I was finally up and running with a basic Linux image on my Pi. Now it was time to try and get nodejs up and running. I did some looking around the web and the best article I could find was this one from July. It looked highly promising. Here’s where I ran into my next gotcha. While editing with VI I found that I couldn’t enter a # character on my keyboard. I got around it by cutting and pasting a # from somewhere else in the document but a few minutes later when I needed to use the | character on the command line I knew I was going to have to fix the problem.
The image that is on the Raspberry Pi website was obviously generated by someone in the UK as the keyboard settings are set for a UK keyboard and this is what was causing me grief. To fix this issue you first have to type in the following:
$ sudo dpkg-reconfigure keyboard-configuration
$ sudo invoke-rc.d keyboard-setup start
$ sudo halt
At this point I was getting pretty frustrated with compile times so I cranked that baby up to 1GHz, re-downloaded node and got to work compiling. Unfortunately this ended really quick as for some reason the node compile died almost immediately. I took a look at the file that wouldn’t compile and found that the text file was corrupted. Turns out that my “stability” was not good. I assumed that my power supply was not up to the job, so I cranked my CPU back down to 700 MHz and reformatted again to get rid of my corrupt files.
I continued to get nowhere with building node and spent a lot of time searching for other ways to get it to build. I probably tried 3 different articles that people had posted as well as one binary distribution that immediately died with a segmentation fault. Finally on Saturday morning I came across this gist. This is the one that made it all happen. Down near the bottom is the post from a month ago with the script that worked for them as well as me:
export NODE_VER=0.8.7 cd ~ rm -rf ~/work/node-build/node-$NODE_VER;mkdir -p ~/work/node-build && cd ~/work/node-build rm -rf ~/opt/node-$NODE_VER;mkdir -p ~/opt/node-$NODE_VER curl -O https://github.com/adammw/node/commit/arm-patches-2.patch curl http://nodejs.org/dist/v$NODE_VER/node-v$NODE_VER.tar.gz | tar xz cd node-v$NODE_VER git apply --stat --apply ../arm-patches-2.patch ./configure --shared-openssl --without-snapshot --prefix=~/opt/node-$NODE_VER date;time make CFLAGS+=-O2 CXXFLAGS+=-O2 install;date
If you copy this into a shell script and run it you should get an actual build of node 0.8.7 and npm that works. After the build I was quickly able to install express and have a web site up and running on the Raspberry Pi. I was also able to install the serialport library for nodejs and talk to an Arduino board over the USB connection (a topic for another day).
I was so excited to have node running that I even went ahead and compiled redis for the Pi as well.
I just pulled down the distribution off this link and did a
$ make -j 2
Finally here’s the obligatory screenshot of my Raspberry Pi running the default Express installation on nodejs.