Power off button on RPI2

Hi all,

it might sound a simple and silly question, but does anybody have a solution to power off a RPI2 running volumio with a simple button that is not the main power switch one?

A lot of times the web ui gets shut down before even thinking to use the shut down button, so you are left with a running volumio that you would just want to switch off with a button.

You can do that with GPIO pins and GPIO Buttons plugin.
For instance, if your setup does not use GPIO 3 (pin #5), you can wire a push button (not a ON/OFF switch!) between pins 5 and 6 (GND) and use Shutdown action with GPIO Buttons. Good thing is that the same button will also power-up the device (benefit of using GPIO 3).

I am using a Pi 3 and a HiFiberry DAC+. Does anyone know if I can use GPIO 3, as described above. I currently am using the plug-in but have the power-down switch connected to another GPIO. It would be nice to be able to take advantage of the power-up feature offered by GPIO 3 as well as the power-down.

Per the WiFiberry website “GPIO2-3 (pins 3 and 5) are used by our products for configuration. If you are experienced with I2C, you might add other slave devices. If you are a novice, we don’t recommend this at all.”

1 Like

i2c uses GPIO3/2 (clock & data). My take on this is: at boot certain software may use i2c to detect and configure boards (automated devicetree detection thanks to EEPROM read for instance), but that’s at a time where, if you connect a push-button, that part of the wire will be “up in the air”, and not shorted to GND by the button. So I do not anticipate this may cause any trouble (but I take no responsibility if it does of course).

Volumio does have it’s own (more complex) DAC auto-detect procedure which does use i2c too, and interaction with such use of GPIO3 is discussed here.
The discussed case is different: unwanted error messages happen when no HAT are connected to the Pi. I do not think the same (non-critical) thing will happen in your case because HifiBerry board does connect GPIO3 (hence no clock stretching phenomena).
In any case, should auto-detections even fail, you may set audio-out device with UI and save config, so it should not adversely impact your setup I guess.

Your call, but if you decide to try, thanks for posting your feedback.

Well I tried it but unfortunately I could not get any sound out of the DAC so I guess it’s a no-go. Maybe there are some other things that could be done to get it to work but I’m a programming idiot. It did turn the unit on and off but seemed to take the DAC out of the equation.

I do appreciate you taking the time to respond to my question.

Just a question: did you manually set and saved the Audio preference on your DAC settings (even if they are shown correct)?

Well…and another one: are you using a real push-button that does not stay in “pushed” position?

1 Like

Based on your response I revisited the situation. For several months I have been successfully using the plugin with the shutdown feature using GPIO 26. I then had to physically disconnect the power supply before I could restart. For this test I started up normally to ensure everything was working normally. I then changed the shutdown GPIO setting to GPIO 3 in the plugin and saved. Everything was playing normally. Based on your comment I went to the DAC settings which were displayed as expected and did a manual save which immediately killed the music. The GUI still showed that things were going normally (music was advancing, volume control worked in the GUI but no sound from the speakers). I then wired in the button to GPIO 3 and using it I initiated a shutdown; which, based on the flashing lights on the PI 3 generated a controlled shutdown and the GUI went to a state that would indicate that the unit was off. The green light on the DAC which normally would go out remained lit. I then pressed the button and, based on the flashing lights on the PI 3 generated a start up and in fact the GUI was reactivated but there was no sound. Going through all the settings everything appeared normal but there was no sound. When I reverted the system back to using GPIO 26 everything returned to normal. It appears that there is a conflict between the plugin and the DAC when using GPIO 3 in this configuration.

I am using a momentary contact push button.

As a FYI a question about this scenario was asked in the HiFiBerry forums back in November but never elicited a response. I was hoping somebody here might have successfully tried it.

Thanks again for your time.

Any chance you could hook a HDMI display to the Pi to check if any error message kicks-in (and check shutdown/restart are real: the leds thing should be the same whatever GPIO used)?
Better: could you get a log file through SSH, with sudo journalctl > /tmp/logfile.txt and then download it with a SFTP client?

Could be that I2c auto detection plugin has not finished its work before GPIO_Buttons plugin kicks-in, and then registered interrupt function alters proper board config: that’s one problem mentioned in the opened Github issue.
Log messages may help understanding.

HifiBerry confirmed i2c communication happens at any time on DAC+, so GPIO3 can not be used for shutdown for this product (but should be OK for DAC+ Light for instance).

I may have another option to propose, based on this.
The idea is to use 2 different pins for ON and OFF, but with one single physical button.
ON stays on GPIO3, but OFF detection (the one that GPIO Button handles & “blocks”) is then moved to another GPIO (GPIO 27 in the schematic for instance), hence freeing GPIO3 for normal i2c communication when needed (i.e; Hifiberry configuration).
From user’s perspective it’s only one button.

Wiring could be simpler, I think, in particular if one finds a dual push button (DPST-NO Momentary) with 2 separated entries in parallel: GPIO3 & GPIO27 on one side, GND for both on the other side.

1 Like

I was just getting ready to try to get the info you requested when I saw your post. I’ve been sidetracked fighting another issue this morning. I updated from 2.014 to 2.114 to see if that had any affect on the issue and now I’m getting random pause in my playback which I guess other people are having similar problems with. Missed that post on the HiFiberry forums, glad you found it as it definitively answers the question. The post I found was never answered.

Your proposed solution sounds promising. I’m not sure I have the required switch handy, but I’ll scrounge around in my junk drawer and see if I can find something that will work.

Thanks again for all your help … now if I can figure out how to use an i2C LCD display with Volumio ver 2.xxx I will be close to being able to put together my project (previous attempts seem to be using Volumio ver 1.55)

For such a big leap, you probably want to make a clean re-install flashing new 2.114 image: seems to work far better.

I think you’re right. I’m going to give that a shot. I did a several hour test and I’m fairly sure the problem revolves around using the “Random” play feature.

Haven’t had a chance to do a test with the push button, but I may get to that later tonight or tomorrow morning if I can get the right hardware.

Once you get such 1-button solution working, please post feedback here: I’m pretty sure some other users will benefit from it.
Thanks.

It appears that it will in fact work. I didn’t have a DPST switch so I thought to use two separate switches and press them both at the same time which will simulate the DPST. One was wired to handle the shutdown function and it’s GPIO pin number was entered into the plugin. The other was wired between GPIO 3 and ground. Wiring up a DPST would be similar using one side for the shutdown function and the other for the startup function. Be careful of the voltages, ground connection and default value of the GPIO pins. See details here:

github.com/tomatpasser/gpio-buttons

When the unit was running, pressing both buttons simultaneously initiated an orderly shutdown. Pressing both simultaneously again initiated an orderly startup. Please note that this does not kill the power to the Pi, but rather places it in a “standby” mode (the little red light on the Pi will stay on).

Somebody that has more knowledge than me may want to see what, if anything, taking GPIO 3 to ground at shutdown does to the software (Volumio in particular)

Thanks again for the help and the suggestion that got me on the right track.

Hi all,

Will this also work on the Asus Thinker Board too?

@macmpi : see my post https://forum.volumio.org/normally-open-momentary-switch-and-off-command-t12638.html how I did solve the on/off problem with one switch.

first of all nice that this app exists, nice work :smiley:

now the problem I run into, I use a push button and select at poweroff gpio 3, this way the pi goes into a kind of sleep mode and when pressing again the pi starts up again, so far everything is ok.
but as soon as I select another gpio pin number under power, the pi shuts down completely.

now my question, is it possible that i can use both of these functions but with two different push buttons, one for real shutdown and one for that sleep/power function which only works with gpio 3

1 Like

have you thought about the Pimoroni on/off shim? I have it on my rpi3 and it works fine.

that’s also a nice option, maybe I’ll go for such a Pimoroni.

Thanks for the tip.

there is a note for the pi4 …

It’s possible to use OnOff SHIM and a 2.5A USB micro-B power supply to power a Raspberry Pi 4. However, the recommended power spec for the Pi 4 is 3A, so you may run into low power issues (especially if using power hungry USB devices).

pi 4 is usb-c so you could run in power supply problems…