8

I use a power bank to power my Raspberry Pi, and I want to create script to turn off the Raspberry Pi when the battery level is low, but I cannot find any command to visualize the battery level.

I don't know if is possible. Does such a command exist?

5
  • 2
    The short answer is yes; here are a few links to get you started raspberrypi.org/forums/viewtopic.php?t=41849 raspi.tv/tag/raspberry-pi-monitoring-its-own-battery-voltage also check this question raspberrypi.stackexchange.com/questions/7414/… Commented Sep 5, 2015 at 4:03
  • 3
    It is unlikely that voltage will be a good indicator of battery level as most batteries now a days contain a step up voltage regulator. Commented May 28, 2016 at 3:05
  • @MohammadAli They certainly can, but it does of course depend on the battery OP is using.
    – Dan
    Commented Jun 27, 2016 at 19:07
  • 2
    @dan that is true, although it is highly likely that he is talking about a usb battery bank, you may still be correct Commented Jun 27, 2016 at 19:09
  • 4
    @MohammadAli Yeah, you're right, "Power Bank" does sound regulated. He COULD crack open the power bank and measure the actual cell voltages if he wants to get his hands dirty though.
    – Dan
    Commented Jun 27, 2016 at 19:12

2 Answers 2

3

No Raspberry Pi can correctly measure its input voltage without at least one additional component.

https://github.com/aboudou/picheckvoltage

Some Raspberries can detect whether the input voltage is below 4.65 V or not - and provide a simple answer of yes/no , true/false. They use this binary distinction to display the undervoltage symbol.

3
  • This is using a sledge hammer to crack a nut! An ADC to convert voltage then a program to monitor voltage is overkill. If you wanted to do this all you need is a comparitor and 2 resistors. Using a linear regulator is inefficient, and 1A inadequate for the Pi.
    – Milliways
    Commented Jul 27, 2016 at 7:09
  • 4
    That gives only a yes/no answer to "Is the voltage too low ?'" , doesn't it ? I think the Pi can already "measure" that : raspberrypi.org/forums/viewtopic.php?t=82373
    – flakeshake
    Commented Jul 27, 2016 at 7:16
  • 3
    As @MohammadAli said in the comments, monitoring the output voltage of a power bank is meaningless: the output will stay close to 5V until the cell is empty and you have to shut down. Commented Feb 7, 2017 at 8:48
0

Ideally you would need access to the battery terminals (not the 5V) to be able to measure it and feed into the software. For that I have been using the analog-to-digital converter ADS1115 and this tutorial from Adafruit https://learn.adafruit.com/adafruit-4-channel-adc-breakouts/python-circuitpython .

You would the need to know which voltage is "low enough" and then issue a shutdown command to the Pi. I've seen some solutions posted here, like this one: How to check how much battery is left on my Raspberry Pi in the terminal?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.