EveryCircuit
Contact
Reviews
Home
HeJa
modified 8 years ago

Raspberry Pi Safe Shutdown

14
4
582
10:05:13
Safe power-down for RaspBerry Pi. Power-off a Pi without a "shutdown" of the operating system will result in a "operating system crash". This endangers the integrity of the SD-card. We must therefore "delay" the power-off until the Pi has closed the io on the SD-card and HALTed. This circuit will do this. Pressing the Power button on the left will charge the left upper capacitor. The PNP-transistor will conduct, and the gate of the MOSFET will be "high". The MOSFET conducts, the rightmost LED will glow and the Pi (symbolized by R=10 Ohm on the far right) will be powered, and it will boot. The capacitor slowly discharges, thru the base-emitter circuit of the PNP-transistor and the 150kOhm resistors. The switch stands for a GPIO pin A: it gets HIGH = 3.3V when a Python script starts when the Pi has booted. The capacitor is now charged thru the NPN-transistor, so the power will remain. Obviously this pin A must get HIGH within the period the capacitor is completely discharged. The green LED will glow when the pin is HIGH. The circuit is now stable, and delivers power to the Pi. A shutdown will make pin A eventually LOW (=0 V), and the capacitor will discharge slowly. The Pi has the discharge period to completely HALT. 30 Seconds is normally more than enough. You can decrease the period by decreasing the value of the capacitor, or reducing the resistor to the base of the PNP-transistor. The (Python) script in the Pi to control pin A also uses the Power button for controlled shutdown. The script checks another GPIO pin B, connected to the button via a diode. The two resistors will limit the HIGH voltage to 3,3V (safe for the Pi). Let's assume power = ON. A short push on the Power button makes pin B LOW, and the script will issue a "shutdown halt after 1 minute". A long push (> 1 sec) will result in "shutdown reboot after 1 minute". The script will blink the green led when a shutdown is planned (NB: a duty cycle of 10% is still enough to keep the capacitor charged). While a shutdown is planned a push will cancel the shutdown. Parts and design considerations: N-mosfet = IRLZ24N, it has a voltage drop of only 80 mV. NB: A P-mosfet (in the Vcc line) generally has a greater ON-resistance than an N-mosfet. PNP and NPN transistors are low-power like BC556B, BC547B. The capacitor across the lower resistor (for pin B) is necessary for "debouncing": I have interrupts attached to my buttons in the script. The Pi-input-pins are connected thru 10kOhm resistors, for safety. I have tested the circuit and the script on a RPi1 B+ with RuneAudio. Discharge period is now about 30 seconds. Interested in the Python-script? Please send a comment. So far , so good (2015-12-11): the hardware works, and the software too, and I don't see any flaws. I will use the circuit on my Pi2 /Hifiberry DAC+ RuneAudio music-and-radioplayer.
published 8 years ago
Taz8du29
8 years ago
Yup ! Can you link your script please ? Thx !
HeJa
8 years ago
What do you mean by "link"?
HeJa
8 years ago
2016-03-24 I have built the circuit on "experiment print", on top of the Hifiberry DAC+, and it works fine. I extended the softshut.py script with rotary encoders with buttons, so I can adjust volume and playlist entries. If you want the script, please let me know.
Lucan01
7 years ago
Please post link to your script here. :)

EveryCircuit is an easy to use, highly interactive circuit simulator and schematic capture tool. Real-time circuit simulation, interactivity, and dynamic visualization make it a must have application for professionals and academia. EveryCircuit user community has collaboratively created the largest searchable library of circuit designs. EveryCircuit app runs online in popular browsers and on mobile phones and tablets, enabling you to capture design ideas and learn electronics on the go.

Copyright © 2023 by MuseMaze, Inc.     Terms of use     Privacy policy