Skip to main content

RPi Mini Battery Display

Continous Integration PyPI package version Python versions GitHub license

Library and command-line program to control 10-segment mini battery displays based on the TM1651 chip, such as the ones from Open-Smart, on a Raspberry Pi.

System requirements

The rpi-mini-battery-display library is written to run on a Raspberry Pi. It has been tested on Raspbian Buster (10) with Python 3.7.

If you don't have pip, install it first with:

sudo apt install python3-pip

This library uses the RPi.GPIO library to communicate with the TM1651 chip. The default user pi in Raspbian has already the right permissions for GPIO access. If you want to use the library as another user, the user needs to be in the gpio group to have the right permissions. This can be done with:

sudo adduser $USER gpio

Installation

sudo pip3 install rpi-mini-battery-display

Connections

The mini battery display should be connected like this to the Raspberry Pi's GPIO header:

Mini Battery Display Raspberry Pi
CLK BCM24
DIO BCM23
VCC 5 V
GND GND

See pinout.xyz for the Raspberry Pi GPIO pinout.

The CLK and DIO pin can be connected to other pins on the Raspberry Pi, but these are the default values used by the code. If you change the connections, you have to supply the other pin values as parameters to the software.

Usage

You can use the rpi-mini-battery-display program to set the level of the battery display from 0 to 7 or to let it show the CPU percentage as a level from 0 (less than 12.5%) to 7 (more than 87.5%):

usage: rpi-mini-battery-display [-h] [-c CLOCK_PIN] [-d DATA_PIN]
                                [-b BRIGHTNESS] (-l LEVEL | -p)

Control a 10 LED mini battery display with TM1651 chip

optional arguments:
  -h, --help            show this help message and exit
  -c CLOCK_PIN, --clock-pin CLOCK_PIN
                        Clock pin in BCM notation (default: 24, range: 0-27)
  -d DATA_PIN, --data-pin DATA_PIN
                        Data pin in BCM notation (default: 23, range: 0-27)
  -b BRIGHTNESS, --brightness BRIGHTNESS
                        Brightness (default: 2, range: 0-7)
  -l LEVEL, --level LEVEL
                        Set battery level (range: 0-7)
  -p, --processor       Show CPU percentage

Use cases

These displays are handy in every situation where you want to show a status on a Raspberry Pi on a low budget. For instance, I'm using them to show the CPU load of every Raspberry Pi in my six-node cluster:

Six displays

This was actually my motivation to develop the rpi-mini-battery-display library.

Changelog

  • 0.3.0 (2020-02-28): Refactored code from rather C++/Arduino-like to something more Pythonic
  • 0.2.0 (2020-01-27): Added option to show the CPU percentage
  • 0.1.0 (2020-01-26): Initial version

TODO

  • Individually address the LED segments instead of only using them as a LED bar (fairly trivial, I already played with it but haven't implemented the necessary method yet).
  • Add the possibility to switch the direction of the LED bar.
  • Add static typing with mypy.
  • Support other versions of the mini battery displays based on the TM1651 chip, for instance the 5-segment one.
  • Support other mini battery displays, such as the Grove LED Bar, which uses the MY9221 chip.

Developer notes

  • The TM1651 is one of a series of LED driver control chips by Titan Micro Electronics. Other popular similar chips of the same manufacturer are the TM1637 and TM1640.
  • English datasheet of the TM1651

License

This project is provided by Koen Vervloesem as open source software with the MIT license. See the LICENSE file for more information.

Release files for rpi-mini-battery-display 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rpi-mini-battery-display 0.3.0
File Size Uploaded
rpi-mini-battery-display-0.3.0.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rpi-mini-battery-display 0.3.0
File Interpreter ABI Platform
rpi_mini_battery_display-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / rpi-mini-battery-display-0.3.0.tar.gz

Download URL rpi-mini-battery-display-0.3.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
23ff6d086b4c951b63d7d5e5517fc794dc44126f79f351f72c1a7f0e03b18dcf
BLAKE2b-256 checksum
How to use checksums
6d2e54c688b00c0badf8f4800550167b54fd3470b1654ef116ce2fc890b3493f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release files / rpi_mini_battery_display-0.3.0-py3-none-any.whl

Download URL rpi_mini_battery_display-0.3.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29edcbb3eb64ff63524fd778723cfe83f316d3d518427c2b7015f4a71f9c1313
BLAKE2b-256 checksum
How to use checksums
6edc17cbeb671fe7e02c397190b15cae2b35b0d20c819be874bd7ef22795e5c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page