Select Playlist via hardwired push button

Hi,

I like to select a defined playlist via a pushbutton. Such that these push buttons act as a 1 button selection.

I am new to python and I struggle to find a good example that explains how to make the connection between Volumio SW stack and the GPIO pins.

I saw a lot of examples for the volume control via the GPIO, but for playlist selection I did not find until now.

Can you point in the good direction?

Many thanks,

Olaf

you can use parts of the code in the GPIO volume control topic, but you would need an to use an other command to select the playlist instead of increase / decrease volume. “mpc add” should do the trick

Thanks for the hint. In the end, understanding the “mpc”, all became clear. Here is the code, which works excellent. An Arduino sends via RX/TX the command. I used a straight forward 1 and 2 over the serial line to select the playlist.

regards,
Olaf

#!/usr/bin/env python

import subprocess
import time
import serial

ser = serial.Serial('/dev/ttyAMA0', 9600)

while True:
        select = ser.readline()
        print ("you selected playlist" + select)
        if select[0] == '1':
                subprocess.call(['mpc', 'clear'])
                subprocess.call(['mpc', 'load', 'PlayList_button_1'])
                subprocess.call(['mpc', 'play'])
                time.sleep(.2)
        elif select[0] == '2':
                subprocess.call(['mpc', 'clear'])
                subprocess.call(['mpc', 'load', 'PlayList_button_2'])
                subprocess.call(['mpc', 'play'])
                time.sleep(.2)