AirPlay Radio
with Raspberry Pi and WiFi
Posted by
Before I started working for Pelagicore I won two Raspberry Pi's (short RP) which they sponsored. One because I was one of the first people on the foss-gbg mailinglist which they started. It is for people from Gothenburg and surroundings who would like to join others and talk about open source stuff in Gothenburg. And another which I won because I was on a hackaton for embedded systems they hosted. I also already had one more from before which I wanted to use as my entertainment system in the living room but this never really worked, I described why in a earlier blogpost.
Anyway, I had 3 RP's and didn't know what to do with them. Then a colleague showed me a YouTube video where someone made a remote controllable entertainment system built in to the bath room ceiling with help of a RP, a amplifier and a couple of loudspeakers.
I often listen to podcasts or german radio on my computer and have often the problem that when I go out of the kitchen to the bath room or the bedroom. I was thinking about buying a couple of those AirPlay speakers, but I found all of them really expensive for what they did and I never got around researching if there are some I would like.
But that video gave me a great idea: Why not use one of my RP's, put it into an old radio and stream audio from my iMac or iPhone to that mobile device. I could take this then with me to both the bathroom and the bedroom, and even outside if I wanted.
I know I could learn everything about electronics and just use the radios transformer to get rechargeable batteries charged and the 5V which the RP needs. I sure even could find out how to hack in between the built in tuner and amplifier to use both together with the built in speaker for the audio.
But I am a lazy person, I don't have much free time and I have the money to buy other parts which make it easier for me to get the project done. You know, refining a already working project is so much easier then getting it perfect from the start.
Hardware
So I bought a big rechargeable battery with a USB input for charging and output for the RP.
At home I already had one of those really small USB chargers. I removed the plastic shell and soldered it to the power input of the the old radio. That way I can load the battery without removing it, just by plugging in the radio into a normal 230 V power outlet.
I bought a really old radio from a second hand shop. I got it for 2,50 € and I removed almost everything inside it to have space for the RP and the speakers. I put the battery and the USB charger where normally the four "D" batteries went.
I also bought a USB WiFi stick and attached it to the RP because, obviously, in some way I need to get the audio stream from my iPhone/iMac on to this radio.
And lastly I bought a couple of cheap computer speakers powered via USB which I connected to the second USB port of the RP and put inside of the old radio shell.
All in all it was quite expensive:
Name | Price |
---|---|
97 € | |
battery | 20 € |
USB WiFi | 13 € |
Raspberry Pi | 33 € |
case | 10 € |
speakers | 10 € |
old radio | 3 € |
USB charger | 3 € |
SD card | 5 € |
97 € which is kind of the starting price for one of those off the shelf AirPlay loudspeakers. But I am confident that the next one will be much cheaper, because I will have learned more about electronics so I will be able to reuse the old radios interna instead of buying every part separately. But to be honest, most of the small stuff I already had lying around at home and haven't been using them anyway.
Software
I used ArchLinux because it doesn't have stuff installed and started I don't need anyway, so it will not use power unnecessarily. And frankly I only had a 2 GB SD card at hand, Raspbian needs a 4 GB one.
I installed a WiFi driver, Alsa, and at first the perl version of ShairPort which had really bad audio performance. After a bit of research I found out that the original repo of ShairPort moved on and has rewritten everything in C instead. I compiled it and oh wonder all the audio problems are gone! Funny side note, every other website writing about the perl version of ShairPort tried, and succeed, to convince people that the RP's audio output is really bad and that you need to buy a USB sound card to get it working.
Luckily ArchLinux already uses systemd which I know from work, so I wrote a service file to autostart ShairPort on boot, configuread and added autostart of wifi, alsa, etc. and it works flawlessly. I'm very impressed, it shows up together with my AirPort Express on my iMac and iPhone as a normal AirPlay device and behaves exactly like the AirPort Express.
Future
There is still some weird stuff going on sometimes which I want to adress.
- If you start loading the battery the RP always reboots and sometimes runs, but sometimes doesn't start.
- There is no way of turn up or down the volume on the radio, I only can do it on the iMac or iPhone.
- You can't turn the RP off ore reboot it without removing the battery.
- To see the battery status you have to open the battery compartment, only there are 4 LEDs which are showing it
- There is no way to see from the outside if the RP is on or off
- It is complicated to log in to a new WiFi, you basically have to be logged in into one which is already known and via SSH change it so you can put in the password, etc.
And one could even use the other hardware buttons to do more cool stuff, for example to have some software installed which runs a standalone internet radio, without the need of streaming from the iPhone or iMac, and to change the channels with the buttons. Or even use the potentiometer on the top right to search for new channels.
There is a on/off button on the top which I would like to use to turn the RP on or off and reboot it, which I think will be the first refinement of this project.
[update:] Discussion on HackerNews
2 Replies
@jeena @Raspberry_Pi shove a pi-DAC in there - it'll sound even better.
@jeena Love the choice of donor radio. Keep it up.
1 Mention
I put a Raspberry Pi into a radio from the 80's to get a portable AirPlay device | Hacker News
88 Likes
64 Reposts