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?

Steve Robillard
  • 34,687
  • 17
  • 103
  • 109
  • 2
    The short answer is yes; here are a few links to get you started https://www.raspberrypi.org/forums/viewtopic.php?t=41849 http://raspi.tv/tag/raspberry-pi-monitoring-its-own-battery-voltage also check this question http://raspberrypi.stackexchange.com/questions/7414/is-it-possible-to-detect-input-voltage-using-only-software – Steve Robillard Sep 05 '15 at 04: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. – Mohammad Ali May 28 '16 at 03:05
  • @MohammadAli They certainly can, but it does of course depend on the battery OP is using. – Dan Jun 27 '16 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 – Mohammad Ali Jun 27 '16 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 Jun 27 '16 at 19:12

2 Answers2

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.

flakeshake
  • 6,235
  • 1
  • 14
  • 33
  • 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 Jul 27 '16 at 07: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 : https://www.raspberrypi.org/forums/viewtopic.php?t=82373 – flakeshake Jul 27 '16 at 07: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. – Dmitry Grigoryev Feb 07 '17 at 08: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?

Clóvis Fritzen
  • 373
  • 1
  • 11