Pi Day comes round again

As I said this time last year, and will probably continue to say every year I’m still blogging: “Happy Pi Day”.

This is nothing to do with pies of the edible variety or with the Raspberry Pi, although both will probably be featuring in my celebrations.  Rather, it is a celebration of the mathematical constant, π (or “pi”, for those of you who don’t read Greek or maths), which is the ratio of a circle’s diameter to its circumference.  This is  a universal constant for all circles (at least in this universe!) and its value, despite attempts (apparently) by at least one US state to legislate a change to 4, is approximately 3.14159.  That’s as many digits as I can generally remember without having to look it up, and is sufficiently accurate for most purposes (actually, 3.14 is good enough quite often).   Since π is irrational, its exact value cannot be written as a ratio of integers (aka. a fraction) or a finite decimal.

In case you’re wondering why π is celebrated today, it helps to look at the date in either ISO or US standard format.   In the UK, we’d usually write today’s date in figures as “14/3/2013” – that’s the 14th day of the 3rd month in the year 2013AD (or CE if you prefer).   The US version would be “3/14/2013” and the ISO version “2013-03-14”.  Leaving aside the question of which order is most logical (FWIW, IMHO it’s ISO, closely followed by UK, with US a long way behind), if you drop the year then both the US and ISO versions leave you with “3.14” (using a cunningly chosen neutral separator for the two remaining parts of the date), which should make it obvious why Pi Day is today.  If you’re wondering why we bother to celebrate Pi Day at all, you’re probably not a mathematician. 🙂

As alluded to earlier, I make full use of the homophony between “pi” and “pie” as an excuse to celebrate Pi Day with the eating of pies.  I haven’t yet been to the shops today, so I don’t know what sort of pie I’ll be eating, but it will probably be a pork pie for dinner followed by a rhubarb pie or treacle tart, or something like that, for pudding.  Sadly, I won’t have time to bake my own pies this year, so I’ll have to rely on commercial offerings.  I’m not sure how non-English speakers celebrate Pi Day without conveniently homophonic comestibles in their languages.

As well as eating pie, I usually celebrate pi day by listening to songs about pi (of which I only know one — Pi by Kate Bush) and songs about pie (of which there are many).  I have set up a Spotify playlist of about 40 songs mentioning pie in the title, which I’ve listened to on Pi Day for the last several years.  This year, by way of change, I decided to just listen to songs from my own music collection with pie (or pi) in the title.  There are rather fewer of these (just 8 currently on my computer), including Don McLean’s American Pie, Bob Dylan’s Country Pie, 3 versions of Charles Mingus’ jazz classic Goodbye Pork Pie Hat (one by Mingus himself, one by Swedish sax/flute player Magnus Lindgren and a rather tasty guitar version by John Renbourn), and a cover by my own band, the Rice Hooligan Orchestra, of June Christy’s Shoo Fly Pie, as well as the aforementioned Kate Bush song, which mostly seems to be a recitation of the first few hundred digits of π set to music.

Since last year, of course, I have acquired a Raspberry Pi, so if I get time later today I’ll probably do a bit of tinkering with that as part of my celebrations.  My Pi has been slightly neglected of late, as I’ve been concentrating on other things.  Since my last post on the subject, I’ve picked up a LedBorg, a fairly simple expansion board for the Pi which essentially adds a multicoloured LED operated via the GPIO interface.  I have got this up and running and written a couple of simple scripts for it but my next plan is to rewrite my tea timer script to use the LedBorg instead of a lashup of LEDs and resistors on a breadboard).

Incidentally, I gather that an authentic Greek pronunciation of π would be “pee” rather than “pie” but for the sake of celebrating in homophonic style I’m more than happy to go with the anglicised mispronunciation. 🙂

Raspberry Tea

I am writing this on my Raspberry Pi, which is currently hooked up to my monitor at work (it’s now my lunchbreak and I’ve, once again, successfully resisted the temptation to play with my Pi all morning).

As I mentioned the other day, my first attempt at directly hooking up the I/O hardware (rather than going in via SSH or VNC to a headless setup) failed because my HDMI cable and DVI adaptor combo was too big to fit in the space at the back of my monitor.  I suppose the proper geek solution to this problem would have been to dismantle the cable and adaptor and see if I could wire them together directly and make the whole thing short enough to fit.  Instead, I opted for the slightly-less-exciting but also considerably-more-likely-to-work-without-frying-myself-or-my-monitor approach of buying a new cable with a HDMI connector at one end and a DVI connector at the other.  This has now arrived and works fine.

