happy birthday raspberry pi

Yesterday marked the second birthday of the Raspberry Pi. It was two years ago on 1 March 2012 (well, actually, 29 February, as 2012 was a leap year) that the Raspberry Pi was officially released (after months of speculation and pre-release ordering). It was an instant hit, selling 100,000 on its first day. Since that inaugural date it’s passed the 2.5 million mark, and continues on at a healthy pace. Mine were purchased a year ago March, but due to my circumstances I didn’t really start to dig in with the R-Pi until around Christmas.

Most of my time has been spent on “loftier” goals, such as building a development environment on the R-Pi using Arch Linux Arm. Arch Linux has turned out to be a good choice for me, better than the others originally presented for the R-Pi. I’ve also installed and gotten used to writing applications in Javascript on the R-Pi using Node.js. Using all that I’ve learned so far I wrote the following little script to flash four LEDs back and forth using the GPIO pins. I would have used two, but it looked a bit silly with just two LEDs going back and forth, so I added two more.

// NOTE: Code written for Raspberry Pi Model B.// NOTE: Pin 13 is GPIO 27//var Gpio = require('../onoff').Gpio,led1 = new Gpio(17, 'out'), // Header pin 11led2 = new Gpio(18, 'out'), // Header pin 12led3 = new Gpio(27, 'out'), // Header pin 13led4 = new Gpio(22, 'out'), // Header pin 15iv1,shifter = 1,multiplier = 2;// LEDs have 50 ms on period. Loop period is 200 ms.//iv1 = setInterval(function() {led1.writeSync(shifter & 1 ? 1 : 0); // 1 = on, 0 = offled2.writeSync(shifter & 2 ? 1 : 0);led3.writeSync(shifter & 4 ? 1 : 0);led4.writeSync(shifter & 8 ? 1 : 0);shifter *= multiplier;if (shifter > 4) multiplier = .5;if (shifter < 2) multiplier = 2;}, 50);// Stop blinking the LEDs and turn them all off after 10 seconds.//setTimeout(function() {clearInterval(iv1); // Stop blinkingled1.writeSync(0);  // Turn LED 1 off.led1.unexport();// Unexport GPIO and free resourcesled2.writeSync(0);  // Turn LED 2 off.led2.unexport();// Unexport GPIO and free resourcesled3.writeSync(0);  // Turn LED 3 off.led3.unexport();// Unexport GPIO and free resourcesled4.writeSync(0);  // Turn LED 4 off.led4.unexport();// Unexport GPIO and free resources}, 10000);

Following is a sample video clip showing the LEDs in action. I apologize in advance for requiring Flash to view this. I uploaded this to Flickr, and I guess Flickr hasn’t gotten the memo yet on HTML5 video.

The key to flashing back and forth is lines 17, 18, and 19. Line 17 shifts a single bit left or right depending on the multiplier, which can either be 2 or 1/2 (.5). Lines 18 and 19 decide when to set the multiplier to either shift right (2) or left (.5). I tried to use the bit operators in Javascript, but found that the code would have been a bit clunkier and longer if I had. I could have also put an ‘else’ clause in front of the second if statement, but decided not to. We’re not dealing with time critical testing here, and I preferred short, simple statements in this example.

If the code looks a bit familiar, it should. I started with the flash_led.js example in the onoff examples directory, and hacked it from there. It took me about 30 minutes of tinkering and hacking to get it to work. I would have done it in half the time except I was switching my attention between this and “Gravity” on the Blu-ray player.

I also decided to use a simpler breadboard as apposed to the larger, more sophisticated Parallax Professional board. I’m using the board for which it was intended, as a Propeller development board, and using I2C to tie the R-Pi to the Propeller, with the Propeller and the R-Pi working together, doing some interesting things for me.

Here’s hoping I don’t get bored with the R-Pi or allow some other major event to stop me from working with it.

Camera Used

I used my Olympus E-M5 with the Panasonic 1.4/25mm sitting on a Gorilla Hybrid. It was a nice compact rig that allowed me to set the camera fairly close to the R-Pi and the LEDs. I was generally pleased with the output (we’re not talking Oscar material here), but I was somewhat annoyed with the very minor shaking I see going on in the video. I thought I had the vaunted five axis stabilization enabled when I hit the video record button. I need to go back and see just how all that is set up.

raspberry pi + arch linux + node.js + express + jade


I’ve been working with Node.js on the Raspberry Pi, particularly with regards to the web application framework Express and the page template engine Jade. My past experiences with web tools like these goes back to the late 1990s with Microsoft’s early IIS and ASP pages, IE 4, msxml 0.8 and Microsoft’s initial Dynamic HTML implemention, through plain old Apache 1.0 with Perl, to Tomcat and JSP pages and Ruby on Rails to Node.js and Express and Jade with a side trip to EJS.

I’ve been following a tutorial titled “Creating a basic site with Node.js and Express” to create an initial application. Interestingly enough, even though the tutorial was written back in April 2011, it was still reasonably up to date. I had one deprecated call in app.js (replacing “app.use(express.bodyParser())” with “app.use(express.json())” and “app.use(express.urlencoded())”) and one error in a Jade template file (replace “!!! 5” with “doctype html” in views/layout.jade). Once those minor fixes were in place I was able to start up my very simple Node web server and have it deliver the sample page (see below) to my various home devices on my internal home network. You see a screen capture on the Nexus 7 2012 running Opera. If I’m going to use Node on my R-Pi, then I’m going to make full use of it. The screen capture above shows the system resources via htop in the upper left window, and the simple Node application with logging running in the upper right window.

As usual everything is behind a firewall.

My reason for digging into this part of Node is to build a web interface into the i2c and onoff Node modules, and thus the Raspberry Pi’s I/O capabilities. My next release of my Arch Linux image will contain all of this (though not necessarily the final web interface into the Raspberry Pi’s I/O), hopefully this weekend. I will only update the graphic image, not the base image.