Git Product home page Git Product logo

ht16k33-python's Introduction

HT16K33 Drivers 4.0.0

This repo provides Python drivers for the Holtek HT16K33 controller chip and various display devices based upon it, such as the Adafruit 0.8-inch 8x16 LED Matrix FeatherWing and the SparkFun Qwiic Alphanumeric Display.

The drivers support both CircuitPython and MicroPython applications. They communicate using I²C.

The library also supports generic seven-segment displays wired up to an HT16K33, which can drive up to eight these LEDs. The HT16K33 may be on a board of your own design, or on a third-party one, such as the Adafruit 16x8 LED Matrix Driver Backpack . LED units you can connect range from single digits up to combinations of multi-digit units.

Connect your HT16K33 column pins to each LED's digit selection pin, and its row pins to the LED's segment selection pins.

Display Drivers

Driver
(Click for docs)
Example Product
Small 4-digit, 7-segment LED  Adafruit 0.56-inch 4-digit, 7-segment LED display
Large 4-digit, 7-segment LED  Adafruit 1.2-inch 4-digit, 7-segment LED display
Small 4-digit, 14-segment LED SparkFun Qwiic Alphanumeric Display,
Adafruit 0.54in Alphanumeric Display
8x8 monochrome matrix LED  Adafruit Mini 0.8-inch 8x8 LED Matrix
8x8 bi-colour matrix LED Adafruit 1.2-inch 8x8 bi-color LED matrix backpack
16x8 FeatherWing matrix LED Adafruit 0.8-inch 8x16 LED Matrix FeatherWing
Standalone HT16K33 Adafruit 16x8 LED Matrix Driver Backpack

Further drivers may be added in due course.

Import the Drivers

The driver package comprises a parent generic HT16K33 class and child classes for various displays themselves. All your code needs to do is import the latter. For example:

from ht16k33 import HT16K33Segment

You can then instantiate the driver object. This requires a configured I2C bus object.

You will need at least one display driver file, eg. ht16k33segmentgen.py and ht16k33.py in your project folder.

Install the Drivers

MicroPython Manual Install

Use the pyboard or mpremote command line tools to copy the ht16k33 directory to your board's lib directory.

MicroPython MIP Install

You can install the drivers using MicroPython's MIP system. This requires a board running MicroPython 1.20 or above and connected to the Internet. Add the following to your code:

import mip
mip.install('github:smittytone/HT16K33-Python')

If your board is not Internet-capable, you can install locally using the mpremote tool:

mpremote mip install github:smittytone/HT16K33-Python

Install Script

Alternatively, use our convenient installer script:

./tools/mpinstall.sh

To install pre-compiled versions of the library files, run:

./tools/mpinstall.sh mpy

This requires MicroPython's mpy-cross tool installed on your computer.

CircuitPython Manual Install

Copy ht16k33 directory to the mounted board's lib folder.

Reducing Memory Usage

Adding the driver code may prove too much for certain CircuitPython devices which have limited amounts of memory. To overcome this, use MicroPython’s mpy-cross compiler. This will compile the raw Python into a highly compact form as a .mpy file. Copy ht16k33.mpy and the device-specific .mpy file to your device in place of the .py versions.

For MicroPython boards, I recommend you use the mpinstall.sh script to compile and install .mpy versions if the library files all in one go.

Documentation

You can find documentation for all of the drivers at smittytone.net.

Python Package Index

This code is now available via the Python Package Index for folks using Thonny and other code-pulling IDEs.

Release Notes

  • 4.0.0 8 May 2024
    • Completely reorganise the library files into their own directory.
    • Add device installation script for MicroPython users - thanks, @ubidefeo.
    • Add HT16K33SegmentGen CircuitPython examples.
    • Use Raspberry Pi Pico for all examples.
  • 3.5.3 15 January 2024
    • Remove the .mpy versions and provide instructions instead.
    • Fix incorrect selection of blink rate 0.5Hz — thanks, @Karrp.
  • 3.5.2 11 December 2023
    • Add mip support — thanks, @ubidefeo (no code changes).
  • 3.5.1 30 October 2023
    • Add provisional PyPI support (no code changes).
  • 3.5.0 2 September 2023
    • Add HT16K33SegmentGen a generic, 1-8 digit 7-segment driver — thanks, @vader7071.
  • 3.4.2 14 February 2023
    • Fix an error when a space is shown as a zero — thanks, @asasine.
  • 3.4.1 14 November 2022
    • Correct VK16K33 naming.
    • Fix VK16K33 colon setting and unsetting — thanks, Dietmar Schüller.
  • 3.4.0 6 October 2022
  • 3.3.1 13 September 2022
    • 14-segment character-set numerals now match 7-segment equivalents.
    • Assorted code tweaks.
    • Wrangle and extend examples.
    • Remove old docs.
    • Big thanks to @akbiocca for assistance with this release.
  • 3.3.0 5 August 2022
    • Add rotate() method to HT16K33Segment.
  • 3.2.0 26 July 2022
  • 3.1.0 16 February 2022
  • 3.0.2 23 November 2020
    • Refactor out some ht16k33matrix.py code.
  • 3.0.1 7 November 2020
    • Correct variable name in ht16k33matrix.py.
  • 3.0.0 6 November 2020
    • Initial public release.

Licence and Copyright

This repository’s source code and documentation is copyright © 2024, Tony Smith (@smittytone).

The HTK16K33 driver and subsidiary display drivers are licensed under the MIT License.

ht16k33-python's People

