rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Soft Power Switch

Sun Jun 12, 2016 10:23 pm

Hello,

This has to have been solved before, but I can't find it via google or searching on this board.

I want to run a pi off a LiPo battery, but when the pi is off, I don't want it draining the battery. I'm looking for a configuration that allows for the following:

1) when the pi is off, no power is drawn from the battery
2) pressing a momentary switch will power on the pi
3) pressing the same momentary switch will trigger a python (or other script) to issue the sudo shutdown -h now command to power down the pi
4) once the pi is powered down, it stops drawing power from the battery

Is this even possible? Does anyone know of a solution?

Thanks
Rick
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
DougieLawson
Posts: 35793
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Soft Power Switch

Sun Jun 12, 2016 11:32 pm

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
Sneds
Posts: 4
Joined: Sun Jun 12, 2016 10:24 pm
Location: United States

Re: Soft Power Switch

Mon Jun 13, 2016 12:53 am

That is a cool extension, I never heard about it!

geoffr
Posts: 85
Joined: Wed Aug 22, 2012 11:25 am
Location: Melbourne, VIC

Re: Soft Power Switch

Wed Jul 06, 2016 2:43 am

rickseiden wrote:Hello,

This has to have been solved before, but I can't find it via google or searching on this board.

I want to run a pi off a LiPo battery, but when the pi is off, I don't want it draining the battery. I'm looking for a configuration that allows for the following:

1) when the pi is off, no power is drawn from the battery
2) pressing a momentary switch will power on the pi
3) pressing the same momentary switch will trigger a python (or other script) to issue the sudo shutdown -h now command to power down the pi
4) once the pi is powered down, it stops drawing power from the battery

Is this even possible? Does anyone know of a solution?

Thanks
Rick
I think one of the problems is that everybody has slightly different expectations of what an on/off switch should do. :-)

I have been working on making something like this for a project I am busy with, where one of the requirements I have is to be able to just press a button to turn the Pi on or off.
I have got to a design which I soldered up on veroboard this week, and which is working (it isn't perfect).

This is what the finished product looks like:
onoff-switch.jpg
onoff-switch.jpg (55.41 KiB) Viewed 1657 times
You can find some more details on my blog at http://www.rehmet.alt.za/blog

The latest schematic on my blog is not the final circuit. I have changed a couple of resistors, and I still need to update the schematic and post it.

The idea of how it works is that when you push the switch it does 2 things, firstly: charging a capacitor, which gradually discharges into a Schmitt trigger inverter and which also switches a GPIO input to high. The Schmitt trigger inverter's output is held low long enough for the P-channel MOSFET to power the Pi until the serial console becomes active. I also use the serial console TX line to charge the capacitor (via one of the BJTs), so as long as the Pi is booted, power stays on.

I also have an interrupt handler, which triggers on the falling edge of the GPIO line which is switched by the push-button. When I get an interrupt, I send a signal to systemd to shut down and power off the Pi.
When the serial console becomes quiescent at the end of a power off, the output of the inverter into the MOSFET goes high, and power it cut.

After power off, the current drain of the whole setup drops to less than 0.1mA, which I am happy with. Hopefully that is low enough to satisfy your needs. I think a Pi Zero when powered off draws in the region of 22mA.

paulv
Posts: 558
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Soft Power Switch

Sun Jul 10, 2016 8:05 pm

Have a look at this post or the references to other ones in it. It may do what you want viewtopic.php?f=37&t=145954

Success

Return to “Other projects”