Pocket Adventures.com
by John Till

Products| Cartridge| Guides| 3D Models| Shipping|

There are a couple of methods for setting up safe shutdown. If you're using an ADS1x15 for battery monitoring, then it's recommended to use the MintyPi method. Otherwise, if you simply want to implement safe shutdown without battery monitoring, then the easiest method is to add a couple of lines to /boot/config.txt. (This assumes you've wired a shutdown button to GPIO 4, and that GPIO 17 provides a signal to the power board to keep the Pi turned on even when the switch is off.)

Safe Shutdown

sudo nano /boot/config.txt
Scroll to the bottom and change it to the following:
dtoverlay=gpio-poweroff,gpiopin=17,active_low="y"
dtoverlay=gpio-shutdown,gpio_pin=4
Save the changes using Ctrl-X, Y, Enter.


MintyPi Battery Monitoring

These instructions are described in detail here.

Run the installation commands for Mintybatterymonitor:
cd ~
wget https://raw.githubusercontent.com/HoolyHoo/Mintybatterymonitor/master/MintyInstall.sh
sudo git clone https://github.com/HoolyHoo/Mintybatterymonitor.git
sudo chmod 777 MintyInstall.sh
sudo ./MintyInstall.sh
That last line will take awhile as it also updates the already-installed software.

If you're using a GPIO Assist board and have attached a Safe Shutdown button, use these instructions:
sudo nano Mintybatterymonitor/MintyShutdown.py
Scroll to the bottom and change it to the following:
# Interrupts
shutdown_btn = Button(4, hold_time=2)
shutdown_btn.when_held = shutdown
shutdown_btn.when_released = togglestate
pause()
Save the changes using Ctrl-X, Y, Enter.

After rebooting, single-tapping the safe shutdown button will toggle the on-screen battery.
(Note that it will take a few seconds before it appears.)

Holding the safe shutdown button for a couple of seconds will shutdown the system. After the screen goes blank, wait at least five seconds and then power off the device. This will ensure that it's no longer writing to the SD card. (If you peek inside the case past the SD card, you should see the green LED switch off.)

If you notice that the on-screen battery doesn't accurately reflect your remaining power, you can edit the MintyBatteryMonitor.py file and use an alternate set of VOLT% values:
cd ~
cd Mintybatterymonitor
sudo nano MintyBatteryMonitor.py
Change the VOLT75, VOLT50, VOLT25 and VOLT0 values to the numbers to the right of the hashtag. (Or use any other values you feel are appropriate.)
Save the changes using Ctrl-X, Y, Enter.

If you want to use the power switch to toggle the battery indicator, make sure that the dtoverlay=gpio-shutdown line in /boot/config.txt is commented out. Then, turning the power switch off and back on quickly should toggle the battery indicator. (This only works if your power system is set up for safe shutdown. If your power switch cuts the power completely, the device will simply turn off, un-safely.




Copyright © 2024 Pocket Adventures.com