This project uses 2 commonly found breakout boards and one custom board to handle startup and shutdown. A breakout board with the MP2315 buck converter is used to step down the voltage to 5 volts and introduces an enable input.  The other breakout board is the INA226  Two GPIO pins are used on the Rasberry PI.  One as input for a pushbutton switch to trigger safe shut down of the Pi (GPIO pin 24).  Another as output to disable the buck converter (GPIO pin 26).  Also, the I2C interface is used to communicate with the INA226 (GPIO pin 02 and GPIO pin 03).

MP2315 Adjustable Buck converter

INA226 Bi-Directional Current and Power Monitor

Custom Board - RPI Shutdown Interface

RPI Shutdown Interface Design

The buck converter board is attached at J1 with P4 as the Enable pin of the buck converter.  When the push button is pressed, 12v is supplied through the 330K resistor R4 to the Enable pin of the buck converter, which begins to turn on and supply 5V power on pin P3 and power to the Raspberry Pi (RPI), which starts up.  The 5V passes through R1 and the Diode D2 and latches the Enable pin of the buck converter high.  This keeps the buck converter enabled keeping power supplied to the RPI even after the push button is let go.  In this process Zener Diode D1 keeps the voltage on P4 below 5.6 volts.  The RPI is attached at JP2 with pin 2 being a GPIO pin.  While the RPI is powered up it keeps the GPIO pin high (3.3v).  The 10K resistor R2 ensures the current driven into the GPIO pin stays low enough to not damage the pin - needed because P4 could be as high as ~5.6 volts.  When the RPI has an internal request to be shut down, it does a safe shutdown and at the end of that process it pulls the GPIO pin low.  This pulls down the enable on the buck converter, and it stops producing 5V on it's output, reducing the latch voltage.  The buck converter shuts down and the RPI is no longer receiving power.

The RPI has a different pushbutton  on another GPIO pin to trigger shutdown request.   The same process occurs if the user requests shutdown from the command line.

MP2315 Adjustable Buck Converter Modifications

There are two modifications to make on the buck converter.  The first is to set it to an output voltage of 5V.  This can be done by following the directions for the converter and cutting the proper trace and bridging the pads for 5V output with some solder.  After this modification you check the voltage with a meter to guarantee its in the range of 4.95 to 5.2 so that it does not cause problems with the Raspberry Pi.

The next modification is to remove the pull-up resistor on the enable pin on the board.  This is needed to allow power to be off by default.See the image below. This resistor can be carefully removed with the tip of a soldering iron

Updating the Raspberry Pi config.txt file

We want to configure gpio pin 24 as an input pin that when grounded, will start the shutdown.  Also, configure gpio pin 26 as an output to provide a power-off signal to the buck controller.  This can be done by adding the below two lines to the /boot/config.txt file on the Rasperry Pi.

# input pin to start the shut down sequence
# output pin to enable power source

Test the Raspberry Pi Startup and Shutdown

By pressing the pushbutton attached to the Shutdown Interface board, the Raspberry PI should start up.  Pressing the pushbutton between ground and pin GPIO24 should shut down the Raspberry Pi.

Adding the Voltage, Current, and Power Monitoring

A Python script is used to collect the voltage and current and track power used.  The script is launched at startup using a systemd service.  If the battery voltage goes below a threshold, it triggers a shutdown with a 5 minute...

Read more »