Introduction

Documentation Status Discord Build Status

This is a library for using the I²C-based LED matrices with the HT16K33 chip. It supports both 16x8 and 8x8 matrices, as well as 7- and 14-segment displays.

  • Notes

    1. This library is intended for Adafruit CircuitPython’s API. For a library compatible with MicroPython machine API see this library.
    2. This library does not work with the Trellis 4x4 LED+Keypad board. For that product use: CircuitPython Trellis Library

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-ht16k33

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-ht16k33

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-ht16k33

Usage Example

# Import all board pins and bus interface.
import board
import busio

# Import the HT16K33 LED matrix module.
from adafruit_ht16k33 import matrix

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the matrix class.
# This creates a 16x8 matrix:
matrix = matrix.Matrix16x8(i2c)
# Or this creates a 8x8 matrix:
#matrix = matrix.Matrix8x8(i2c)
# Or this creates a 8x8 bicolor matrix:
#matrix = matrix.Matrix8x8x2
# Finally you can optionally specify a custom I2C address of the HT16k33 like:
#matrix = matrix.Matrix16x8(i2c, address=0x70)

# Clear the matrix.
matrix.fill(0)

# Set a pixel in the origin 0,0 position.
matrix[0, 0] = 1
# Set a pixel in the middle 8, 4 position.
matrix[8, 4] = 1
# Set a pixel in the opposite 15, 7 position.
matrix[15, 7] = 1
matrix.show()

# Change the brightness
matrix.brightness = 8

# Set the blink rate
matrix.blink_rate = 2

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation

For information on building library documentation, please check out this guide.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/ht16k33_matrix_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Basic example of clearing and drawing a pixel on a LED matrix display.
# This example and library is meant to work with Adafruit CircuitPython API.
# Author: Tony DiCola
# License: Public Domain

# Import all board pins.
import board
import busio

# Import the HT16K33 LED matrix module.
from adafruit_ht16k33 import matrix


# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the matrix class.
# This creates a 16x8 matrix:
matrix = matrix.Matrix16x8(i2c)
# Or this creates a 8x8 matrix:
#matrix = matrix.Matrix8x8(i2c)
# Or this creates a 8x8 bicolor matrix:
#matrix = matrix.Matrix8x8x2(i2c)
# Finally you can optionally specify a custom I2C address of the HT16k33 like:
#matrix = matrix.Matrix16x8(i2c, address=0x70)

# Clear the matrix.
matrix.fill(0)

# Set a pixel in the origin 0,0 position.
matrix[0, 0] = 1
# Set a pixel in the middle 8, 4 position.
matrix[8, 4] = 1
# Set a pixel in the opposite 15, 7 position.
matrix[15, 7] = 1
examples/ht16k33_segments_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Basic example of setting digits on a LED segment display.
# This example and library is meant to work with Adafruit CircuitPython API.
# Author: Tony DiCola
# License: Public Domain

import time

# Import all board pins.
import board
import busio

# Import the HT16K33 LED segment module.
from adafruit_ht16k33 import segments

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the LED segment class.
# This creates a 7 segment 4 character display:
display = segments.Seg7x4(i2c)
# Or this creates a 14 segment alphanumeric 4 character display:
#display = segments.Seg14x4(i2c)
# Finally you can optionally specify a custom I2C address of the HT16k33 like:
#display = segments.Seg7x4(i2c, address=0x70)

# Clear the display.
display.fill(0)

# Can just print a number
display.print(42)
time.sleep(2)

# Or, can set indivdual digits / characters
# Set the first character to '1':
display[0] = '1'
# Set the second character to '2':
display[1] = '2'
# Set the third character to 'A':
display[2] = 'A'
# Set the forth character to 'B':
display[3] = 'B'
time.sleep(2)

# Or, can even set the segments to make up characters
if isinstance(display, segments.Seg7x4):
    # 7-segment raw digits
    display.set_digit_raw(0, 0xFF)
    display.set_digit_raw(1, 0b11111111)
    display.set_digit_raw(2, 0x79)
    display.set_digit_raw(3, 0b01111001)
