The Raspberry Pi is a single board computer that runs on a Debian based operating system. The Raspberry Pi finds many applications due the fact it can operate like a normal computer and its ability to interact with the outside world using sensors. Due to it small size, it make it easier to deploy in the field for applications that require high computing capabilities that are not found in microcontrollers. When deploying sensor systems in the field, power is one of the most important factors to consider. The fact that the Raspberry Pi operates like a normal computer makes it even more important. Shutting the Raspberry Pi unconventionally due to power outage may result to corruption of it storage leading to loss of one's work and/or data. It is for this reason the we developed the DSAIL Power Management Board to power the Raspberry Pi in the field intelligently.
Figure 1: DSAIL Power Management Board
To enable the Raspberry Pi to control power management board, several programs were written. The programs are:
The power management program enables the Raspberry Pi to monitor the state of charge (SOC) of the battery used in the system. This helps ensure that the Raspberry Pi does not shut down due to depletion of charge in the battery. This also protects the battery from being over discharged resulting to a longer lifespan. The program enables the Raspberry Pi to make an informed decision of shutting down when the battery reaches the cut off voltage. The program has a provision for setting the number of hours one intend to power the Raspberry Pi in a day. It is possible to set the system to power the Raspberry Pi during different time windows in a day. The program is responsible for shutting down the system when the time matches the specified shutdown time.
The program is written in Python and uses third party libraries from Adafruit which are board, busio, and digitalio. The program reads the battery voltage after every 30 seconds and compares it with the predetermined cut off voltage. Whenever the voltage goes below the specified cut off voltage, the program initiates the shutdown of the Raspberry Pi and the entire system. The program uses our own made modules to achieve this. The modules are rtc.py and adc.py that we will look into in the following two sections:
The rtc.py module helps in setting the alarm of a DS3231 Real Time Clock (RTC) board on the power management board to schedule the wake up of the system. The alarm function of the rtc.py module is called to set the RTC's alarm to schedule wake up of the system whenever the Raspberry Pi has "decided" to shut down.
The adc.py module is used by the power management program to read the voltage of the battery used in the system. The Raspberry Pi lacks an onboard analog to digital converter (ADC) and hence has to use an external ADC to read the battery voltage which is an analog quantity. In our system, we used the MCP3008 i/p ADC to enable our system to read the battery voltage. The power management program calls the volt function from this module after every thirty seconds to read the battery voltage. After every five minutes, the voltage reading at that moment is saved in a datestamped CSV file alongside with the time at that moment using the volt_csv function from this module.
The flow chart below shows the performance of the power management program:
Figure 2: Power management program flow chart
The time set program program is used to set time of the Raspberry Pi every time on wake up since the Raspberry Pi lacks an onboard RTC.
- Raspberry Pi 2/3/4
- Raspberry Pi power supply
- An SD Card loaded with Raspberry Pi OS—follow the steps outlined here to install Raspberry Pi OS.
- Access to the internet.
- Ability to access the Raspberry Pi's command line.
Plug the Raspberry Pi on the power management board as shown in Figure 3.
-----Pi + Power board -------
Power the Raspberry Pi and access its terminal. Ensure the Raspberry Pi is connected to the internet.
Clone the powering Raspberry Pi in the Raspberry Pi by running the following command on the terminal:
git clone https://github.com/DeKUT-DSAIL/powering-raspberrypi.gitAfter cloning the repository, run the following commands to create a virtual environment and install the requirements needed to run the programmes:
cd powering-raspberrypi
./requirements_setup.shReset the RTC by running the following following on the terminal.
python rtc_reset.pyLet us set the RTC time by syncing it with the Raspberry time. Run the following command on the terminal.
python timeset.py** Add info **
Next, we will need to schedule the programs to run every time on boot using crontab. Run the following the command:
crontab -eIf it is the first time using crontab, you will be prompted to choose an editor. Choose nano editor by entering 1. Copy and paste the following in the crontab:
@reboot /home/'username'/powering-raspberrypi/timeset.sh
@reboot /home/'username'/powering-raspberrypi/power.shReplace 'username' with the set Raspberry Pi username e.g. 'pi'.
The system is now ready for deployment. To monitor the voltage profile of the battery, check the csv files stored in the created battery-voltage folder. In case the system fails, check for the errors raised in the log files stored in the powering-raspberrypi folder.

