Thursday, October 4, 2012

My Raspberry Pi Adventure


Last Christmas, my friend +Norman Robinson gave me a BeagleBoard-xM computer to play with. The BeagleBoard is a small, single-board, ARM-based computer. As I started to work with it I was impressed with its relative performance and low-power consumption. However, due to its price (approx. $150), I didn't think it represented a tremendous value. After all, I only paid $199 for my HP Mini netbook at my local computer store and the netbook comes with a case and a keyboard!

I had been hearing a lot about the Raspberry Pi computer which appeared to be very similar to the BeagleBoard but only costs $35. That price, being clearly in impulse-buy territory, appealed to my computer buying impulses.


First Discovery: They're hard to get.



The Raspberry Pi computer is the brainchild of a group of British computer science educators. They set out to solve a problem:
The idea behind a tiny and cheap computer for kids came in 2006, when Eben Upton and his colleagues at the University of Cambridge’s Computer Laboratory, including Rob Mullins, Jack Lang and Alan Mycroft, became concerned about the year-on-year decline in the numbers and skills levels of the A Level students applying to read Computer Science in each academic year. From a situation in the 1990s where most of the kids applying were coming to interview as experienced hobbyist programmers, the landscape in the 2000s was very different; a typical applicant might only have done a little web design. 
Something had changed the way kids were interacting with computers. A number of problems were identified: the colonisation of the ICT curriculum with lessons on using Word and Excel, or writing webpages; the end of the dot-com boom; and the rise of the home PC and games console to replace the Amigas, BBC Micros, Spectrum ZX and Commodore 64 machines that people of an earlier generation learned to program on.
As they had modest objectives and resources, they only planned to produce a few thousand boards, however when they announced the computer and its price, they were flooded with hundreds of thousands of orders. Needless to say, this has led to some supply problems. It was many months before the boards became generally available in the U.S.. Even now, you should expect a long wait to receive a board.

I ordered mine from Allied Electronics and waited about 12 weeks for delivery.

If you're willing to pay more, there are scalpers out there (like this guy on Amazon) who will happily sell you a board albeit at a greatly inflated price.

Second Discovery: You'll need accessories.


For $35 all you get is a bare board, nothing else, not even documentation. That's available on-line. I ordered a case, power supply, and cables from Adafruit Industries which offers an extensive array of Raspberry Pi accessories. You'll also need a 4GB (or larger) SD card to act as its boot disk.

One interesting cable I bought from Adafruit was the USB TTL to Serial Cable. With this cable, you can both power the Raspberry Pi and interact with it via a serial terminal program on your computer. I installed GtkTerm on my Ubuntu box and was able to work with the board while I waited for my back-ordered power supply.

The Raspberry Pi is powered with 5 volts over a USB cable so many mobile phone chargers will work. My Nexus 7 charger worked fine for testing purposes.

Third Discovery: It ain't no slouch.


So how good is a $35 computer? Surprisingly good. In terms of computing horsepower, you can think of the Raspberry Pi as a late 1990s-era desktop PC, but with a better graphics card. The CPU performance is roughly equivalent to a 300 MHz Pentium II.

The board comes equipped with 256 MB of RAM, 2 USB ports, an Ethernet port, HDMI video out, RCA composite video out, and a speaker port. Notice that there is no VGA output. It's really designed to be hooked up to a digital TV or monitor via HDMI. If you have a monitor that supports DVI (as I do), you can use a HDMI-to-DVI cable. I only used a monitor with the board once and it worked fine. Be aware that the HDMI is not bi-directional, meaning that the board cannot detect the capabilities of the monitor it's attached to. You may need to adjust some configuration files to get the video the correct size on your monitor. Another limitation of the Raspberry Pi is that it does not have a real-time clock. It relies on a network connection and Network Time Protocol to keep accurate time.

Fourth Discovery: USB is an issue.


Due to its limited power supply, both my BeagleBoard and Raspberry Pi cannot meet the official specification for USB power output. This means you should not try to power devices via USB. My mouse and keyboard worked okay, but forget about USB powered hard disks and the like. Either use an externally powered device or use a good quality powered USB hub.

Fifth Discovery: There's lots of software.


I set up my Raspberry Pi as a headless media server. I downloaded and installed Raspbian, the version of Debian 7 for the Raspberry Pi. It is officially supported by the Raspberry Pi Foundation and you can download it from their site. To install the image, use dd to write the image file on to the SD card. After it's done, insert the SD card into the Raspberry Pi, attach a monitor and keyboard, plug in the power supply and it boots up. There are a few setup questions (start with setting the correct keyboard layout for your locale) and you're done.

Most every application that's available for Debian (more than 30,000) is also available for the Raspberry Pi. I installed Samba (Windows style file server), Apache (web server), OpenSSH-server (secure shell server), byobu (terminal screen multiplexer), apcupsd (UPS monitor), and the Logitech Media Server.

It is also possible to build an all-text Linux workstation as I describe in my blog series.

I attached a 200 GB 3.5 inch external hard drive and added a line to /etc/fstab to explicitly mount it since Raspian, in its standard form, does not automatically mount drives.  

I wrote a bash shell function for my .bashrc file (on the Raspberry Pi) to provide a quick snapshot of the system's health:


status() {
        { echo -e "\nuptime:"
        uptime
        echo -e "\ndisk:"
        df -h 2> /dev/null
echo -e "\nblock devices:"
blkid
        echo -e "\nmemory:"
        free -m
        echo -e "\nrsync_backup.log:"
        tail /var/log/rsync_backup.log
        echo -e "\nsyslog:"
        tail /var/log/syslog
        } | less
}


The rsync_backup.log file is created by a script of mine that performs nightly backups of the system.

Here is my Raspberry Pi in its final production configuration:


On the left we see the power cable, on the right, USB cables to the APC UPS and external hard drive, and 10 Base-T Ethernet.

Final Discovery: I like it.


The Raspberry Pi, along with my BeagleBoard, have replaced two old desktop machines that acted as servers on my home network. My office is now eerily quiet (and much cooler!).