Tackling Graceful Shutdowns on the GBZ
- Camble
- Posts: 885
- Joined: Thu May 05, 2016 2:31 am
- Location: Scotland
- Has thanked: 269 times
- Been thanked: 488 times
Re: Tackling Graceful Shutdowns on the GBZ
You'll still be able to use a Pololu switch to perform a graceful shutdown. The problem of the supply being on exists with both the Banggood module, as there is no EN pin to shut it off manually. You could always add a switch between your battery and the power supply module though.
-
- 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
@Popcorn : I've followed your tutorial for the pololu graceful shutdown.
When I switch off I have a kernel panic.

When I switch off I have a kernel panic.

-
- 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
Or simply replace the reset tact button by a slide switchCamble wrote:You'll still be able to use a Pololu switch to perform a graceful shutdown. The problem of the supply being on exists with both the Banggood module, as there is no EN pin to shut it off manually. You could always add a switch between your battery and the power supply module though.

Re: Tackling Graceful Shutdowns on the GBZ
I doubt it: how can it work if the boost module has no EN pin or so?? But maybe it would be possible to do an EN pin with a transistor.... I'd be interested in that because I found 1A chargers for very cheap (TP4056) and booster/protectors as well (DLX-UPDC5V)..SidSilver wrote:Or simply replace the reset tact button by a slide switchCamble wrote:You'll still be able to use a Pololu switch to perform a graceful shutdown. The problem of the supply being on exists with both the Banggood module, as there is no EN pin to shut it off manually. You could always add a switch between your battery and the power supply module though.
tent:wq
tent:wq
-
- 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
Oh sorry, I had not read correctly.tent wrote:I doubt it: how can it work if the boost module has no EN pin or so?? But maybe it would be possible to do an EN pin with a transistor.... I'd be interested in that because I found 1A chargers for very cheap (TP4056) and booster/protectors as well (DLX-UPDC5V)..SidSilver wrote:Or simply replace the reset tact button by a slide switchCamble wrote:You'll still be able to use a Pololu switch to perform a graceful shutdown. The problem of the supply being on exists with both the Banggood module, as there is no EN pin to shut it off manually. You could always add a switch between your battery and the power supply module though.
tent:wq
With no EN pin you need to cut directly the battery, indeed.
Re: Tackling Graceful Shutdowns on the GBZ
I was thinking about trying to implement kind of an enable pin to be added to the more "Simple" boosters/chargers out there...
or, by the way, did somebody understand the difference between the adafruit 1000 basic and the 1000C? for GBZ purposes I do not quite see evident difference or missing part (enable pin, low battery, etc.)..
tent
or, by the way, did somebody understand the difference between the adafruit 1000 basic and the 1000C? for GBZ purposes I do not quite see evident difference or missing part (enable pin, low battery, etc.)..
tent
tent:wq
- 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
The Charger lets you charge the battery while you use it (charge+play). The Basic can't charge during use, as far as i know.tent wrote:I was thinking about trying to implement kind of an enable pin to be added to the more "Simple" boosters/chargers out there...
or, by the way, did somebody understand the difference between the adafruit 1000 basic and the 1000C? for GBZ purposes I do not quite see evident difference or missing part (enable pin, low battery, etc.)..
tent
Re: Tackling Graceful Shutdowns on the GBZ
Really?? Well I hope then that when you plug in usb it will give precedence to output and not charge!!
) but in the end not really a vital feature.. and from your calculations what would be the tipical consumptions of those 3.5 lcds? (I suppose the rest is quite low.. Ok hub and dac if you use it and wifi dongle but Ok.

tent:wq
-
- 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
Tackling Graceful Shutdowns on the GBZ [RECALBOX 4.0+ VERSION]
I've managed to make the "Tackling Graceful Shutdowns" works on Recalbox v4.0
Here is how I've done that.
First of all Recalbox has no sudo command (user is root)
It doesn't have omxplayer (will be added in the next 4.1 version), it doesn't have Git and it doesn't have crontab !
So, some little tricks are needed to make the Popcorn TGS works :
Using WinSCP (or equivalent), create a folder "/recalbox/scripts/GBZPowerMonitor" where you put the python script and the mp4 videos from Popcorn's Github.
I've done some little modifications in the python to make it works : remove all sudos and change the video paths
[spoiler="code"][/spoiler]
Then create a script "S99gbzpower" in "/etc/init.d" to launch the python script on startup
To do that you will need to make the folder writable, run the command
Don't worry, on restart Recalbox reset the folder rights to make it read only.
@Popcorn : Thanks again for this great feature
I've managed to make the "Tackling Graceful Shutdowns" works on Recalbox v4.0
Here is how I've done that.
First of all Recalbox has no sudo command (user is root)
It doesn't have omxplayer (will be added in the next 4.1 version), it doesn't have Git and it doesn't have crontab !
So, some little tricks are needed to make the Popcorn TGS works :
Using WinSCP (or equivalent), create a folder "/recalbox/scripts/GBZPowerMonitor" where you put the python script and the mp4 videos from Popcorn's Github.
I've done some little modifications in the python to make it works : remove all sudos and change the video paths
[spoiler="code"]
Code: Select all
#!/usr/bin/env python2.7
# date: 30/05/16
# author: Popcorn <abandonedemails@gmail.com> - Add "Sudomod" in the subject or your message will not be received
# version: 1.0a
# name: GBZ-Power-Monitor - a Power Management utility for the Gameboy Zero project
# description: a GPIO monitor that detects low battery and power switch status which provides a graceful shutdown facility
# source: https://github.com/NullCorn/GBZ-Power-Monitor/
# modified by SidSilver 08/07/16 for Recalbox
import RPi.GPIO as GPIO
import os
import sys
import time
batteryGPIO = 17 # GPIO 17/pin 0
powerGPIO = 27 # GPIO 27/pin 2
sampleRate = 0.1 # tenth of a second
batteryTimeout = 10 # 10 seconds
powerTimeout = 1 # 1 second
shutdownVideo = "/recalbox/scripts/GBZPowerMonitor/lowbattshutdown.mp4" # use no space or non-alphanum characters
lowalertVideo = "/recalbox/scripts/GBZPowerMonitor/lowbattalert.mp4" # use no space or non-alphanum characters
playerFlag = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(batteryGPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(powerGPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def lowBattery(channel):
#Checking for LED bounce for the duration of the battery Timeout
for bounceSample in range(1, int(round(batteryTimeout / sampleRate))):
time.sleep(sampleRate)
if GPIO.input(batteryGPIO) is 1:
break
global playerFlag
while playerFlag is 1:
time.sleep(1)
#If the LED is a solid condition, there will be no bounce. Launch shutdown video and then gracefully shutdown
if bounceSample is int(round(batteryTimeout / sampleRate)) - 1:
playerFlag = 1
#videos should be enabled when Recalbox will be in version 4.1 as it doesn't have omxplayer yet
#os.system("/usr/bin/omxplayer --no-osd --layer 999999 " + shutdownVideo + " --alpha 180;shutdown -h now");
os.system("shutdown -h +1");
playerFlag = 0
sys.exit(0)
#If the LED is a solid for more than 10% of the timeout, we know that the battery is getting low. Launch the Low Battery alert.
if bounceSample > int(round(batteryTimeout / sampleRate * 0.1)):
playerFlag = 1
#videos should be enabled when Recalbox will be in version 4.1 as it doesn't have omxplayer yet
#os.system("/usr/bin/omxplayer --no-osd --layer 999999 " + lowalertVideo + " --alpha 160;");
playerFlag = 0
#Discovered a bug with the Python GPIO library and threaded events. Need to unbind and rebind after a System Call or the program will crash
GPIO.remove_event_detect(batteryGPIO)
GPIO.add_event_detect(batteryGPIO, GPIO.BOTH, callback=lowBattery, bouncetime=300)
#If we know the battery is low, we aggresively monitor the level to ensure we shutdown once the Power Timeout is exceeded.
lowBattery(batteryGPIO)
def powerSwitch(channel):
#Checking for LED bounce for the duration of the Power Timeout
for bounceSample in range(1, int(round(powerTimeout / sampleRate))):
time.sleep(sampleRate)
if GPIO.input(powerGPIO) is 1:
break
if bounceSample is int(round(powerTimeout / sampleRate)) - 1:
#When the Power Switch is placed in the off position with no bounce for the duration of the Power Timeout, we immediately shutdown
os.system("shutdown -h now")
try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass
sys.exit(0)
def main():
#if the Low Battery LED is active when the program launches, handle it
if GPIO.input(batteryGPIO) is 0:
lowBattery(batteryGPIO)
#if the Power Switch is active when the program launches, handle it
if GPIO.input(powerGPIO) is 0:
powerSwitch(powerGPIO)
#Add threaded event listeners for the Low Battery and Power Switch
try:
GPIO.remove_event_detect(batteryGPIO)
GPIO.add_event_detect(batteryGPIO, GPIO.FALLING, callback=lowBattery, bouncetime=300)
GPIO.remove_event_detect(powerGPIO)
GPIO.add_event_detect(powerGPIO, GPIO.FALLING, callback=powerSwitch, bouncetime=300)
except KeyboardInterrupt:
GPIO.cleanup()
main()
#We make an endless loop so the threads running the GPIO events will always be listening, in the future we can add Battery Level monitoring here
while True:
time.sleep(1)
GPIO.cleanup()
Then create a script "S99gbzpower" in "/etc/init.d" to launch the python script on startup
Code: Select all
#! /bin/sh
case "$1" in
start)
recallog "Starting GBZ Power Management"
python /recalbox/scripts/GBZPowerMonitor/gbz_power_monitor.py &
;;
stop)
recallog "Stopping GBZ Power Management"
killall python
;;
restart|reload)
;;
*)
esac
exit $?
Code: Select all
mount -o remount,rw /
@Popcorn : Thanks again for this great feature
Re: Tackling Graceful Shutdowns on the GBZ
there's a more expensive alternative but requires next to no work:
ATXRaspi-R2
https://www.youtube.com/watch?v=w4vSTq2WhN8
ATXRaspi-R2
https://www.youtube.com/watch?v=w4vSTq2WhN8
Who is online
Users browsing this forum: No registered users and 1 guest