I'm calling it version 1 with the intention of revisiting it to address some lose ends and make some improvements. Version 2 will come when I need a longer hold-up, rather than the (almost) immediate shutdown.
You can find my excuses elsewhere as to why it's taken so long and why this documentation is a bit thin, but here's the short version of events:
- I needed a UPS for the Raspberry Pi to handle sudden power loss and prevent file corruption.
- The "Wemo 18650 Battery Shield" will output whilst taking power and it's cheap. I like cheap.
- The RPi can't be trusted to shut it's own power off so I looked for the smallest, cheapest Arduino-type board (to minimise faffing) to handle the delay-if-then logic. I got a couple of DigiSpark boards (clones as it turned out) and cobbled together the code and connections.
- Saw some odd behaviour, maybe the DigiSpark board isn't what I need.
- Worked around the issue, circuit and code seem to work on the bench until the RPi is actually connected (instead of manually simulating the I/O signals).
- (some time later) Sick of the DigiSpark; I switch to the trusty Nano, then add some traffic-light LEDs for indication and because I can.
- More odd behaviour; looks like back-feeding through the µC inputs. I should really disconnect the GND too.
- I transplant a small DPDT relay onto the opto-isolated "arduino" relay board and re-wire again to also break the GND this time.
- Dammit! Killed a Pi pin by forgetting 5V > 3V3. Moved to next GPIO and added a pot.div.
- Success!?! Tested the UPS with the RPi two or three times, mounted both in the head and moved on to power distribution but I'm waiting on some parts that got delayed in transit, so I'm using the time to write this. Below is the schematic I did a few days(?) ago.
3 - RPi_UP (DI), RPi GPIO output - high after boot, low just before complete shutdown.
2 - RPi_SD (DO), RPi GPIO input - active-high to trigger shutdown of RPi (through pot.div; 5V >> 3V3).
Not Used: A0 - ADC to 18650 battery, 4V - disconnect load from battery when voltage drops.
4 - Main Power present/not present (DI).
Not Used: 5 - Keep alive/immediate select switch (DI)*
6 - Relay (DO) - active-high opto-isolated (N.O. contacts). Opens to disconnect battery.
7 - Amber UP LED.
8 - Red SD LED.
9 - Green MPP LED.
*Mode selection input:
Not Used: Keep alive = 0V - waits until battery is low before shutting down and disconnecting.
Keep alive = N.C. - immediate safe shutdown and disconnect.
RPi signals to UPS when it is up. UPS tells Pi to shutdown and waits for RPi_UP to go low before removing power.
RPi_UP=21 # GPIO output - high after boot, goes low a few seconds before complete shutdown. RPi_SD=17 # GPIO input - active-high to trigger shutdown of RPi (through pot.div; 5V >> 3V3).