My Pi is beautifully quiet compared to my desktop PC, as it has no fan to make lots of noise (the chip is sufficiently cool-running not to need one) but it’s also noticeably slower (as it has a lot less memory and probably a much slower processor), so I won’t be trying to persuade my boss to let me replace my office computer with a Raspberry Pi, nor ditching my home PC in its favour.  However, it’s certainly an excellent little bit of kit for the price.

I’m still trying to think of actual GPIO based projects that I might want to use in real life, but I’ve now come up with an idea that is at least a step up from just making LEDs flash in pretty patterns.

Several  years ago, I wrote (and then, over the space of a few years, gradually modified) a simple little tea timer script.  As I recall, it started life as a shell script but was soon reworked in Python and has remained in that language to this day.  There are plenty of tea timers in existence but none of the ones I could find did quite what I wanted (which, initially, was mostly to allow me to run it from the command line without a GUI environment to hand, although I later added a GUI option too).

My script works reasonably well and I still use it occasionally, although these days if I want a countdown timer (whether for brewing cups of tea or other purposes) I usually reach either for my mobile phone or my mechanical kitchen timer.  However, one problem I always found with it was that it’s all too easy to miss the alarm bleep and the console message or dialog box that appears when the timer is finished.

It occurred to me the other day (or perhaps it was this morning?) that a nice shiny LED to indicate when the tea is done would be a lot more eyecatching and, with the Raspberry Pi’s GPIO facilities, it wouldn’t be very difficult to set up.  In fact, I’m intending (once I get home to my electronics stuff) to rig up two separate LEDs – one (probably red) to shine while the timer is operating (to show that it’s working) and the other (probably green) to switch on when it finishes.  I may further refine it by making the first LED flash as well if you don’t switch the timer off after a minute or so.

Due to the nature of the hardware and software involved, it’s unlikely to be possible to produce a very accurate timer, but it certainly should work well enough for purposes such as brewing a cup of tea.

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.

The Joys (and Sorrows) of Pi

Yesterday was quite a mixed day for me and my Raspberry Pi.

As I mentioned the other day, I’ve been running my Pi headless and accessing it via ssh since I didn’t have suitable input/output hardware to connect to it directly. I also mentioned that I’d obtained a USB keyboard and ordered an HDMI cable and HDMI/DVI converter to allow me to connect up my Pi directly using my monitor at work (strictly during my lunch break, of course ;)).

Shortly after writing that post, my HDMI cable arrived (the converter had in fact got here already), so it was with some excitement yesterday that I took my Pi and related bits along to work with me. Exercising great self-discipline, I managed to resist the temptation to start playing with my Pi during the morning (despite the fact that my boss was safely away at a meeting down in Cardiff) and got on with my actual work until lunchtime. At that point I lost no time in setting up the equipment only to find that the combined length of the HDMI/DVI converter and the connector at the end of my shiny new HDMI cable was slightly greater than the available space in the recessed area at the back of the monitor where the cables are supposed to plug in. In short, there was no physical way of plugging the cable into the monitor.

Scouting around the rest of the building, I discovered that none of the other available monitors had a DVI or HDMI input that I could use. However, I did manage to find one with a composite video socket, as well as a suitable cable, so I was able to connect the Pi that way and have a bit of a direct-connect session with it. I wasn’t vastly impressed with the video quality (and the monitor in question is in a cold part of the building and not easy to move) so I think I probably won’t take the Pi to work again until the new HDMI/DVI cable I’ve now ordered arrives (this one will have a DVI connector wired in directly at one end so it should fit my monitor with no trouble).

Returning home in the evening, I was able to make some progress on the headless connection front which put an altogether more positive spin on the day’s adventures with my Pi. Up to now, I’ve been using ssh to access it via my local network. This is great for command line stuff (which is where I spend quite a lot of my time in Linux anyway) and I recently discovered how to enable the use of programs with a GUI (essentially, adding the “-X” switch to the ssh command, which lets your local X server handle the graphics on behalf of the remote programs). However, it doesn’t seem to let you run a full graphic desktop environment (it could be that I’m just missing something).

While reading around the subject, I recently came across the concept of Virtual Network Computing (VNC), which seems to allow fuller graphic support for a remote system than ssh (I don’t fully grok the technical details yet). I managed to find a couple of good tutorials on setting up and accessing a VNC server on a Raspberry Pi (I mostly used the Penguin Tutor one and filled in some extra details with the eLinux one).

I haven’t yet had much time to play with it, but so far it seems to be working quite well. I suspect that, until such time as I upgrade to a new monitor with HDMI (or at least DVI) capability at home, I’ll continue to access my headless Pi mostly by ssh and use it mostly from the command line. It will, however, be handy to have the option of using a full graphic interface for it if I want to.

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.