The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.34 (Linux)
File Line Function
/showthread.php 906 errorHandler->error

Thank you for your donation!

Instruction Guide Use hardware momentary switches to control moOde
Hardware momentary switches can be used to control the play, pause, next, previous functions of moode. They can also be used to power off and to launch a playlist.
On the hardware side, you set your hardware button to connect the ground pin of your RPi with a GPIO pin of your choice. Have a look here to see how to select the gpio pins.
Then you have to open a ssh session.

Create a new directory called "hwbuttons"
mkdir hwbuttons

Go to the new directory
cd hwbuttons

Open nano text editor

Paste the following python script. This python script include the following buttons:

Toggle play pause: GPIO 12
Previous: GPIO 10
Next: GPIO 11
Volume up: GPIO 20
Volume down: GPIO 26
Power off: GPIO 9
Launch playlist "JAZZ_STREAM": GPIO 16
Launch playlist "MUSIC_STREAM": GPIO 13

It works for radio stations and music files. Make sure no spaces on playlists names.
If you are not interested in a particular button, mark it with # everywhere it appears.

#script for moode audio GPIO buttons
#not sure this is needed:
#sudo apt-get update
#sudo apt-get install python-dev
#sudo apt-get install python-rpi.gpio
#on playlist names no spaces

import RPi.GPIO as GPIO
import sys
import time
import os
import subprocess

#set GPIO mode

#Define your GPIO pins
SW_PREV = 10
SW_NEXT = 11
SW_PLAY = 12
SW_PL1 = 16
SW_PL2 = 13

#code to manage BUTTONS
GPIO.setup(SW_PREV,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_NEXT,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PLAY,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_VOLUP,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_VOLDOWN,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PL1,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PL2,GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
     prev_switch = GPIO.input(SW_PREV)
     next_switch = GPIO.input(SW_NEXT)
     play_switch = GPIO.input(SW_PLAY)
     volup_switch = GPIO.input(SW_VOLUP)
     voldown_switch = GPIO.input(SW_VOLDOWN)
     poweroff_switch = GPIO.input(SW_POWEROFF)
     pl1_switch = GPIO.input(SW_PL1)
     pl2_switch = GPIO.input(SW_PL2)
     if prev_switch == False:['mpc', 'prev' ])
        print "previous"
     elif next_switch == False:['mpc', 'next' ])
        print "next"
     elif poweroff_switch == False:['mpc', 'stop' ])['sudo', 'poweroff' ])
        print "shutting down"
     elif volup_switch == False:['/var/www/','up','2' ])
        print "volumeup"
     elif voldown_switch == False:['/var/www/','dn','2' ])
        print "volumedown"
     elif pl1_switch == False:['mpc','clear' ])['mpc','load','JAZZ_STREAM' ])['mpc','play' ])
     elif pl2_switch == False:['mpc','clear' ])['mpc','load','MUSIC_STREAM' ])['mpc','play' ])
     elif play_switch == False:['mpc', 'toggle' ])
        print "play"

  except KeyboardInterrupt:
     print "\nExit"
#End of program

ctrl-x and save the file as ""

To set the script to run every time you launch moode
sudo nano /etc/rc.local

Add the line below just before the exit 0
sudo python /home/pi/hwbuttons/ &

It works on my moode streamer. I did put this together from information I found on the volumio forum and from help I received from Kent (aka theoldpresbyope). It is possible that some of the lines in the script are not needed.


Messages In This Thread
Use hardware momentary switches to control moOde - by remy1961 - 05-20-2018, 03:05 PM

Forum Jump: