I’ve been playing with the very excellent Volumio. Having got it all up and running, with a Hifiberry DAC and an LCD from http://andypi.co.uk/?p=351 it was pretty good. However, Volumio only allows for one playlist and the occasional song I was not in the mood for crept in.
So I wanted a skip to the next song button. Entirely possible with the Pi, and I found a guy who had done it – but his code wasn’t complete. Here are the full instructions:
Connect a switch to two spare gpio pins. I used GPIO 4 to ground. This was useful.
sudo apt-get update
sudo apt-get install python-dev python-pip
sudo pip install –upgrade distribute
sudo pip install ipython
sudo pip install –upgrade RPi.GPIO
Then make a file – mine is called button py
nano button.py
This is the code
[code language=”python”]TEST_MPD_HOST = “localhost”
TEST_MPD_PORT = “6600”
TEST_MPD_PASSWORD = “volumio” # password for Volumio / MPD
# Connect with MPD
client = mpd.MPDClient()
connected = False
while connected == False:
connected = True
try:
client.connect(TEST_MPD_HOST, TEST_MPD_PORT)
except SocketError as e:
connected = False
if connected == False:
print “Couldn’t connect. Retrying”
time.sleep(5)
print(“Connected”)
while True:
if (GPIO.input(buttonPinNext)): # Play the next song in this play list.
print “Next track in play list”
client.next()
time.sleep(1)
Ctrl x to save
Download it here and change the extentio from txt to py
Test the code:
python button.py
Make it run at boot – you need to edit /etc/rc.local (as root since this is the owner).
sudo nano /etc/rc.local
At the bottom, just above exit 0
we’ll add a call to our script.
python /root/python.py
Ctrl x to save
Here is a rubbish picture of the finished article.
Disclaimer. This may not be the worlds best Python. Please let me know if I can improve it!