Making some modifications to some nice Python examples found on the Internet (Fuzzy Logic Robots, python-mpd documentation, raspi-hd44780 by Irvick) I was able to make a very basic, but fully working, standalone RPI Web Radio receiver.

Here is the complete wiring sketch:

In the above sketch, pin 1 of the LCD is the leftmost one. The rightmost 2 pins (15 and 16) are for the backlight connections. The LCD works at 5V. A 2 lines x 40 characters display was employed, because the titles and the station-ID are generally long. If a smaller display is being used (e.g. 16/20 characters), some modifications to the LCD program are necessary. Adjust the small 10 kOhm variable resistor to get the best LCD characters contrast.

S1 and S2 are used to move up and down through the channels, S3 and S4 to adjust the volume level. The pull-up resistors are all connected to the 3.3V power source. Idea: the four pushbuttons may be connected to a simple remote control circuit.

Take care not to short out each-other the 5V and the 3.3V outputs coming from the RPI and double-check the wiring before powering-up the RPI.

For simplicity, two independent programs have been made: one starts mpc and handles the four pushbuttons, while the other one handles the LCD (updated every 3 seconds). Both programs run in background.

The name of the playlist used by mpc is embedded into the program.  The playlist is named “mymy” (see below).


MPD/MPC must be already be installed as described in Part 1.

1. download the python programs and change the file permissions:

mkdir /home/pi/rpi_web_radio
cd /home/pi/rpi_web_radio
sudo chmod +x radio*

2. download the sample playlist “mymy.m3u” (stations may be obsolete at the time you’re reading this article, just update the contents as needed) then check/change the file permissions and the owner:

sudo cd /var/lib/mpd/playlists/
sudo wget
sudo chown mpd:audio /var/lib/mpd/playlists/mymy.m3u
sudo chmod 644 /var/lib/mpd/playlists/mymy.m3u

3. download the following programs into /etc/init.d/ then change the files permissions:

sudo wget -O /etc/init.d/radio_btn
sudo wget -O /etc/init.d/radio_lcd
sudo chmod +x /etc/init.d/radio_btn
sudo chmod +x /etc/init.d/radio_lcd

4. make the programs run automatically at boot:

sudo update-rc.d radio_btn defaults
sudo update-rc.d radio_lcd defaults

If needed, the two control programs can be manually stopped/started:

sudo /etc/init.d/radio_btn stop
sudo /etc/init.d/radio_btn start
sudo /etc/init.d/radio_lcd stop
sudo /etc/init.d/radio_lcd start

To stop the automatic program execution at boot:

sudo update-rc.d -f radio_btn remove
sudo update-rc.d -f radio_lcd remove

The Raspberry, wired to the network (ethernet or wifi), should automatically start playing and the LCD should show the song title and the station name at every reboot.


Along with their conventional RF transmitters, nearly all major radio stations now broadcast their programs through the Internet (Streaming Media). Also, many web-radios are exclusively Internet-based.

Being cheap and small, transforming the Raspberry PI into an Internet radio player was really tempting. Adding a wireless adapter, plus a handful of cheap components, the RPI may easily be transformed into a standalone “receiver”.

This first article deals with the installation of some command-line programs: MPD, Music Player Daemon, MPC (Music Daemon control-program) and python-mpd. These programs can easily interact with any user-written programs.

The following setup was tested under a fresh installation of the latest Raspbian distro (do sudo apt-get update and sudo apt-get upgrade before starting).

Download and install the required packages from the repository:

sudo apt-get install mpd mpc python-mpd alsa-utils

Make sure that the sound module is enabled:

sudo cat /etc/modules

snd-bcm2835 must be present in the list. Otherwise add it.

The setup is done, so let’s test the “receiver” and make it play. Execute MPC:

sudo mpc

it should reply:

volume: 80%   repeat: off   random: off   single: off   consume: off

Good, it should work.

MPC holds the list of “stations” on a playlist. It’s time to add the first “radio” to the playlist, so enter:

sudo mpc add

Inside the playlist, each station is identified by a number, starting from 1 and increasing as we enter the radios one after another. Having only one station, make it play entering:

sudo mpc play 1

MPC should reply with:
[playing] #1/1   0:00/0:00 (0%)
volume:100%   repeat: off   random: off   single: off   consume: off

and… if an headphone or the speakers are plugged into the RPI’s audio socket, we should now hear the radio playing.

Deleting an entry from the playlist, the list is shifted backwards (so, if the 4th was deleted, the 5th will become the 4th, the 6th will become the 5th, an so on).

The volume can be adjusted with the following command:

sudo mpc volume (followed by any number from 0 to 100)

and again MPC will reply with some useful informations:


Let’s now add another nice station,  then query the status of MPC:

sudo mpc add
sudo mpc

The reply should be something similar to:
[playing] #2/2   0:00/0:00 (0%)
volume:100%   repeat: off   random: off   single: off   consume: off

Now we can save our playlist entering:

sudo mpc save mylist

The list, named “mylist” in the above example, is saved under /var/lib/mpd/playlists/ and the full-name is mylist.m3u. More than one list can be created and loaded when needed.

If the playlist exists, it must be deleted before saving it, using:

sudo mpc rm mylist

Among the many MPC commands, the most useful ones are:

sudo mpc load mylist
sudo mpc lsplaylists (show the available .m3u playlists)
sudo mpc playlist (show the playlist content)
sudo mpc clear (to empty the playlist)

To stop the player enter:

sudo mpc stop

Here is a very short and simple Python program that gets the Station Name and the Song Title from MPD and prints these informations onto the command-line:

import mpd

client = mpd.MPDClient()
client.connect("localhost", 6600)

cs = client.currentsong()

if 'title' in cs:
   SongTitle = cs['title']
elif 'file' in cs:
   SongTitle = cs['file']

print ('Song Title  : ' + SongTitle)
print ('Station Name: ' + cs['name'])

Download and run the above program:

chmod +x

The program works only when MPD is tuned-in and playing (through mpc play).

Looks quite simple and promising, isn’t it ?