In the March 2012 issue of Nuts & Volts, I wrote an article entitled "Build Your Own Wi-Fi Internet Radio" about how to build an Internet radio using a repurposed wireless router. While this project worked fine (and still does), it had limitations driven mainly by the small amount of RAM available on the router. After publication of that article, I continued to evolve the design so that it could also play MP3 files stored on a Flash/thumb drive, as well as function as an Internet radio player.
I liked the idea of having the music I was currently interested in on a Flash drive and being able to change it easily. Also, since the capacity of Flash drives was going up and the prices were going down, I could have a fairly large number of songs available at one time. Then, to put frosting on the proverbial cake, I could control the Internet radio/music file player with a new iPhone/iPod Touch app I was developing called MpdClient.
As time passed, I became frustrated with the fact I had to convert all of the songs I wanted to play on my Internet radio/music file player to MP3s to play them. So, I started looking for a better solution that would allow me to play many different types of music files. When the Raspberry Pi came on the scene, I figured out how to run a full featured version of MPD which solved all my problems. Now, while I’m sitting in my favorite chair, I can listen to Internet radio stations or play artists, albums, or individual songs from a Flash drive plugged into my Raspberry Pi.
In this article, I will show you step by step how to turn your Raspberry Pi into a remote-controllable Internet radio/music file player.
With the high level of system integration on the Raspberry Pi (RPi), you can make an Internet radio/music file player with fewer parts than what would be required using a repurposed wireless router. Figure 1 shows a block diagram of the proposed system; Table 1 gives some specifics as to the components required. For our purposes here, I will assume your RPi will be connected to an existing audio system (through an appropriate stereo interconnect cable) or used with headphones, so we won't worry about discussing amplifiers or speakers.
I will show you how to connect the RPi to your local wireless network using an inexpensive (less than $6) USB Wi-Fi adapter. However, you could run an Ethernet cable from your RPi to your router and skip the Wi-Fi stuff altogether.
|Raspberry Pi Model B
with power supply
|SD Memory Card
4 GB or larger
Bigger = More Songs
I used an 8 GB device.
|Mini 150 Mbps USB Wi-Fi Wireless N LAN Network Adapter 802.11n/g/b||eBay|
|Audio Output Cable
3.5 mm stereo cable to whatever input(s) your amplifier requires
|eBay, BestBuy, Amazon|
TABLE 1. Required Hardware.
The two USB ports on the RPi Model B fit our needs exactly with one port for the USB adapter and the other for a Flash drive containing music. The Model A RPi would not work for this application because it only has a single USB port (unless you want to incorporate a USB hub into your system). In any case, the increased amount of RAM (512 Mbytes) on the Model B probably makes the MPD server run better. The hardware connections to/from the RPi are as follows:
When I first began using the RPi for Internet radio, it had a real problem with loud pops when changing stations. So loud, in fact, as to almost make this arrangement unusable. Recently, however, I reloaded my RPi with the 02-09-2013 version of the Raspbian operating system (available from raspberrypi.org); this problem seems to have been fixed.
If you have an older version of the operating system software on your RPi, I strongly suggest reloading it with this new version. You can follow the directions in my March 2013 article, "Raspberry Pi, Anyone?" All of the initial configuration described in that article is still appropriate and should be done before proceeding.
Assuming we are starting with a newly loaded RPi image, we will first get the Wi-Fi working, then update the OS software with all the newest packages. Next, we will update the RPi firmware and install a series of packages required to run MPD. Finally, we will configure MPD for our purposes.
To get started, insert the SD memory card with the operating system into the RPi and make all of the connections listed in the hardware section above. Once power is applied, your RPi should boot and take you into raspi-config automatically if you haven't done your initial configuration already, or to the command prompt if you have. At this time, please log in with the username of pi and the password of raspberry.
Now, it’s time to find out if our Internet radio/music file player is working. For this test, make sure there are music files on the Flash drive which is plugged into the USB hub. Then, plug some headphones into the 3.5 mm jack on the RPi. Type the following command in a shell window: mpc add http://220.127.116.11:8088. Then, type mpc play. If all is well, you should hear the Beatles Internet radio station.
Next, type mpc clear to stop the server from playing the Internet radio station. Then, type mpc update to force the MPD server to build a database of the songs on the Flash drive. Type mpc listall and you should see all the songs listed that are on the Flash drive.
Then, type mpc add followed by one of the file names you saw with the listall command. Finally, type mpc play and you should hear the song you just added.
If these tests are successful, you are ready to go. You can power-down your RPi and remove the USB keyboard, mouse, and the USB hub. Remember to plug your USB Flash drive containing your songs back into the RPi and connect the audio cable to your stereo system.
To control your MPD server remotely, you can use my iPhone/iPod Touch app (MpdClient) or any other MPD client application you have available.
The MPD server used in conjunction with the RPi can play many different audio file formats. If you would like a complete list of supported files, type mpd --version at a command line prompt. This means you can put a variety of audio file types on your Flash drive, and MPD should have no trouble indexing and playing them all.
MPD does not require any kind of directory structure for music file storage like some other music library programs do (like iTunes). All files can be placed in the root directory of your Flash drive and MPD will sort things out. This is possible because MPD extracts song information from metadata stored in the music files themselves.
When MPD is commanded to do an update, it extracts information from the song files and stores it in its private database. This allows for some very powerful searching and sorting capabilities. Using the MPC client we installed on the RPi for testing, we can list all the available songs by typing mpc listall. Type mpc list artist to see a list of all the artists with songs on the Flash drive. Type mpc list album to see the albums the songs on the Flash drive are associated with. Finally, type mpc list genre to see the genres covered by the songs on the Flash drive.
While these capabilities might not seem all that powerful, consider the following example. Say you execute mpc list genre and get the following list retuned:
Say you only feel like listening to World music. You can do so using the following series of commands:
Of course, I only used genre here as an example, but you could use these same techniques to select songs from a specific album or to play back all songs by a specific artist. Pretty powerful stuff, really.
Having a remote-controllable Internet radio/music file player is very convenient. Building one yourself inexpensively makes it all that much sweeter. NV
|Feature||Model A||Model B|
|Suggested Retail Price||$25.00||$35.00|
|CPU||700 MHz ARM11 with hardware floating point|
|GPU||Capable of 1080p video|
|Memory||256 MB shared with GPU||512 MB shared with GPU|
|Video Outputs||HDMI and composite video|
|Audio Outputs||Stereo 3.5 mm jack + HDMI|
|Onboard Storage||SD memory card up to 128 GB|
|Connectivity||3.3” x 2.1”|
|Size||3.3” x 2.1”|
|Power Requirement||300 mA – 1.5W||700 mA – 3.5W|
|Official OS||Raspbian version of Linux|
TABLE 2. Raspberry Pi Specs.