Adapt Scroll pHAT HD library to 16x9 matrix


#1

Hi Pimoroni community!

I am trying to run a 16x9 led matrix driven by an IS31FL3731 (matrix and driver both by Adafruit and bought from Pimoroni). Since it is the same driver as in the Scroll pHAT HD I figured it should be easy to use the library provided on github (links to the one I used below) and fiddle around to accomodate for the slightly larger matrix. There seems to be more to be changed.
Just adapting width and height (in init.py and is31fl3731.py) leaves me with a nicely flashing matrix (e.g. using the swirl example provided with the library) that seems to fall apart between the first 72 leds addressed by the driver and the second half (changing directions). Any ideas what to look for in the library or if there are differences in the wiring between the pHAT and the Adafruit matrix would be highly appreciated.

I suspect the class definition and address transformation taking place there to be in the center of the issue. But I struggle to comprehend what is done there and how to adapt for the different matrix size.

class ScrollPhatHD(Matrix):
width = 17
height = 7

def _pixel_addr(self, x, y):
    if x > 8:
        x = x - 8
        y = 6 - (y + 8)
    else:
        x = 8 - x

    return x * 16 + y

#2

Might be worth starting with:

def _pixel_addr(self, x, y):
    return x * 16 + y

Note: this translates the X/Y coordinates of a given pixel into just a single index. The driver IC doesn’t have any concept of X/Y and just addresses a single continuous string of 144 LEDs.


#3

Thank you very much! Your remark of rather thinking in 144 continuous LEDs will be useful when going further with my project. I want to build an alarm clock, using four of the 16x9 matrices.

In the mean time I figured out how to enjoy all the benefits of your library with the adafruit matrices. Turns out I was thinking far too complicated. Three minor changes did the trick. In the original init file:

DISPLAY_HEIGHT = 7
DISPLAY_WIDTH = 17

Change to:

DISPLAY_HEIGHT = 16
DISPLAY_WIDTH = 9

In the original is31fl3731 file:

class Matrix:
    _width = 17
    _height = 7

Change to:

class Matrix:
    _width = 9
    _height = 16

And at the end of the original is31fl3731 file:

class ScrollPhatHD(Matrix):
    width = 17
    height = 7

Change to:

class ScrollPhatHD(Matrix):
    width = 9
    height = 16

To address my displays and how the hardware is oriented I use this options:

scrollphathd.rotate(270)
scrollphathd.flip(0,1)

Works fine for me. Nothing spectacular but I did not find any other comprehensive answer for this specific question. Of course there might be a more elegant way, there always is. Next step: Figure out how to display time and other messages on all four matrices.