Hello friends
play/pause works great with a button, but I need it to work with a switch (ON - Play, OFF - Pause) Does anyone know how to do this?
I would strongly advise against it. Adding a permanent switch means your pulling a GPIO up or down continuously. Which will end up in defects. (PMIC)
I have been using a switch connected in this way for a long time to turn off my raspberry and have not had any problems. I only use GPIO 26
then you could try something like this. PREV is added to hold the button state and avoid that the code keeps being executed. (code is not tested)
#!/bin/bash
# select pin GND - D0
GPIO0=26
# Print debug lines => 1 is print
debug=1
PREV=0
# Common path for all GPIO access
BASE_GPIO_PATH=/sys/class/gpio
# Utility function to export a pin if not already exported
exportPin()
{
if [ ! -e $BASE_GPIO_PATH/gpio$1 ]; then
echo "$1" > $BASE_GPIO_PATH/export
fi
}
# Utility function to set a pin as an output
setInput()
{
echo "in" > $BASE_GPIO_PATH/gpio$1/direction
}
exportPin $GPIO0
setInput $GPIO0
# If debug == 1
if [ $debug == 1 ]; then
echo "---------------------------------------------------"
printf "GPIO 0: %s\n" "${GPIO0}"
printf "STATUS 0: %s\n" "${STATUS0}"
fi
# continuously monitor current value
while true; do
sleep 1s
STATUS0=$(cat $BASE_GPIO_PATH/gpio${GPIO0}/value)
if [ $debug == 1 ]; then
echo "---------------------------------------------------"
printf "STATUS 0: %s\n" "${STATUS0}"
printf "PREV: %s\n" "${PREV}"
fi
if [ "$STATUS0" == 1 ] && [ "$PREV" == 0 ]; then
#Write here the code what needs to be done:
PREV=1
elif [ "$STATUS0" == 0 ] && [ "$PREV" == 1 ]; then
#Write here the code what needs to be done:
PREV=0
fi
done
when I run the script I get an error
GPIO 0: 26
STATUS 0:
play.sh: line 47: syntax error near unexpected token `doβ
play.sh: line 47: ` do something.'Preformatted text
Yeah, thatβs is the part where you write the code what the button needs to doβ¦
like:
volumio play
volumio stop
volumio pause
volumio toggle
if [ "$STATUS0" == 1 ] && [ "$PREV" == 0 ]; then
volumio play
PREV=1
elif [ "$STATUS0" == 0 ] && [ "$PREV" == 1 ]; then
volumio stop
PREV=0
fi
Is it possible to add a function that would toggle a LED driven via a transitor, perhaps every second, from a spare GPIO when volumio has been put into mute mode by the play / mute button?
At least itβs then possible to see from the front panel that volumio is in mute mode if no screen is connected.
Unfortunately my programming skills arenβt up to the job, so thanks in advance if this facility is added by someone.
First set you requirements correct. Play (media control) and mute (Audio control) are 2 different things.
The output voltage of a GPIO port is 3,3V which is already to high for a LED so you already need to add a resistor,. Adding a transistor seems an overkill.
If people want to step in, they need to know exactly what you want.
Thanks for the quick response Wheaten.
I just need a flashing LED to indicate Volumio is in pause mode.
The transistor was added rather than driving it direct from the IO pin, so yes, it was a bit of an overkill.
Hello, when I put the buttons for turn on and play and others, do I have to put resistors or not? So far I have installed the turn on/off button but I have not installed the resistor and everything is working great. Did it work according to the semi posted by Wheaten [Plugin] GPIO Buttons: Control Volumio 2/ Volumio 3 with buttons - #116 by Wheaten
i do advise to use resistors to avoid floating pins, which will cause unstable behavior.
ok thanks