Tackling Graceful Shutdowns on the GBZ

Various user-contributed guides for software-related things
User avatar
Popcorn
Trailblazer
Trailblazer
Posts: 354
Joined: Thu May 05, 2016 12:58 am
Location: Berlin
Has thanked: 29 times
Been thanked: 71 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by Popcorn » Tue May 24, 2016 6:32 am

Hi guys,

Here's my latest video to show that the automatic Low Battery Warning shutdown works 100%. The only intervention that I do in this video is just changing the power supply for the screen, from the wall to the battery. This is just to increase the load of the battery which forces a Low Battery condition. The shutdown process is all done by the daemon. I don't touch anything else or trigger it in anyway.

https://www.youtube.com/watch?v=TRkEfD04unk

In this, I'm using all the core GBZ components: A PI Zero, a BW Screen, a Lipo Battery, a Powerboost, etc. My battery level is around 3.3V so it's almost dead. In the start of the video, I have everything running off of the battery, except for the screen. When I switch the screen's power supply to run off of the battery, the screen pushes the Low Batt LED into a solid condition. And you can see the solid RED on the powerboost. The daemon detects that and then proceeds to shutdown as expected. Works great!

On the hardware side, I followed this guide BUT I discovered some biggish problems with this solution. And that is because when the battery level drains down around 3.2-3.3V, there's alot of bounce on the LED. So you don't want to powerdown on the first flash of the LED but you want to shutdown only when it's a solid condition.

So I solved this with some coding that ensures that there is no bounce over a certain period of time. So this way, you know for sure that battery is near dead and it's time to shutdown.

To do this, you use all the same GBZ components, like a Powerboost. But the extra things you will need are:
  • Some wire
    2N3904 NPN transistor
    47k resistor
All you do is solder wire to the led of the Low Battery LED then, attach that to the 47K resistor. Then you attach the other end of the resistor to the Transistor Base. Then you attach the Transistor Emitter to GPIO17 and the Transistor Collector to GND.

Here's the wiring diagram of the resistor and transistor from the original guide (note: I use GPIO17)

Image

Also, I still want to clean up my code so I'll release that in the next day or so.

Image

User avatar
Fleder
Posts: 849
Joined: Thu May 05, 2016 9:04 am
Location: Germany
Has thanked: 183 times
Been thanked: 258 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by Fleder » Tue May 24, 2016 6:52 am

Wow, this is some really good work here Popcorn!
Can't wait to see your GBZ in action. Thanks.

prerunnerseth
Posts: 279
Joined: Fri May 06, 2016 5:36 pm
Has thanked: 16 times
Been thanked: 229 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by prerunnerseth » Tue May 24, 2016 11:27 am

Popcorn wrote:Hi guys,

Here's my latest video to show that the automatic Low Battery Warning shutdown works 100%. The only intervention that I do in this video is just changing the power supply for the screen, from the wall to the battery. This is just to increase the load of the battery which forces a Low Battery condition. The shutdown process is all done by the daemon. I don't touch anything else or trigger it in anyway.

https://www.youtube.com/watch?v=TRkEfD04unk

In this, I'm using all the core GBZ components: A PI Zero, a BW Screen, a Lipo Battery, a Powerboost, etc. My battery level is around 3.3V so it's almost dead. In the start of the video, I have everything running off of the battery, except for the screen. When I switch the screen's power supply to run off of the battery, the screen pushes the Low Batt LED into a solid condition. And you can see the solid RED on the powerboost. The daemon detects that and then proceeds to shutdown as expected. Works great!

On the hardware side, I followed this guide BUT I discovered some biggish problems with this solution. And that is because when the battery level drains down around 3.2-3.3V, there's alot of bounce on the LED. So you don't want to powerdown on the first flash of the LED but you want to shutdown only when it's a solid condition.

So I solved this with some coding that ensures that there is no bounce over a certain period of time. So this way, you know for sure that battery is near dead and it's time to shutdown.

To do this, you use all the same GBZ components, like a Powerboost. But the extra things you will need are:
  • Some wire
    2N3904 NPN transistor
    47k resistor
All you do is solder wire to the led of the Low Battery LED then, attach that to the 47K resistor. Then you attach the other end of the resistor to the Transistor Base. Then you attach the Transistor Emitter to GPIO17 and the Transistor Collector to GND.

Here's the wiring diagram of the resistor and transistor from the original guide (note: I use GPIO17)

Image

