Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Extending HT16K33 library for arrays of displays
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Extending HT16K33 library for arrays of displays

by tim11g on Sun Jul 26, 2020 4:44 pm

I'm using the CircuitPython libarary for the HT16K33 driving 14 segment LED displays.
A Raspberry Pi Zero W with Python3.7 provides the I2C.

I've got the basic configuration working and can use and address the 4 digit display.
My question is how to scale this up to a larger array. Each board is nicely designed to create an array of LED characters horizontally -- Suppose I want to array 3 backpacks for 12 characters.

From the hardware side, it's easy to set the I2C addresses on the backpacks with the A0-2 jumpers.
I can see from the code I would create the class for each by including the address:

Code: Select all | TOGGLE FULL SIZE
display0 = segments.Seg14x4(i2c, 0x70) 
display1 = segments.Seg14x4(i2c, 0x71) 
display2 = segments.Seg14x4(i2c, 0x72) 

But the methods in the class have the 4 digits hard-coded:
Code: Select all | TOGGLE FULL SIZE
        if not 0 <= index <= 3:


Rather than separately dealing with display0, display1, and display2 it seems like it would be cleaner to define a single display class that would support addressing display[0] through display[11], and hide the fact that the display is spread over 3 HT16K33 drivers at 3 I2C addresses.

Because the I2C address is set in the base class HT16K33, I'm not sure how I would structure a "Seg14xN" class that would support an arbitrary number of HT16K33 devices resulting in single logical display. Has anybody done this, or do you have any suggestions on the best way to proceed?

tim11g
 
Posts: 6
Joined: Sat Apr 08, 2017 1:23 pm

Re: Extending HT16K33 library for arrays of displays

by siddacious on Fri Aug 28, 2020 1:49 pm

I'm not aware of anything similar but some targeted searching will often turn up some projects that are close to what you're looking for. It seems very likely that someone has done something very close to what you're trying to do.

If you end up rolling your own, I agree that the general approach you suggest is the right way to go. I would have the constructor for your "Seg14xN" class take a base address and a number of displays and then create N instances of the base class, incrementing the I2C address passed in by 1 for each successive display. You'll need to keep these in a list or other collection that you use to access them when updating the displays.

You'll also need a way of storing the "big picture" that is to be displayed across the displays, and then write code to split it up into pieces according to the number of displays.

You seem to have a good intuition about how to proceed, so I'll offer these additional higher level tips. I apologize if I'm telling you things you already know:

Keep it simple - try to get a basic example working, perhaps where N=1 before continuing to something more complex; the smaller the changes, the easier they are to test. Starting with the whole thing at once is a good way to not know where to look when it's not working

Take small steps; similar to the above, don't add a ton of code at once. Find small achievable, testable, milestones along the way. This could be something as simple as verifying that you can create the correct number of display objects for the given number of displays.

Put your code in source control/git/whatever and USE IT. - Commits don't cost anything and they can save your but. I try to commit whenever I have a new thing working, however small, or when I've but in enough work that I'd not be happy to have to do it over again.


Were I in your shoes, I would probably write it myself even if I found something that did what I wanted, just for the challenge. I'm happy to answer any more questions or give suggestions as needed. If you get something working, I would be happy to review a PR for addition to the HT16K33 library.

Good luck! You can @ me as @siddacious on the adafruit discord (adafru.it/discord) or ask here if you have any questions

siddacious
 
Posts: 302
Joined: Fri Apr 21, 2017 3:09 pm

Re: Extending HT16K33 library for arrays of displays

by tim11g on Thu Sep 03, 2020 10:35 am

@siddacious, thank you for the reply. It's very helpful. I appreciate the tips - I've done lots of embedded programming, but Python is relatively new for me, and I'm still figuring out the object oriented nuances. This project is on pause now for other priorities, but I will eventually get back to it.

tim11g
 
Posts: 6
Joined: Sat Apr 08, 2017 1:23 pm

Please be positive and constructive with your questions and comments.