The following section will show how to control the LED backpack from the board's Python prompt / REPL.  You'll walk through how to control the LED display and learn how to use the CircuitPython module built for the display.

First connect to the board's serial REPL so you are at the CircuitPython >>> prompt.

Initialization

First you'll need to initialize the I2C bus for your board.  It's really easy, first import the necessary modules. In this case, we'll use board and BiColor24.

Then just use board.I2C() to create the I2C instance using the default SCL and SDA pins (which will be marked on the boards pins if using a Feather or similar Adafruit board).

Then to initialize the bargraph, you just pass i2c in.

import board
from adafruit_ht16k33.bargraph import Bicolor24

i2c = board.I2C()
bc24 = Bicolor24(i2c)

If you bridged the address pads on the back of the display, you could pass in the address. The addresses for the HT16K33 can range between 0x70 and 0x77 depending on which pads you have bridged, with 0x70 being used if you haven't bridged any of them. For instance, if you bridge only the a0 pad, you would use 0x71 like this:

bc24 = Bicolor24(i2c, address=0x71)

Setting the Brightness

You can set the brightness of the display, but changing it will set the brightness of the entire display and not individual segments. If can be adjusted in 1/16 increments between 0 and 1.0 with 1.0 being the brightest. So to set the display to half brightness, you would use the following:

display.brightness = 0.5

Setting the Blink Rate

You can set the blink rate of the display, but changing it will set the brightness of the entire display and not individual segments. If can be adjusted in 1/4 increments between 0 and 3 with 3 being the fastest blinking. So to set the display to blink at full speed, you would use the following:

display.blink_rate = 3

Setting Individual Bars

To set individual bars to specific colors, you simply treat the bc24 object as a list and set it to bc24.LED_RED, bc24.LED_GREEN, bc24.LED_YELLOW or bc24.LED_OFF.

bc24[0] = bc24.LED_RED
bc24[1] = bc24.LED_GREEN
bc24[2] = bc24.LED_YELLOW
bc24[3] = bc24.LED_OFF

Filling the Entire Bargraph

To fill the entire bargraph, just use the fill() function and pass in the color you want to set it to. For instance, if you wanted to set everything to green, you would use:

bc24.fill(bc24.LED_GREEN)

This guide was first published on Jul 29, 2012. It was last updated on Sep 28, 2022.

This page (CircuitPython and Python Usage) was last updated on Jan 13, 2020.

Text editor powered by tinymce.