Needy Jelly Babies
Two years ago I took my son along to Maker Faire UK in Newcastle (which is where I grew up). This year the whole family came along.
Whilst I queued with the kids for the ‘laser caper' my wife went along to a talk by Clive from the Raspberry Pi Team. I can’t blame her for wanting to find out about stuff I’m so keen on from an independent (though not impartial) source. She came back very enthused, particularly about Rob Bishop’s singing jelly baby project.
The project looked ideal for a couple of reasons:
- It’s short and simple – something that my son could ostensibly tackle on his own
- Jelly babies – yummy
I set up my son’s Raspberry Pi so that it was working on a newly acquired Edimax EW-7811Un WiFi adaptor in order to minimise clutter (no need for keyboard, screen etc.). I also made sure that his Raspbian was up to date (sudo apt-get update && sudo apt-get upgrade). Once jelly babies, paper clips and jumper wires were sourced from around the house he was almost ready to go. I opened up a PuTTY session to the Pi and left him to it.
Hacking like it’s 1983
The hardware bits were simple – as expected. The software was more troublesome.
I cut my teeth programming on the ZX81 and Dragon32, typing in games from magazines. These would invariably not run due to a multitude of typos causing BASIC syntax errors. As many others found out at the time, learning to debug programs is functionally equivalent to learning to program.
Not a lot has changed (and maybe that’s the point).
It’s possible to cut and paste from Rob’s PDF into Nano, but that doesn’t give you a working python program. All the indentation (which Python relies on) gets stripped out, and characters like ‘ can mysteriously change into .
Sorting out the copy/paste errors was a good refresher on Python loops and conditionals, and highlighted key aspects of the code flow.
Before getting too seriously into hammering the Python into shape I sugested a test that the ‘song’ would play.
I ran ‘mpg321 la.mp3’, but heard nothing. Aha I thought – the Pi is trying to play to HDMI rather than the 3.5mm jack (something I’d seen before with MAME). I ran:
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 1
I ran ‘mpg321 la.mp3’ again, but still heard nothing. I tried ‘aplay /usr/share/sounds/alsa/Front_Center.wav’ – that worked – so the problem was with mp3 playback.
I took a hard look at the la.mp3 file. It’s file size seemed wrong. I downloaded it again – different size, but still wrong. I downloaded it with forced raw:
I now had a file called ‘la.mp3?raw=true’, but at least it was the right size (and hence the right file). Git is an awful place to keep binaries (as I found out when trying to use it for OpenELEC builds).
mv la.mp3?raw=true la.mp3
Still nothing. I conceded defeat and rebooted as suggested by Adafruit guide ‘playing sounds and using buttons with Raspberry Pi‘. It worked when the Pi came back up.
Everything was ready now. This time ‘sudo python SingingJellyBaby.py’ would work.
It didn’t. GPIO.cleanup() was throwing errors (because it didn’t exist in earlier versions of the library).
sudo apt-get install -y python-rpi.gpio
GPIO.cleanup() still throwing errors :(
sudo apt-get install -y python-dev
tar -xvf RPi.GPIO-0.5.2a.tar.gz
sudo python setup.py install
And now, at last, the Jelly Baby sings.
To be fair…
In the course of retracing my steps to write this up it’s looking like the latest Raspbian doesn’t suffer from the GPIO.cleanup() issue. Why an updated/upgraded Raspbian tripped on this will remain a mystery (though I’m starting to suspect that I did apt-get upgrade without an apt-get update).
Until people get much better at putting code into PDF (the Puppet guys seem to have this one covered) kids who cut’n’paste their Python will still have a load of debugging to do.
Github is great for source, not so good for binary objects.
Jelly Babies can be needy – they have dependencies – especially operatic ones.
 I ended up doing my run in 9.45s, which I was told was the fastest of the weekend (as of Sunday morning), though I did just trip the last beam and lost a ‘life’.
 I keep forgetting the config steps for WiFi on the Pi. So here’s what I put into /etc/network/interfaces (as I never be bothered to mess around with wpa-supplicant) – you’ll need to replace MyWiFi with your SSID and Pa55word with your WPA shared key:
iface wlan0 inet dhcp
 The truly lazy can of course:
Filed under: Raspberry Pi | Leave a Comment
Tags: audio, dependency, github, GPIO, jelly baby, mpg321, Raspberry Pi, Raspi, Rob Bishop, RPi, wifi