Projects‎ > ‎

Raspberry Pi radio

Raspberry Pi Radio
I have been messing around with the nifty and very cheap one-chip computer the Raspberry Pi for a year or so but was looking for a project I could get to grips with.
The answer was a broken Bush radio that I had been meaning to try and fix for a couple of years. I followed the brilliant instructions from Bob Rathbone - which really are flawless. They also tell you enough to get you going, but don't spoon-feed you - in other words you need to understand something about what you are trying to do rather than just joining up A to B.Here is the end result (right). The sound quality is similar to the original FM radio - definitely middle-fi, but we have a very usable radio which is being put to use in the kitchen.Bob Rathbone's site provides a comprehensive components list, including the LCD display - I used a cheap, non-backlit  HD44780 again from Maplin. There is also some software and installation instructions to get you going.
I advise getting the software working with a Pi just using headphones and a monitor/keyboard, just so you know that side of things is operational, before moving on to do some wiring.Here are some general notes about my project which might help you with your radio.


The  model B raspberry Pi will work as an IP radio through headphones a TV (via the HDMI interface) or to PC-style speakers through the audio-out socket. Add a USB wireless dongle and you have a 'wireless' to use the old-style lingo. To make something more like a standalone unit you will need a power supply, an amplifier (with possibly another power supply) and a speaker or speakers along with some sort of display and some switches.For the power I used a taken-to-pieces USB power supply to power the Pi, a transformer and Maplin K18231A power supply kit linked to a 15V mains transformer. Of course this means you will have to do some mains wiring - if you are unhappy with this you can buy complete power supplies, but I was keen to get my Bush radio powered just through the figure-of-eight mains socket on the back. 
I had hoped to use the transformer already in the radio - but it was broken (and why the radio wasn't working). I did use the existing speaker - a 8W 4 Ohm one which matched up well with the amplifier kit I used - a Maplin K4001 7W amplifierMake sure you use screened audio cable between the Pi and the amplifier. I was working in mono so I just wired up one channel from a stereo jack plug, plugged into the Pi. I amended the MPD (music player daemon) configuration to make the output mono by changing the configuration file.
Other extras I needed were a 10k preset potentiometer to set the voltage for the contrast on the LCD display (pin 3). Without this the display was too dark in my setup. If you can work out the other wiring, that should be a fairly simple task for you. Similarly I used a 47k linear pot to adjust the input to the amplifier until the sound quality was decent. There are instructions for this in the Maplin amplifier kit.As suggested by Bob, I used  a Slice of Pi  to do the necessary wiring of the LCD and switches. It is a really tight fit and this is going to be the bit of the project that will take most time and is most likely to cause faults. If I was making the project again, I might use a larger circuit board for the wiring.


The Bob Rathbone installation will get you going. Then, depending on your Python skills, you can make a few amendments to personalise your radio. I found that installing Telnet (sudo apt-get install telnetd) was the easiest way to interface with the radio. Once I'd configured the USB wireless dongle, I stopped using the ethernet socket, having configured my wireless router to give the unit a fixed IP address. As I said above, it's easiest to get all this working before you start construction.


Components ready to start
I haven't made many electronics projects, but I'd say the key thins are to be methodical, plan everything, and try everything before you drill holes or solder anything. You really need to check every soldered joint carefully with a meter. There is plenty of soldering advice out there on the Internet. And you will get better with practice.The first picture is of me ready to start.
The second is of the first stage of construction with the transformer, USB power supply and a few switches mounted. The transformer is on the reverse side of the picture in what used to be the 9v battery space.The live wiring is insulated later on!
Cutting a slot for the LCD
Cutting the slot for the LCD display was one of the more time-consuming parts of the construction. It was one of the things that had to be neat for the finished radio to look half decent. I measured and marked the hole carefully and drew a cross shape through the corners. I then drilled a small hole in each corner and a larger one in the middle (big enough for a fretsaw blade. 
Next stage was to use a fretsaw to cut from the centre to each corner - so far pretty easy. The next part requires super-care. Use a steel ruler and a knife or scalpel (I used a 'Stanley' knife) to cut repeatedly along each side of the front side of the cutout. If you go from the holes inwards you are less likely to overcut. Sticky taping the ruler to the radio held stops slips. 
When the cut is about 1/3 of the way through, you can snap off the triangular sections with a neat finish. Do this for each of the four triangles and make any final trims with a flat-bladed wood file.
I am not the neatest craftsperson in the world, but I am pretty proud of the finished result - but it did take time and care.
Inside view
There was far less space in the case than I expected when trying to fit it all in - that's why you must do a trial assembly on everything. The bulk of the internal wiring is for the LCD, with a few paired wires to the switches. I used different colour wires to remind me what was what. 
The power supply for the amplifier is mounted on the right, above the battery box holding the transformer. The USB power supply, for the Pi, and the audio amplifier are mounted on the bottom of the case. The Pi with the Slice of Pi on top, is in the centre-left with the Edimax wireless dongle's antenna clearly visible (it was just what I had not being used - smaller units are available). You can see the extra potentiomenters - for the LCD (glued onto the wheel top left) and the audio level (just above the amplifier and mounted through the back of the case.)
I ended up gluing all the original switches and dials in place as there was nothing to mount them too with the original circuit-board removed. A more imaginative build could have included  the original switches and dials into the design.


Bob Rathbone includes some 'playlist' files for the radio. And there are stacks of Internet stations out there. The BBC has, however, its own peculiar way of doing things. The BBC playlists are 'tokenised' (as far as I understand) and you need to get to the real, underlying playlist address. You need a script to do this and to build it in to your start up routines for the radio. This is easier than it might sound - just follow the instructions for getting the radio to load when the power comes on. If you don't know much about scripts and executables in Unix - it is a good chance to learn!
Here is my script, gleaned from various sources on the Internet:

set -e

declare -A radios
radios["BBC Radio 1"]=""
radios["BBC Radio 1Xtra"]=""
radios["BBC Radio 2"]=""
radios["BBC Radio 3"]=""
radios["BBC Radio 4"]=""
radios["BBC Radio 4LW"]=""
radios["BBC Radio 4 Extra"]=""
radios["BBC Radio 5 Live"]=""
radios["BBC Radio 5 Live Sports Extra"]=""
radios["BBC Radio 6 Music"]=""
radios["BBC Radio Asian Network"]=""
radios["BBC Radio London"]=""
radios["BBC Radio Derby"]=""

for k in "${!radios[@]}"
rm -f "$filepath"
echo "#EXTM3U" >> "$filepath"
echo "#EXTINF:-1, BBC - $k" >> "$filepath"
curl -s $pls | grep File1 | sed 's/File1=\(.*\)/\1/' >> "$filepath"