Also, I still want to clean up my code so I'll release that in the next day or so.

Image
This looks awesome. I assume youre also including the code to shut down when triggered by the button/switch? Once I get my boards in and built I'll see about sending you one for free. I assume the transistor and pull up are because you need to translate the LB output into an active low? If this is the case then I have already integrated that into my board.

Masato
Posts: 6
Joined: Fri May 06, 2016 4:40 pm
Location: Canada
Been thanked: 4 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by Masato » Wed May 25, 2016 12:00 pm

prerunnerseth wrote:I assume the transistor and pull up are because you need to translate the LB output into an active low?
I believe there are two reasons for this. One is yes, it needs to be translated to an active low. But the reason the LED signal is used instead of the LBO signal (which goes low when battery is low), is because when the LBO is high, it is tied to the VBAT voltage, which is anywhere from 2.7-4.2V, while the Pi GPIO are only officially rated at 3.3V

User avatar
Popcorn
Trailblazer
Trailblazer
Posts: 354
Joined: Thu May 05, 2016 12:58 am
Location: Berlin
Has thanked: 29 times
Been thanked: 71 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by Popcorn » Wed May 25, 2016 1:43 pm

Masato wrote:
prerunnerseth wrote:I assume the transistor and pull up are because you need to translate the LB output into an active low?
I believe there are two reasons for this. One is yes, it needs to be translated to an active low. But the reason the LED signal is used instead of the LBO signal (which goes low when battery is low), is because when the LBO is high, it is tied to the VBAT voltage, which is anywhere from 2.7-4.2V, while the Pi GPIO are only officially rated at 3.3V
That's exactly right! Thanks Masato. And amazing, the code should work directly with your board then, @[mention]prerunnerseth[/mention]. And I'd be more than happy to take anything for free! woo. ;) The code is working pretty well. I'm trying to stress test it now.

I thought I'd share the video of the graceful power switch as well.

https://www.youtube.com/watch?v=nRJ42oSrIg4

User avatar
Ganreizu
Posts: 552
Joined: Thu May 05, 2016 8:20 am
Has thanked: 168 times
Been thanked: 97 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by Ganreizu » Wed May 25, 2016 2:25 pm

Wow it's perfect! Great work!

GnobarEl
Posts: 42
Joined: Mon May 23, 2016 4:10 am
Has thanked: 17 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by GnobarEl » Wed May 25, 2016 2:35 pm

Congratulations for your great work.

Can't wait to have a tutorial to make this work :)

SidSilver
Posts: 263
Joined: Sun May 22, 2016 6:22 am
Location: France
Has thanked: 137 times
Been thanked: 37 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by SidSilver » Wed May 25, 2016 2:37 pm

Wow ! Great job ! I definitly need that for my GBZ project. :shock:

prerunnerseth
Posts: 279
Joined: Fri May 06, 2016 5:36 pm
Has thanked: 16 times
Been thanked: 229 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by prerunnerseth » Wed May 25, 2016 3:36 pm

Masato wrote:
prerunnerseth wrote:I assume the transistor and pull up are because you need to translate the LB output into an active low?
I believe there are two reasons for this. One is yes, it needs to be translated to an active low. But the reason the LED signal is used instead of the LBO signal (which goes low when battery is low), is because when the LBO is high, it is tied to the VBAT voltage, which is anywhere from 2.7-4.2V, while the Pi GPIO are only officially rated at 3.3V
actually the output of the LBO pin of the boost is an open collector output. this means that it can only pull low. it is going to the VBAT rail because of the transistor on it. If you would remove the LED and transistor circuit you would see no voltage on this pin and it should be able to drive the input pin of the pi directly assuming the pull up on the pi is low enough current. the reason they do not use this pin to pull directly low on the bottom of the LED like the other LEDs on the battery charger IC is because this pin is only rated for 100uA. Not enough current for a LED. I translated it with a NFet to an active LOW from the LED circuit so that i could keep the LED circuit for customers who want that LED.

User avatar
Popcorn
Trailblazer
Trailblazer
Posts: 354
Joined: Thu May 05, 2016 12:58 am
Location: Berlin
Has thanked: 29 times
Been thanked: 71 times

Re: Tackling Graceful Shutdowns on the GBZ

Post by Popcorn » Wed May 25, 2016 5:58 pm

@prerunnerseth would love for you to look this over to see if it can be optimized more. Ill be the first to admit that my electronics kung-fu is pretty weak

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest