Electronics: Clean Shutdown Circuit

Electronics: Clean Shutdown Circuit

When a piece of artwork is displayed in a gallery, those special instructions on how to shut down a computer are not always transferred to the person closing the gallery each night. My expectation is that the mains plug will just be pulled out. Now, often this will not corrupt the memory of a Raspberry Pi, but I didn’t want to take that risk, I wanted to find out how to do it properly, which took me on quite a journey. I looked at what was already available, and some UPS circuits almost did what I wanted, but when I started, nothing did exactly what I wanted.

The sequence of events should go something like this:

  1. Power is removed from the Akiniscope.
  2. The clean shutdown circuit says to the Raspberry Pi “Hey, we haven’t got any power, anymore. I suppose we ought to shut down”.
  3. Raspberry Pi says “Oh!, better shut down, then. I’ll tell you when I’ve shut down”.
  4. The clean shutdown circuit sees when the Raspberry Pi has shut down, and then removes the power to the Raspberry Pi.

That last bit, removing the power from the Raspberry Pi, was often missing from the circuits I found, relying on a human to intervene.

What chunks are needed, then? Something to hold up the volts to the Raspberry Pi, once the input power is removed; something to tell the Raspberry Pi to shutdown; and something to remove the power, once the Raspberry Pi has shut down. Here’s the circuit I worked out:

R1 & R2 are a potential divider, sending a safe voltage level to the Raspberry Pi, so it can detect the input power disappearing.

C1, C2 & C3 are supercaps, holding up the voltage when nothing else is. I gradually worked my way up to three by experimentation. They make the circuit quite expensive, as the ones I chose are about £10 each.

The schottky diode separates the supercap circuit from the input circuit, with a volt drop of about 0.5V.

Or gate U1 is used to work out when to shut down the power to the Raspberry Pi, with inputs from the main power input, and from the Raspberry Pi. The Raspberry Pi has a setting in /boot/config.txt for an output which signals right at the end of shutdown:

# Set GPIO21 to low once shutdown complete

dtoverlay=gpio-poweroff,gpiopin=21,active_low=”y”

The output of U1, when low, signals that power to the Raspberry Pi should be removed. Where’t the bit of the circuit that removes the power? I’m afraid I got lazy, and offloaded that to another board. I use a Pimoroni Wide Input Shim. This raises the volt drop back up to 5V, and also has an Enable input, which is where the output of U1 attaches (via a 1K resistor, for protection).

And that’s the full circuit.

Since building the supercap circuit, I’ve also tried fitting a Adafruit PowerBoost 1000 Charger and add an or gate in the same way as the supercap circuit. This worked, and I’ll probably use this in future designs. The only downside I can see from using the Powerboost is that the supercaps charge very quickly, whereas a LiPo battery attached to the Powerboost will take a time to charge. But this will be a rare event, maybe just on initial installation.