Raspberry Pi / Volumio Next song GPIO Button.
May 2nd, 2014
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)
[/code]
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!
January 5th, 2020 at 9:40 am
Excelent projecte
Jo vull fer un sistema que un pulsador activi / desactivi un arxiu de musica alhora que encenem uns leds
Em pots ajudar?
February 29th, 2020 at 2:38 pm
Greetings! This is my 1st comment here so I just wanted to give a quick shout ouut
and say I truly enjoy readinng yoour articles. Can you recommend any other blogs/websites/forums that
go over thhe same topics? Thank you so much!
February 29th, 2020 at 4:22 pm
Magnificent website. A lot of useful information here. I’m sending it to several buddies
ans additionally sharing in delicious. And certainly, thank you for your sweat!