- Buy a MCP3008 and some resistors suitable for this project, you can calculate resistor value here: voltage divider calculator, Vin = 4.2V and Vout needs to be maximum 3.3V. I used a 2kOhm and a 5,6kOhm resistor.
- Wire up the MCP3008 like this mockup:
- Measure the voltage of the connecting point of the two resistors and to ground, it should not be over 3.3V
- If you want you can wire up LEDs aswell.
- Install Raspidmx (pngview) and compile it by using
make
- Install this script by running the following command from terminal or ssh:
git clone https://github.com/joachimvenaas/gbzbatterymonitor
- Navigate into the gbzbatterymonitor folder:
cd gbzbatterymonitor
- Edit the config by typing
nano config.py
Here you must edit the battery voltages to suit your needs, add the path to pngview and icons and add the resistor values. - Test the script by running command:
python main.py
- If the script runs as desired you can close it by pressing Ctrl+C
- Add the script to startup by typing
sudo nano /etc/rc.local
and addpython /home/pi/gbzbattery/main.py &
beforeexit 0
- Reboot to test
- You can close the script by killing its process id. Find the id by typing
ps aux | grep gbzbattery
. Thenkill <id>
- Charge your battery to 100%
- Run
python monitor.py
to get the exact values from the battery - Let the battery run down to 3.2V
- Copy the data to Excel or something simular and calculate the 75%, 50% and 25% values
- Edit the config.py file with the newly gattered data to get more accurate batterymeter