Another slice of Pi

I mentioned the other day that I’d got myself a new Raspberry Pi computer and promised to say more about it soon, especially the fun I’ve been having with its GPIO port. This post was slightly delayed due to the pressing need to write about other Pi-related stuff at the end of last week, but here it is now.

GPIO (short for General Purpose Input / Output) is the name for pins on various integrated circuits (or chips) that are available to be programmed by the user. Essentially it’s a convenient way to interface your chip with a wide range of hardware. The Raspberry Pi FAQ defines GPIO as “a pin that can be programmed to do stuff.”

The Broadcom BCM2835 chip at the heart of the Raspberry Pi has 8 GPIO pins (as well as several other pins that are accessible by the user for various purposes that I haven’t yet figured out) and a nice, shiny 26-pin (IIRC) connector to make all of the pins accessible. Unfortunately that includes about half a dozen pins that can fry your chips if you connect stuff to them. Also, it’s not terribly convenient to connect wires directly to these pins. For these reasons, I decided to invest in a cheap, simple and potentially extremely useful accessory called a Slice of Pi (NB I have no connection to Ciseco, the company that sells this product, apart from being a satisfied customer). This is described as a “breakout board” and plugs in to the GPIO port on the PI, providing nicely labelled female connectors (i.e. sockets rather than pins) for the pins you can usefully use while hiding the ones that are liable to destroy the processor.

The Slice of Pi comes as a PCB with a bunch of loose connectors that need to be soldered into place. As well as being, presumably, slightly cheaper for the company to produce, this gives you the flexibility to only include the connectors you actually need. Fortunately it is not a particularly difficult soldering task to assemble the board, as my soldering skills are not the greatest.

Armed with my new Slice of Pi and a bunch of electronics stuff that I’ve had for years (since a previous occasion when I got interested in electronics), I have been able to wire up a few simple circuits to test out the GPIO capabilities of my Pi. So far, this has amounted to a few LEDs and a switch (plus a bunch of resistors and some wires) and all I’ve done with them is to make the LEDs flash in pretty patterns (hopping from one pattern to the next at the press of the switch) but I look forward to being able to move on to bigger and better things soon.

Pi Led #3

On the software side, the GPIO port is controlled by a library for your programming language of choice. At least, I assume there are GPIO libraries available for several languages. So far I’ve only looked at Python, which is the Raspberry Pi’s language of choice (and the reason for the “Pi” bit of the name, although they don’t tie you into using just one language) as well as one of my own favourite programming languages (and probably my strongest, to boot).

Having accomplished my first goal of getting the Pi to flash LEDs in pretty patterns, my next task is to figure out some actually useful things to do with the GPIO port.

A tasty slice of Pi

Last year I was quite excited to hear about the new Raspberry Pi, a computer designed to be small and cheap. Its main aim is, apparently, to provide an accessible and stimulating route into computer programming for young people (rather like the ZX Spectrum and other microcomputers of my youth, although I’m not sure if that was one of their design goals or just a side effect of the fact that you had to type in commands just to get a program to load and the easy accessibility of a programming environment if you wanted to take things further) but it is also a quite capable general purpose computer. The thing that most immediately attracted me to the Pi was the presence of a GPIO port, allowing easy access to hardware control.

As with several other items of new technology, including my Android phone and my Kindle, I waited until I had got my hands on one or two Raspberry Pis (or Pies – I’m not sure if there’s an official plural form) belonging to other people before I purchased one of my own. In many ways this wait served me well, as they doubled the amount of onboard RAM fairly late in 2012 and so, by waiting until the cusp of the new year, I ended up with 512MB instead of 256MB. Mine is a Raspberry Pi Model B, which comes with a built-in ethernet adapter and 2 USB ports so is (IMHO) well worth the extra cost against a Model A (about £10 cheaper but with 1 USB port and no ethernet – actually I don’t recall seeing any of those for sale, so I don’t know if they are still doing them).

The Pi comes with composite video and HDMI outputs for graphics. Unfortunately I don’t have a TV at home (to use the composite video signal) and my monitor is VGA-only (for which HDMI adaptors are expensive). Also I didn’t, until last week, have a USB keyboard. This meant that I couldn’t plug my I/O peripherals directly into the Pi and have had, instead, to resort to running it headless and accessing it via an ssh connection from my PC. This is no great problem except that my PC is in my bedroom, my router is in the kitchen and I therefore have to keep running in and out to get to the Pi (or I could trail an extra-long network cable through the house but I’d rather not). I have now procured a USB keyboard and have an HDMI cable with DVI converter on order, so that I’ll be able to take the Pi into work (I have a DVI-capable monitor in my office) and play with it directly during my lunch breaks, but for now I’ll be sticking to headless / ssh use when I’m playing with it at home.

To start with, I decided to run my Pi with the recommended operating system – a customised version of Linux called Raspbian (which, as the name suggests is based on Debian, one of the most established Linux distributions). I’ve been running Linux, on and off, pretty much since I first got my own PC about 12 years ago and it (in the flavour of Linux Mint 11, aka. Katya) is currently my main OS on my home PC, so Raspbian is pleasantly familiar. At some point, I may try out one or more of the other Pi-based Linuxes (or Linuces or whatever – again, I’m unsure about the plural form). If so, I’ll probably wait to get a new SD card first. One of the attractions of the Pi is the fact that all the software resides on an SD card, so you can effectively have a different machine set up just by swapping out to a different card. One of the ways I can foresee playing around with my Pi is to have several different versions of Linux set up on different cards with a nice stable one (probably Raspbian) I can fall back on and others to be more experimental with.

As I mentioned before, the thing that first drew my attention to the Pi was the GPIO port and, indeed, I have already started to play with that. Since this post is getting a bit long, I’ll postpone further details for a bit.