Sunday, 12 April 2015

Python, MPD and Volumio

I'm building a Raspberry Pi powered vintage radio, by stripping out all the gubbings and add a raspberry pi, IQAudio DAC & Amp.

I'm going to use Volumio to provide the music player and UI, but in order to get the existing buttons on the radio working I need to interact with MPD (Music Player Daemon) which is the server software which makes it all work.

There is a python library called python-mpd2 [code] which provides an api for communicating with MPD, its pretty easy to use and it allows you to do things such as change the volume, play, pause, stop, skip tracks, change playlists, search for music, etc.

Install python-mpd2

I found that I need to install python's "setup tools" when using the volumio image:
wget -O - | sudo python
Once setup tools is installed you can download python-mpd2 and install it:
git clone git://
cd python-mpd2
sudo python install

The python-mpd2 module is pretty easy to use, its effectively a python client for the MPD server. The first steps are to import it, create the MPDClient and connect to the server.
from mpd import MPDClient
client = MPDClient()
#to connect to MPD you need to know the IP address and port
client.connect("localhost", 6600)
Once you are connected you can use the client to issue commands to the MPD server, such as pulling back the current status and the current version.
Some useful other mpd-python2 functions are:
#set the volume between 0 and 100

#play song at certain position

#pause and resume playback

#skip to the next or previous track

#clear current playlist and load a new one
Here is a complete list of mpd-python2 commands.


  1. I am building a similar vintage radio and plan on using almost the exact same configuration as you. I opted to use a hifiberry dac instead of the IAQ. I am just stumped on how to physically interface the pi with the rotary dials on my radio. I would love to have the rotary dials control volume and maybe change playlist when turned. How do you plan on physically interfacing your pi with the buttons on your radio?

    1. I have connected the original power switches and volume switch up using a MCP3008 analogue to digital converter. I have replaced the main tuning dial mechanism (a variable capacitor) with a rotary encoder.

    2. Here is the setup and code for how I got the rotary encoder working.

  2. Hello,
    very interesting project. Would it be possible to get the sourcecode? i'm just new to python programming and would love to make something like this...
    best regards


    1. Do you mean the code for my vintage radio build? If so ... the write up is here