Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Raspberry Pi - can it turn itself off with the Mini Pushbutton Power Switch

Hello

Im trying to get a Raspberry Pi set up so that when I run ‘shutdown’ on the OS, it will also shut off it’s own power. Has anyone ever done this?

I was hoping to use a Mini Pushbutton Power Switch but it has turned out to be non-simple. Under Linux, the GPIO pins apparently can be set to steady output high, or steady output low, after shutdown using the special gpio-poweroff setup in /boot/config.txt. There is also an ‘active_low’ feature which apparently will force a transition from high to low to trigger events.

My issue is that no matter how I try to hook a GPIO to the Power Switch, i can’t seem to make it happy. If power is off, and I connect GPIO 2 to ‘Off’ on the switch, then hit the pushbutton to turn on, the Pi power light flashes for a moment then shuts down - almost like as part of the bootup process, Gpio2 is going high for a moment and triggering the ‘off’ on the Power Switch momentarily, so it’s doing an endless loop of partial booting.

I also tried GPIO17 instead of GPIO2, connecting to Off on the switch - this is supposedly naturally low so it seems like it’s OK when booting up, but then i can never seem to get it to trigger the ‘off’ pad on the switch after shutdown so its not shutting off power.

Also tried connecting to Control instead of Off, this was a bit of a mess

I will try again later but I was wondering if this has not been done before? Is it necessary to put some in-between circuit between the GPIO pin and the pushbutton switch?

I also looked into the slide-switches but i couldnt figure out if / how they allow software self poweroff through a pin.

Thanks

Hello, hmbright.

I was able to get this working with dtoverlay=gpio-poweroff,gpiopin=17 in my /boot/config.txt and GPIO17 connected to the pushbutton power switch’s OFF pin. (You’ll probably need to use GPIO 9+ since GPIO 0-8 are pulled high by default when the RPi starts up.)

If you keep having trouble, could you post some pictures of your setup showing how you have everything connected? Do you have a screen connected to your RPi so you can make sure the shutdown sequence is finishing normally?

Kevin

Hi Kevin,

Thank you, I really appreciate it.

I was using this

dtoverlay=gpio-poweroff,gpiopin=27,active_low=1 

but when i changed it to what you had

dtoverlay=gpio-poweroff,gpiopin=27

it started working correctly.

Thanks!!!

1 Like

Hi,
I did ist on the same way as you did.

dtoverlay=gpio-poweroff,gpiopin=17

I use a Pi Zero W with a Big Power Switch MP.

When the Pi shutdown, it seems to be very fast. The Pololu Switch cut the power very fast after shutdown. What is your meaning, is that the right behavior?

Best regards!

I checked the syslogs and generated a systemd service that start a script when system begin the shutdown.
I found no errors in my syslogs and the script is working well.
So, I think the shutdown with dtoverlay=gpio-poweroff,gpiopin=17 is safe. :slight_smile: