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 BigSeg7x4.

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 display, you just pass i2c in.

import board
from adafruit_ht16k33.segments import BigSeg7x4

i2c = board.I2C()
display = BigSeg7x4(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:

display = BigSeg7x4(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

Printing Text

To print text to the display, you just use the print function. For the 7-segment display, valid characters are 0-9, letters A-F, and a hyphen. So if we want to print ABCD, we would use the following:

display.print("ABCD")

Printing Numbers

Printing numbers is done similar to printing text, except without the quotes, though you can still print numbers in a string as well.

display.print(1234)

Printing Hexidecimal Values

To print hexidecimal values, you use the print_hex function:

display.print_hex(0x1A2B)

Setting Individual Characters

To set individual characters, you simply treat the display object as a list and set it to the value that you would like.

display[0] = '1'
display[1] = '2'
display[2] = 'A'
display[3] = 'B'

Setting Individual Segments

To set individual segments to turn on or off, you would use the set_digit_raw function to pass the digit that you want to change and the bitmask. This can be really useful for creating your own characters. The bitmask corresponds to the following diagram. The highest bit is not used, so an X represents that spot to indicate that.

The bitmask is a single 8-bit number that can be passed in as a single Hexidecimal, Decimal, or binary number. This will use a couple different methods to display 8E8E:

display.set_digit_raw(0, 0xFF)
display.set_digit_raw(1, 0b11111111)
display.set_digit_raw(2, 0x79)
display.set_digit_raw(3, 0b01111001)

Filling all Segments

To fill the entire display, just use the fill() function and pass in either 0 or 1 depending on whether you want all segments off or on. For instance, if you wanted to set everything to on, you would use:

display.fill(1)

Scrolling Display Manually

If you want to scroll the displayed data to the left, you can use the scroll() function. You can pass in the number of places that you want to scroll. The right-most digit will remain unchanged and you will need to set that manually. After scrolling, you will need to call the show function. For example if you wanted to print an A and then scroll it over to spaces, you would do the following.

display.print("A")
display.scroll(2)
display[3] = " "
display.show()

Displaying the Colon

There are a couple of different ways to display a colon on the 7-segment display. The first and easiest way is to use the print function:

display.print("12:30")

The other way to control it is to access the colon with the colons property and set index 0 to True or False:

display.colons[0] = False

Setting the Left-Side Dots

There are a couple of different ways to set the left-side dots on the large 7-segment display. The first way is to use the colons property like above:

display.colons[1] = False

If you would like to set the dots individually, you can do that using the top_left_dot and bottom_left_dot properties and set them to True or False:

display.top_left_dot = True
display.bottom_left_dot = True

Setting the AM/PM Indicator

If you would like to set the upper-right dot, you can do this using the ampm property:

display.ampm = True

Displaying an Automatic Scrolling Marquee

To make displaying long text easier, we've added a marquee function. You just pass it the full string. Optionally, you can pass it the amount of delay between each character. This may be useful for displaying a phone number, words using only letters A-F, or other numeric data:

display.marquee('Deadbeef ')

By default it is 0.25 seconds, but you can change this by providing a second parameter. You can optionally pass False for a third parameter if you would not like to have it loop. So if you wanted each character to display for half a second and didn't want it to loop, you would use the following:

display.marquee('Deadbeef', 0.5, False)

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 27, 2020.

Text editor powered by tinymce.