HT16K33SegmentBig

This is a hardware driver for the Adafruit 1.2-inch 4-digit, 7-segment LED display, which is based on the Holtek HT16K33 controller. The driver communicates using I²C.

'Adafruit 1.2-inch 4-digit, 7-segment LED. Image copyright Adafruit'

Adafruit 1.2-inch 4-digit, 7-segment LED. Image © Adafruit

Caution

This display requires a 5V input in addition to the IO driver voltage (3V3 or 5V). Please check that your MCU board can deliver this.

Compatibility

HT16K33SegmentBig is compatible with MicroPython and CircuitPython.

Importing the Driver

The driver comprises a parent generic HT16K33 driver and a child driver for the 7-segment display itself. All your code needs to do is import the latter:

from ht16k33segmentbig import HT16K33SegmentBig

You can then instantiate the driver.

You will need both the display driver file and ht16k33.py in your project folder.

Characters

The class incorporates its own (limited) character set, accessed through the following codes:

  • Digits 0 through 9: codes 0 through 9.

  • Characters A through F: codes 10 through 15.

  • Space character: code 16.

  • Minus character: code 17.

  • Degree character: code 18.

Display Digits

The display’s digits are numbered 0 to 3, from left to right.

Method Chaining

Most methods return a reference to the driver instance (self) to allow method chaining with dot syntax:

led.clear().set_number(4, 0).set_number(3, 1).draw()

Class Constructor

class HT16K33SegmentBig(i2C_bus, i2c_address=0x70)

To instantiate a HT16K33SegmentBig pass the I²C bus to which the display is connected and, optionally, its I²C address if you have changed the display’s address using the solder pads on rear of the LED’s circuit board.

The passed IC bus must be configured before the HT16K33SegmentBig object is created.

Parameters:
  • i2c_bus (I²C bus object) – The I²C bus to which the display is connected.

  • i2c_address (Integer) – An optional I²C address. Default: 0x70.

Examples

# MicroPython
from ht16k33segmentbig import HT16K33SegmentBig
from machine import I2C

# Update the pin values for your board
DEVICE_I2C_SCL_PIN = 5
DEVICE_I2C_SDA_PIN = 4

i2c = I2C(scl=Pin(DEVICE_I2C_SCL_PIN), sda=Pin(DEVICE_I2C_SDA_PIN))
led = HT16K33SegmentBig(i2c)
# CircuitPython
from ht16k33segmentbig import HT16K33SegmentBig
import busio
import board

i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
    pass
led = HT16K33SegmentBig(i2c)

Class Methods

HT16K33SegmentBig.set_brightness(brightness=15)

Set the LED’s brightness (its duty cycle). If you don’t pass a value, the method will default to maximum brightness.

Parameters:

brightness (Integer) – An optional brightness value between 0 (dim) and 15 (maximum brightness). Default: 15.

Example

# Turn down the display brightness
led.set_brightness(1)

This method can be used to flash the display.

The value passed into rate is the flash rate in Hertz. This value must be one of the following values, fixed by the HT16K33 controller: 0.5Hz, 1Hz or 2Hz. You can also pass in 0 to disable flashing, and this is the default value.

Parameters:

rate (Integer/Float) – The flash rate in Hertz. Default: 0.

Example

# Blink the display every second
led.set_blink_rate(1)
HT16K33SegmentBig.set_colon(pattern)

Call this method to specify whether the display’s center and left-side colon symbols and upper point (between digits 2 and 3) are illuminated. Pass in an integer bit patten which determines which symbols are lit:

  • 0x02 — centre colon

  • 0x04 — left colon, lower dot

  • 0x08 — left colon, upper dot

  • 0x10 — decimal point (upper)

Parameters:

pattern (Integer bitfield) – The elements to light

Returns:

The instance (self).

Example

# Set the centre : and the left :
pattern = 0x02 | 0x04 | 0x08
led.set_colon(pattern).draw()
HT16K33SegmentBig.set_glyph(glyph, digit=0)

Write a character that is not in the character set — see Characters, above — to a specified digit.

Calculate the glyph pattern value using the following chart. The segment number is the bit that must be set to illuminate it (or unset to keep it unlit):

    0
    _
5 |   | 1
  |   |
    - <----- 6
4 |   | 2
  | _ |
    3

For example, to define the letter P, we need to set segments 0, 1, 4, 5 and 6. In bit form that makes 0x73, and this is the value passed into glyph.

Parameters:
  • glyph (Integer) – A glyph-definition pattern.

  • digit (Integer) – The digit to show the number. Default: 0.

Returns:

The instance (self).

Example

# Display 'SYNC' on the LED
letters = 0x6D, 0x6E, 0x37, 0x39
for index in range(0, len(letters)):
    led.set_glyph(letters[index], index)
led.draw()
HT16K33SegmentBig.set_number(number, digit=0)

Write a decimal or hexadecimal number to a single digit.

Parameters:
  • number (Integer) – The number to display.

  • digit (Integer) – The digit to show the number. Default: 0.

Returns:

The instance (self).

Example

# Display '42.42' on the LED
led.set_number(4, 0).set_number(2, 1, True)
led.set_number(4, 2).set_number(2, 3).draw()
HT16K33SegmentBig.set_character(character, digit=0)

To write a character from the display’s hexadecimal character set to a single digit, call set_character() and pass the the letter to be displayed ("0" to "9", "A" to "F", "-" or " ") and the digit number (0, 1, 2 or 3, left to right) as its parameters. You can pass the string "deg" for a degree symbol.

If you need other letters or symbols, these can be generated using set_glyph().

Parameters:
  • character (String) – The alphanumeric character to display.

  • digit (Integer) – The digit to show the number. Default: 0.

Returns:

The instance (self).

Example

# Display 'bEEF' on the LED
led.set_char("b", 0).set_char("e", 1)
led.set_char("e", 2).set_char("f", 3).draw()
HT16K33SegmentBig.clear()

Wipe the class’ internal display buffer.

clear() does not update the display, only the buffer. Call draw() to refresh the LED.

Returns:

The instance (self).

Example

# Clear the display
led.clear().draw()
HT16K33SegmentBig.draw()

Call draw() after changing any or all of the internal display buffer contents in order to reflect those changes on the display itself.