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
Hi devs and everyone! I don’t if im in thr right thread, i just want to know or is there any way or execute command to know the available physical gpio pin. If, i have this st400 dac hat attached on rpi4?
Here’s my dac hat from geekworm https://www.amazon.com/Geekworm-Ultra-Thin-Raspberry-Aluminum-Embedded/dp/B096TV9164
Thanks,
An I2S DAC is apparently connected in the linked product. I2S cards usually use the GPIOs 2, 3 and 4.
My plugin GPIO control might be able to help you out.
Cheers supercrab, that’s great news.
Is there a link to it where i can download from?
Paul F.
just via the plugins within Volumio.
I’m stuck trying to get the GPIO Buttons working on a RPI5, I can’t get the plugin (0.8.3) to function, it appears to install correctly however I’m not able to save any configuration settings and then it becomes “InActive”.
Anybody able to help me with some pointers to get these working?
Cheers
Mark Z