Main Menu

search

You are here

softShutdown

[last updated: 2017-09-04]
-----

As noted elsewhere, in order to avoid SD card corruption, it is necessary to properly shut down the rPi before powering it off. You can of course close all windows and programs by directly interacting in the GUI, but this circuit and software allows you to do a soft shutdown by pressing a pushbutton.

The hardware is simply a pushbutton connected to one of the GPIO pins. In my implementation, I connect the PB to ground through a 1k resistor (for short-circuit current limiting), and program the GPIO pin as an input with internal pullup resistor enabled.

First hardware implementation is part of the GMC GUI project, and softshutdown circuit is wired on the (go to:) power shield.

softShutdown.py sketch is here (or will be when I get it written...):
Current version (AutoRunAtStartup02.py) starts an infinite while-loop that continuously reads a PB, and if pressed, executes:
os.system("sudo shutdown -h now")
...after having done:
import os
This way of doing things does work, but the while-loop appears to bog down everything else. At some point I'll investigate using a callback background thread instead.

Execute the sketch at startup, and run it in the background:

.

.

.

eof