# \[Plugin\] GPIO Buttons: Control Volumio 2/ Volumio 3 with buttons

**URL:** <https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076>\
**Category:** Plugins\
**Created:** [August 3, 2016, 8:08am UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076 "2016-08-03T08:08:32Z")\
**Posts on this page:** 20\
**Page:** 7

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [March 28, 2023, 3:09pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/125 "2023-03-28T15:09:08Z")

</div>

> **[Pi Supply Switch - On/Off Power Switch for Raspberry Pi](https://uk.pi-supply.com/products/pi-supply-raspberry-pi-power-switch)**
>
> The Pi Supply Switch is the solution to all of your Raspberry Pi power management problems. It is an intelligent, ATX style power supply switch for the revolutionary Raspberry Pi computer allowing you to turn it off with just the quick push of a...

---

<div class="post-metadata">

**Author:** ![\_McCormick](https://community.volumio.com/user_avatar/community.volumio.com/_mccormick/32/23381_2.png) [@\_McCormick](https://community.volumio.com/u/_McCormick)\
**Post date:** [February 10, 2024, 8:47pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/126 "2024-02-10T20:47:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [February 10, 2024, 9:09pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/127 "2024-02-10T21:09:34Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![\_McCormick](https://community.volumio.com/user_avatar/community.volumio.com/_mccormick/32/23381_2.png) [@\_McCormick](https://community.volumio.com/u/_McCormick)\
**Post date:** [February 10, 2024, 9:52pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/128 "2024-02-10T21:52:01Z")

</div>

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

 ![Снимок экрана 2024-02-11 в 00.41.14](https://community.volumio.com/uploads/default/original/3X/b/3/b30eb59252d952d71f43094e5bd43b27819e6af6.jpeg)

---

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [February 10, 2024, 10:20pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/129 "2024-02-10T22:20:03Z")

</div>

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)

```auto
#!/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

```

---

<div class="post-metadata">

**Author:** ![\_McCormick](https://community.volumio.com/user_avatar/community.volumio.com/_mccormick/32/23381_2.png) [@\_McCormick](https://community.volumio.com/u/_McCormick)\
**Post date:** [February 11, 2024, 8:12am UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/130 "2024-02-11T08:12:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [February 11, 2024, 8:49am UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/131 "2024-02-11T08:49:25Z")

</div>

Yeah, that’s is the part where you write the code what the button needs to do…  
like:

```auto
volumio play
volumio stop
volumio pause
volumio toggle

```

```auto
  if ["$STATUS0" == 1] && ["$PREV" == 0]; then
	volumio play
	PREV=1
  elif ["$STATUS0" == 0] && ["$PREV" == 1]; then
	volumio stop
	PREV=0
  fi

```

---

<div class="post-metadata">

**Author:** ![paulf](https://community.volumio.com/letter_avatar_proxy/v4/letter/p/eb9ed0/32.png) [@paulf](https://community.volumio.com/u/paulf)\
**Post date:** [April 5, 2024, 5:05pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/132 "2024-04-05T17:05:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [April 5, 2024, 7:52pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/133 "2024-04-05T19:52:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulf](https://community.volumio.com/letter_avatar_proxy/v4/letter/p/eb9ed0/32.png) [@paulf](https://community.volumio.com/u/paulf)\
**Post date:** [April 6, 2024, 9:53am UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/134 "2024-04-06T09:53:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zoran\_Buric](https://community.volumio.com/user_avatar/community.volumio.com/zoran_buric/32/9847_2.png) [@Zoran\_Buric](https://community.volumio.com/u/Zoran_Buric)\
**Post date:** [April 14, 2024, 7:23pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/135 "2024-04-14T19:23:39Z")

</div>

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](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/116)

---

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [April 14, 2024, 7:34pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/136 "2024-04-14T19:34:57Z")

</div>

i do advise to use resistors to avoid floating pins, which will cause unstable behavior.

---

<div class="post-metadata">

**Author:** ![Zoran\_Buric](https://community.volumio.com/user_avatar/community.volumio.com/zoran_buric/32/9847_2.png) [@Zoran\_Buric](https://community.volumio.com/u/Zoran_Buric)\
**Post date:** [April 15, 2024, 2:33pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/137 "2024-04-15T14:33:05Z")

</div>

ok thanks

---

<div class="post-metadata">

**Author:** ![Kuyadrei0502](https://community.volumio.com/user_avatar/community.volumio.com/kuyadrei0502/32/23399_2.png) [@Kuyadrei0502](https://community.volumio.com/u/Kuyadrei0502)\
**Post date:** [June 6, 2024, 1:55am UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/138 "2024-06-06T01:55:29Z")

</div>

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](https://www.amazon.com/Geekworm-Ultra-Thin-Raspberry-Aluminum-Embedded/dp/B096TV9164)

Thanks,

---

<div class="post-metadata">

**Author:** ![Pirx](https://community.volumio.com/user_avatar/community.volumio.com/pirx/32/383_2.png) [@Pirx](https://community.volumio.com/u/Pirx)\
**Post date:** [June 9, 2024, 5:56am UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/139 "2024-06-09T05:56:35Z")

</div>

An I2S DAC is apparently connected in the linked product. I2S cards usually use the GPIOs 2, 3 and 4.

---

<div class="post-metadata">

**Author:** ![supercrab](https://community.volumio.com/user_avatar/community.volumio.com/supercrab/32/818_2.png) [@supercrab](https://community.volumio.com/u/supercrab)\
**Post date:** [June 22, 2024, 4:11pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/140 "2024-06-22T16:11:37Z")

</div>

My plugin GPIO control might be able to help you out. 🙏🏽😉

---

<div class="post-metadata">

**Author:** ![paulf](https://community.volumio.com/letter_avatar_proxy/v4/letter/p/eb9ed0/32.png) [@paulf](https://community.volumio.com/u/paulf)\
**Post date:** [June 22, 2024, 7:59pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/141 "2024-06-22T19:59:49Z")

</div>

Cheers supercrab, that’s great news.  
Is there a link to it where i can download from?

Paul F.

---

<div class="post-metadata">

**Author:** ![Wheaten](https://community.volumio.com/user_avatar/community.volumio.com/wheaten/32/33147_2.png) [@Wheaten](https://community.volumio.com/u/Wheaten)\
**Post date:** [June 22, 2024, 9:34pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/142 "2024-06-22T21:34:56Z")

</div>

just via the plugins within Volumio.

---

<div class="post-metadata">

**Author:** ![supercrab](https://community.volumio.com/user_avatar/community.volumio.com/supercrab/32/818_2.png) [@supercrab](https://community.volumio.com/u/supercrab)\
**Post date:** [June 30, 2024, 4:40pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/143 "2024-06-30T16:40:53Z")

</div>

@paulf Check the plugin section in volumio, I think it’s in the system category.

---

<div class="post-metadata">

**Author:** ![MarkZ](https://community.volumio.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@MarkZ](https://community.volumio.com/u/MarkZ)\
**Post date:** [August 20, 2024, 4:47pm UTC](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076/144 "2024-08-20T16:47:45Z")

</div>

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

[Previous page](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076.md?page=6)

[Next page](https://community.volumio.com/t/plugin-gpio-buttons-control-volumio-2-volumio-3-with-buttons/4076.md?page=8)
