[FIXED] Normally open momentary switch and on/off command

Momentary On-Off Switch.pngI have build a Volumio player and have attached an normally open momentary switch to pins 5 (GPIO3) and 7 (GPIO4) and 6 (GND). I can switch Volumio on by pushing the switch. I installed the GPIO buttons plugin and enabled GPIO4 to shutdown Volumio.
A friend told me to use 2 diodes so there’ll be no connection betweeen the two GPIO pins.

3 Likes

This is awesome. Thanks for posting that and the instructions for assigning the button for shutdown. I added it to my system last night with a pair of LED status lamps running off the 3.3v supply and GPIO14 to show power and when the system is booted up and running. It works perfectly.

2 Likes

What diodes did you use? I don’t yet understand the different types.

EDIT:…If you are not using a HAT of any kind that requires GPIO3 …

You only need GPIO3 to turn on and off.

GPIO3 control for turning on is part of the rpi’s firmware.
Use the GPIO buttons plugin and set shutdown to GPIO3.

This is how I have mine setup and from standby ( red light on) press the button it powers up and boots volumio then press it again while in volumio it will shut down…so on and so forth

2 Likes

I hadn’t seen your reply but of course that would work. Excellent post.

I wonder: using GPIO3 you have no problems with audio DACs?
All DACs use GPIO3

1 Like

Thats a valid point.
Not using a HAT DAC myself. I use a USB DAC, So not experienced any problems.
Perhaps others using a HAT DAC can comment

1 Like

I’m using a HiFi Berry and through some experimentation on a new streamer and I can confirm that using GPIO3 for on/off will not work with a DAC HAT. As soon as you assign #3 for Enable Shutdown in GPIO Buttons, it conflicts with the DAC and no music will play. Assign it to another pin and it works fine again (reboot required).

EDIT: I’ve tested on Volumio 2 and Volumio 3 with the same results.

1 Like

Yeah …Massive oversight on my part. Not using a DAC HAT myself and honestly didn’t consider it.
Thanks for the input though I’ll edit my original post.

Hi.

Im New with Volumio. So, if have correctly understood. Ist just conect the 2 wires of the monetary switch to ge GPIO3 and the ground pin in front of the GPIO 3, and install the GPIO buttons plugging, and assign the GPIO 3 to on/off. Correct?

Thanks in advance.

If you are not using a HAT of any kind that requires GPIO3.

then yes, just use gpio buttons plugin and select gpio 3 to shutdown. To boot up from standby is part of the rpi’s firmware.
Tested on and rpi 3b+ and rpi4…works fine

Hi! Mind me to know what are the scripts did you use to on and off the pi and what is the value/kind of diode did you used.
Thanks,

There is not much to it with regards to coding, but this solution causes problems with HAT-DACS and is not very stable to my experience. So I never advice it.
You need GPIO3 and a 2nd GPIO to start up. The diodes are to avoid interference between the 2 GPIO’s
If you for example use GPIO 21 to restart then the following line needs to be added to the userconfig.txt:
dtoverlay=gpio-shutdown,gpio_pin=21,active_low=1,gpio_pull=up

Does it work with ky-040 encoder? If i put 2 wires and diode each wire for switch?

Then you can simply use the Rotary Encoder 2 plugin, no diodes needed:

Well i manage now to power on/off the rpi3b using encoder. Gpio3 on gpio4 off

But in the rpi4b not working…

Thanks,