Contributors

akbiocca avatar electricimpsamplecode avatar smittytone avatar ubidefeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ht16k33-python's Issues

Problem connecting Bi-color matrix to Pi Pico ...

Hi. Thanks for putting this together. I'm trying to get this running in MicroPython (latest build) for use on an older Adafruit Bi-color 8x8 matrix with a Pico W and I'm getting errors. I've used CircuitPython to test the matrix and it works fine. I copied the code and created the 2 libraries and saved those to my \lib folder on the Pico. Trying to get your example.py program to run using your i2c line (scl=Pin(9)) but get this set of errors :

Traceback (most recent call last):
File " ", line 18, in
File "/lib/ht16k33matrixcolour.py", line 135, in _init
File "/lib/ht16k33.py", line 36, in _init
File "/lib/ht16k33.py", line 95, in power_on
File "/lib/ht16k33.py", line 120, in write_cmd
OSError: [Errno 5] EIO

Appreciate any guidance. Thanks.

HT16K33 Python Drivers

I recently downloaded and am happily making use of your Python drivers for the Sparkfun 4 digit 14 segment displays but noticed that it does not presently support the centre colon illumination. (led.set_colon().draw()) does not function. Is this something that will be rectified in the future?

Blink rate at 0.5 Hz is impossible to obtain.

'''
>>> display.set_blink_rate(0.5)
Traceback (most recent call last):
File "", line 1, in
File "/lib/ht16k33.py", line 49, in set_blink_rate
TypeError: unsupported types for and: 'float', 'int'
'''

Mutliple devices and 'rotate()'

I think I saw that there is a scheme for connecting multiple devices together in an array, for example to display 8 character on 7-seg. Is the 'rotate()' setting on each display, or on the whole array (together as one)?

The reason I'm asking is that 1.2inch display is NOT rotational symmetrical:
https://smittytone.net/docs/ht16k33_segmentbig.html

And for my project (https://github.com/mungewell/pico-timecode) I am considering using these for a 'Digi-Slate'. One thing that is done is 'tail slating', where the slate is 'clapped' at the end of a segment - to signify this the slate is inverted....

Most of the time the TimeCode will contain characters which would define which way up the 'display' is, for example no question with "13:13:13:13" but others are ambiguous (ie "2", "5", "6" and "9"s). If I was to place the two display with the two 'joining colons' together, I could light one or the other to signify which way the display is the the :SS:FF value (vs HH:MM ).

Just a thought, and you're welcome to say "won't implement". Thank you for the library anyhow.

Rotation support

Would it be possible to add support for 180 degree rotation (defined at object instantiation)

PyPi entry/adding from Thonny IDE

Package manager in Thonny does not show the package in search results making it more difficult for beginners to use/discover.
obrázok

Would it be possible to upload it to pypi in order to resolve this?

8 digit 7 segment display?

I was looking through the code for the 7 segment portion. I noticed that the library is setup for a 4 digit display with a colon. Is there a version that will allow the use of (8) 7-segment displays with no colon? I want to use the HT16K33 to be able to drive (8) 7-segs to be able to display a value of 0-99,999,999 (ignore the commas).

HT16K33Segment - writing space draws a 0

Bug

Writing a space to the segment using led.set_character(" ") displays 0 in the first digit.

Example code

display = HT16K33Segment(I2C(0, sda=Pin(16), scl=Pin(17)))
display.clear().draw()
for digit in range(4):
    display.set_character(" ", digit)

display.draw()

Investigation

I believe this bug is due to the " " using the HT16K33_SEGMENT_SPACE_CHAR value 0x00 for char_val in set_character

char_val = self.HT16K33_SEGMENT_SPACE_CHAR

which is then used as an index into CHARSET

self.buffer[self.POS[digit]] = self.CHARSET[char_val]

whose first value (index 0x00) is 0x3F, representing the 0 character (LED segments 0-5)

CHARSET = b'\x3F\x06\x5B\x4F\x66\x6D\x7D\x07\x7F\x6F\x5F\x7C\x58\x5E\x7B\x71\x40\x63'

Possible solution

I think a new value, \x00, needs to be added to CHARSET, and HT16K33_SEGMENT_SPACE_CHAR needs to change to 0x12. I'd be happy to make a PR if this solution seems good to you.

Support for Cpython/etc in linux eg. Rpi boards/etc

I have been developing a project using an ARM board similar to a Raspberry Pi (in fact, it's an Orange pi!!) but there are few (if any) usable libraries for interfacing to the ht16k33 in C-Python (or similar). Whilst the adafruit libraries and ecosystem are comprehensive, they're a bit heavyweight, and not very portable outside of their supported hardware.

Is this something you would be able to consider? It would be great to see similar functions to those exposed by eg. the Arduino library, for writing numbers directly to displays such as the 7-seg. clock, but it's possible I could port some of those myself if desired (they look pretty trivial even in C!) and potentially PR them.

incompatible .mpy file error

Hi,

Trying to use your library on pico pi micropython:
MicroPython v1.21.0, picow v1.21.0 on 2023-10-06; Raspberry Pi Pico W with RP2040
via .mpy files (the installation via mip failed - OSError -6) but upon running example code I'm getting the error:

Traceback (most recent call last): File "<stdin>", line 4, in <module> ValueError: incompatible .mpy file

The .mpy files are where they should be I guess (using MicroPico VS Code extension):
Screenshot 2024-01-03 at 15 02 17

Any clues of what might be the problem here ?
Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.