else:
    # 14-segment raw digits
    display.set_digit_raw(0, 0x3F2D)
    display.set_digit_raw(1, 0b0011111100101101)
    display.set_digit_raw(2, (0b00111111, 0b00101101))
    display.set_digit_raw(3, [0b00111111, 0b00101101])
examples/ht16k33_bicolor24_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Basic example of using the Bi-color 24 segment bargraph display.
# This example and library is meant to work with Adafruit CircuitPython API.
# Author: Carter Nelson
# License: Public Domain

import time

# Import board related modules
import board
import busio

# Import the Bicolor24 driver from the HT16K33 module
from adafruit_ht16k33.bargraph import Bicolor24

# Create the I2C interface
i2c = busio.I2C(board.SCL, board.SDA)

# Create the LED bargraph class.
bc24 = Bicolor24(i2c)

# Set individual segments of bargraph
bc24[0] = bc24.LED_RED
bc24[1] = bc24.LED_GREEN
bc24[2] = bc24.LED_YELLOW

time.sleep(2)

# Turn them all off
bc24.fill(bc24.LED_OFF)

# Turn them on in a loop
for i in range(24):
    bc24[i] = bc24.LED_RED
    time.sleep(0.1)
    bc24[i] = bc24.LED_OFF

time.sleep(1)

# Fill the entrire bargraph
bc24.fill(bc24.LED_GREEN)

adafruit_ht16k33.ht16k33

  • Authors: Radomir Dopieralski & Tony DiCola for Adafruit Industries
class adafruit_ht16k33.ht16k33.HT16K33(i2c, address=112, auto_write=True)[source]

The base class for all displays. Contains common methods.

Parameters:
  • address (int) – The I2C addess of the HT16K33.
  • auto_write (bool) – True if the display should immediately change when set. If False, show must be called explicitly.
auto_write

Auto write updates to the display.

The blink rate. Range 0-3.

brightness

The brightness. Range 0-15.

fill(color)[source]

Fill the whole display with the given color.

show()[source]

Refresh the display and show the changes.

Matrix Displays

class adafruit_ht16k33.matrix.Matrix16x8(i2c, address=112, auto_write=True)[source]

A double matrix or the matrix wing.

pixel(x, y, color=None)[source]

Get or set the color of a given pixel.

class adafruit_ht16k33.matrix.Matrix8x8(i2c, address=112, auto_write=True)[source]

A single matrix.

pixel(x, y, color=None)[source]

Get or set the color of a given pixel.

class adafruit_ht16k33.matrix.Matrix8x8x2(i2c, address=112, auto_write=True)[source]

A bi-color matrix.

fill(color)[source]

Fill the whole display with the given color.

pixel(x, y, color=None)[source]

Get or set the color of a given pixel.

Segment Displays

class adafruit_ht16k33.segments.BigSeg7x4(i2c, address=112, auto_write=True)[source]

Numeric 7-segment display. It has the same methods as the alphanumeric display, but only supports displaying a limited set of characters.

ampm

The AM/PM indicator.

bottom_left_dot

The bottom-left dot indicator.

top_left_dot

The top-left dot indicator.

class adafruit_ht16k33.segments.Colon(disp, num_of_colons=1)[source]

Helper class for controlling the colons. Not intended for direct use.

class adafruit_ht16k33.segments.Seg14x4(i2c, address=112, auto_write=True)[source]

Alpha-numeric, 14-segment display.

print(value)[source]

Print the value to the display.

scroll(count=1)[source]

Scroll the display by specified number of places.

set_digit_raw(index, bitmask)[source]

Set digit at position to raw bitmask value. Position should be a value of 0 to 3 with 0 being the left most character on the display.

bitmask should be 2 bytes such as: 0xFFFF If can be passed as an integer, list, or tuple

class adafruit_ht16k33.segments.Seg7x4(i2c, address=112, auto_write=True)[source]

Numeric 7-segment display. It has the same methods as the alphanumeric display, but only supports displaying a limited set of characters.

scroll(count=1)[source]

Scroll the display by specified number of places.

set_digit_raw(index, bitmask)[source]

Set digit at position to raw bitmask value. Position should be a value of 0 to 3 with 0 being the left most digit on the display.

Indices and tables