The idea of this project was to build a WLAN internet radio based on a Raspberry Pi (Model B) which is able to play back internet radio streams, podcasts and MP3 files from the SD Card. The radio can be controlled via buttons and a 16x2 LCD display or via a responsive web interface with any browser on a laptop, tablet or mobile phone. The radio also provides an Airplay/DNLA renderer, which makes it possible to directly stream music from a mobile phone, tablet, PC or a media server.
For the software, I reused some of the Perl software I wrote for my NSLU2-based internet radio I built some years ago.
The Raspberry Pi became very famous during the last years, and has become (along with the Arduino) one of the ultimate platforms for DIY projects. The facts:
Power is always a critical topic when dealing with the Raspberry Pi. Most of available cell phone power adapters will not get you enough power to run a Raspberry Pi stably. A power adapter with at least 1200mA or more is strongly recommended. I use a 1200mA adapter - my measurements have shown that the Pi (plus peripherals: WLAN stick, passive 4-port USB hub, sound card and LCD display) consume not more that 700mA, so the adapter can even be used to also power a little amplifier (see below). But this may vary, depending on the devices you are using together with your Pi. If you are unsure, get a power adapter with 2 or 2,5 A.
The Raspberry Pi has an onboard sound card. Unluckily, it doesn't sound very well: Data exchange over USB, access to the SD card,... - all that causes a disturbing chirping sound. Therefore, it's highly recommended to use an external DAC or usb sound card. For example, HiFiBerry offers additional sound boards for the Raspberry Pi that provide high quality sound.
For my project, I used a cheap USB sound card from Speedlink, which I already used for my NSLU radio project. It's sound is not perfect, but okay. A problem though is that the sound card is designed for sound output via headphones. It just hasn't enough power for a speaker adequate for a radio. To solve this, I use a little amplifier module from Kemo that can be run with 4,5 - 12 Volts and consumes max. 500mA (see video to the right). This boosts the volume of the little Speedlink sound card to an acceptable level (max. 3,5 Watts).
I used a 16x2 LCD module from Bernd Walter Computer Technology that was left-over from my NSLU radio project. It is based on the clasic Hitachi HD44780 LCD controller but comes right out of the box with a USB interface. The display should work together with LCD4Linux and LCDProc, but I used a modified version of the Libusb-based software for the display that can be downloaded at the BWCT homepage.
A probably easier and cheaper way is to buy a Hitachi HD44780 LCD and just connect it to the Raspberry Pi's GPIO port
Before diving deeper into this chapter: There is a very easy way to provide the Raspberry Pi with a LCD display, some LEDs and buttons: The company PiFace offers different Raspberry Pi extension boards, exspecially the PiFace Control and display board will likely provide you with everything you need. Because I wanted to learn something about electronics and circuits during this project, I wanted to do it myself "hands-on" (I only used a "Plug & Play" LCD module because I had one left). So unless you like planning circuits and soldering, skip this chapter, buy a PiFace board and get happy with it :).
I use 3 LEDs to indicate which kind of media (radio stream, podcast or MP3) the radio is currently playing. Controlling LEDs via the Pi is actually quiet simple: The GPIO pins can be configured to "output" or "input" mode. If configured for output, the Pin can be set to "high" via software, which gives you 3,3 Volts at the pin. So theoretically, you could just connect the LED with a little series resistor directly to a GPIO pin.
However, this is not the ideal way, as you draw the current to run the LED directly from the GPIO pin. As LEDs don't cosume much power, this will normally not be a big problem, but a "cleaner" way is to use the supply voltage of 5 Volts from the GPIO to run the LED, and a little transistor that will be switched on and off by the voltage change at the GPIO pin (see circuit image). Make sure you have a big resistor between the transistor and the GPIO pin (R1, in my case 27kOhms), otherwise you will have a short-circuit between GPIO pin and ground! You will also need a series resistor for your LED (R2) which size depends on the LEDs you are using (in my case, 560 Ohms).
To control the radio, 4 buttons and a switch (having 3 states) are used. The button is connected to the Raspberry Pi via a Pull Up resistor (R1): If the button (SW) is not pressed, the output (connected to a GPIO pin) has a voltage of 3.3 Volts, setting the GPIO to "high". When the button is pressed, the 3.3 Volts will be connected to ground, and there will be no voltage at the output - the GPIO port will therefore switch to "low".
Note: The Raspberry Pi has internal Pull Up & Pull Down resistors (approximately 50 kOhms) that can be enabled and disabled via Software (except of the I2C ports, GPIO 1 & GPIO 2, they use hardware Pull Up resistors with 1.8 kOhms each which can't be disabled via software). So you don't need the resistor R1 nessecarily, but then you must ensure that the intenal Pull Up resistor is enabled! Otherwise, the Raspberry Pi can be damaged. For more details about the internal Pull Up & Pull Down resistors, take a look at this tutorial.
A problem is that a short circuit can be created by accidently setting the GPIO pin to "output" instead of "input" mode. In this case, the GPIO pin with an electric potential of 3.3 Volts will be directly connected to ground. To avoid this, a second resitor (R2) was inserted before the GPIO pin. Even if the GPIO is accidently set to output, this resistor reduces the current from the GPIO pin, avoiding a short circuit (and a porential damage to the Pi).
When pressing the button, it can happen that due to the mechanical nature of a button the button press doesn't result in one simple state change from High to Low but instead many state changes during the button isn't fully pressed down ("Bouncing"). You can prevent this behaviour either via software or by inserting a small capacitor (C, 10 or 100 nF). This capacitor kind of delays the signal of the button push/release for a few miliseconds.
You can see a complete draft of the board I use below. Note that the GPIO 1 & GPIO 2 inputs (SDA/SDL) have no Pull up resistors (as described above, the Raspberry Pi has internal hardware resistors for those two ports).
There are many Linux distributions for the Raspberry Pi out there, and some of them are specialized on using it as a music player. I tested two of them:
With Volumio, I had some issues when I tried to install additional software from Debian/Raspbian repositories. Although Volumio is also based on Raspbian, there were many dependecy issues, making it very hard for example to get a fully working C compiler.
So finally, I ended up using Pi Musicbox. Basically, it has the same features as Volumio (Web interface, Dnla/Airplay support,...), but unlike Volumio, installing additional debian packages is very easy. A disadvantage is that mopidy takes a lot of resources (about 50-70 percent CPU load on the Pi)
For my NSLU2-based internet radio, I wrote some software in Perl that was used to control the music player daemon (MPD) by using an old laptop mouse and to display the current MPD state on the USB LCD display. As Mopidy, the music server of Pi Musicbox, also supports the MPD protocol, I was able to re-use most of the code from the NSLU project.
You can download my software below, if you want to get a first impression of how to get the whole thing running, but be warned: The software is not developed for robustness, extendibility or fault tolerance. A solid knowledge of Perl is recommended if you want to use parts of it.
You may need some more stuff to get it running which I just forgot.
The software consists of the following parts (most of them are adaptions of the modules I used for my NSLU2-based internet radio).