We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

Nicko vS
Posts: 7
Joined: Tue Feb 10, 2015 10:58 pm

Pi 5 power button technical questions

Wed Nov 15, 2023 5:13 pm

I have a couple of questions about the power button on the Raspberry Pi 5 and I'm hoping the good people here might be able to help.

The first is a software question: On the Desktop version of Raspberry Pi OS pressing the power button while the Pi is running brings up a menu asking what the user wants to do, while pressing the button on the Lite version initiates an immediate power down. How is the button press detected and where are the scripts that are triggered when the press is detected? I was hoping that this was just going to be a configuration line for the triggerhappy daemon but I don't see anything in the /etc/triggerhappy/triggers.d folder. It would be helpful to be able to carry out custom functions when the button is pressed.

The second question is a hardware one: The Raspberry Pi 5 documentation shows how to add an external power button[1] to the Pi 5, saying that you can add a momentary-close push button across the provided two pins. Is it possible to use an IO line from another device to drive one of these pins as in input instead of using push button? This would be valuable for battery-powered situations where you want to wake up the Pi based on something other than just the timer in the RTC. I'm hoping that one of the two pins is ground and the other is an input pin with a pull-up, and driving that pin with an open-collector/open-drain output from some other device can emulate a push button without needing to add any extra components. It would be helpful to get validation of this before I blow up my rare and precious Pi5 experimenting to find out! (If this is the case, it would also be helpful to know which pin is which!)

[1] https://www.raspberrypi.com/documentati ... wer-button

cleverca22
Posts: 9535
Joined: Sat Aug 18, 2012 2:33 pm

Re: Pi 5 power button technical questions

Wed Nov 15, 2023 9:56 pm

Nicko vS wrote:
Wed Nov 15, 2023 5:13 pm
How is the button press detected and where are the scripts that are triggered when the press is detected?
i would start by running "evtest --grab" as root, over ssh

you will likely see a power button input device
due to --grab, it will steal all events and not allow normal processing of them
so you should be able to click power and just see the event and no action be triggered

i'm guessing its something in systemd, logind, or wayland, that captures the event normally, and does something

Nicko vS
Posts: 7
Joined: Tue Feb 10, 2015 10:58 pm

Re: Pi 5 power button technical questions

Wed Nov 15, 2023 10:59 pm

Thanks for the pointer. That was most helpful. Using that I was able to find that pressing the power button generates a KEY_POWER keypress event on /dev/input/event0. This device is kept open by both the triggerhappy daemon and also by the systemd login service. By default the power-off functionality is handled by that service and it can be disabled by editing /etc/systemd/logind.conf. Once I disabled the default functionality I was able to provide a trigger configuration in /etc/triggerhappy/triggers.d to handle my custom action.

As for my own hardware question, close examination of the board shows that one of the two pins (the one with the round pad, further away from the physical power button) is connected to ground. I will try driving the other pin low with an open drain output from a Pi Pico when I have the right wires and see if it can be used as an input.

Nicko vS
Posts: 7
Joined: Tue Feb 10, 2015 10:58 pm

Re: Pi 5 power button technical questions

Thu Nov 16, 2023 4:12 am

For anyone who is interested, connecting the two pin "external power button" connector just to the right of the USB-C socket to an open drain output works very well as a way to switch the Pi5 on and off using an external control. The pin closest to the USB-C socket should be connected to the OD output and the pin further away is ground (which likely needs to be common between the Pi5 and whatever you use to control the input). I tested this with a Pi Pico but it should work with anything with an open drain output. A logic output might also work, but with that there is more chance of damaging things if the voltages are wrong.

Return to “General discussion”