Introduction

Documentation Status Discord

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.

Usage Example

# Import all board pins.
from board import *
import busio

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

# Create the I2C interface.
i2c = busio.I2C(SCL, 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.  Always call show after changing pixels to make the display
# update visible!
matrix.fill(0)
matrix.show()

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

Contributing

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

Building locally

To build this library locally you’ll need to install the circuitpython-build-tools package.

python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools

Once installed, make sure you are in the virtual environment:

source .env/bin/activate

Then run the build:

circuitpython-build-bundles --filename_prefix adafruit-circuitpython-ht16k33 --library_location .

Sphinx documentation

Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):

python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme

Now, once you have the virtual environment activated:

cd docs
sphinx-build -E -W -b html . _build/html

This will output the documentation to docs/_build/html. Open the index.html in your browser to view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to locally verify it will pass.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/matrix.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
# 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.
from board import *
import busio

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


# Create the I2C interface.
i2c = busio.I2C(SCL, 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.  Always call show after changing pixels to make the display
# update visible!
matrix.fill(0)
matrix.show()

# Set a pixel in the origin 0,0 position.
matrix.pixel(0, 0, 1)
# Set a pixel in the middle 8, 4 position.
matrix.pixel(8, 4, 1)
# Set a pixel in the opposite 15, 7 position.
matrix.pixel(15, 7, 1)
matrix.show()
examples/segments.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
# 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 all board pins.
from board import *
import busio

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


# Create the I2C interface.
i2c = busio.I2C(SCL, 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.  Always call show after changing the display to make the
# update visible!
display.fill(0)
display.show()

# Set the first character to '1':
display.put('1', 0)
# Set the second character to '2':
display.put('2', 1)
# Set the third character to 'A':
display.put('A', 2)
# Set the forth character to 'B':
display.put('B', 3)
# Make sure to call show to see the changes above on the display!
display.show()

adafruit_ht16k33.ht16k33

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

The base class for all displays. Contains common methods.

The blink rate. Range 0-3.

brightness(brightness)[source]

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)[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)[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)[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.Seg14x4(i2c, address=112)[source]

Alpha-numeric, 14-segment display.

hex(number)[source]

Display the specified hexadecimal number.

number(number)[source]

Display the specified decimal number.

push(char)[source]

Scroll the display and add a character at the end.

put(char, index=0)[source]

Put a character at the specified place.

scroll(count=1)[source]

Scroll the display by specified number of places.

text(text)[source]

Display the specified text.

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

Numeric 7-segment display. It has the same methods as the alphanumeric display, but only supports displaying decimal and hex digits, period and a minus sign.

push(char)[source]

Scroll the display and add a character at the end.

put(char, index=0)[source]

Put a character at the specified place.

scroll(count=1)[source]

Scroll the display by specified number of places.

Indices and tables