Skip to content

Commit 83a4eab

Browse files
authored
Merge pull request #59 from makermelissa/master
Add support for multiple rows of panels
2 parents 885fb7e + 6290e0c commit 83a4eab

File tree

3 files changed

+86
-26
lines changed

3 files changed

+86
-26
lines changed

adafruit_matrixportal/graphics.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ class Graphics(GraphicsBase):
3838
3939
:param default_bg: The path to your default background image file or a hex color.
4040
Defaults to 0x000000.
41-
:param int width: The width of the display in Pixels. Defaults to 64.
42-
:param int height: The height of the display in Pixels. Defaults to 32.
41+
:param int width: The total width of the display(s) in Pixels. Defaults to 64.
42+
:param int height: The total height of the display(s) in Pixels. Defaults to 32.
4343
:param int bit_depth: The number of bits per color channel. Defaults to 2.
4444
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
4545
:param string color_order: A string containing the letter "R", "G", and "B" in the
4646
order you want. Defaults to "RGB"
47+
:param bool Serpentine: Used when panels are arranged in a serpentine pattern rather
48+
than a Z-pattern. Defaults to True.
49+
:param int tiles_rows: Used to indicate the number of rows the panels are arranged in.
50+
Defaults to 1.
4751
:param debug: Turn on debug print outs. Defaults to False.
4852
4953
"""
@@ -58,6 +62,8 @@ def __init__(
5862
bit_depth=2,
5963
alt_addr_pins=None,
6064
color_order="RGB",
65+
serpentine=True,
66+
tile_rows=1,
6167
debug=False
6268
):
6369

@@ -67,6 +73,8 @@ def __init__(
6773
height=height,
6874
alt_addr_pins=alt_addr_pins,
6975
color_order=color_order,
76+
serpentine=serpentine,
77+
tile_rows=tile_rows,
7078
)
7179

7280
super().__init__(matrix.display, default_bg=default_bg, debug=debug)

adafruit_matrixportal/matrix.py

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,29 @@ class Matrix:
4747
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
4848
:param string color_order: A string containing the letter "R", "G", and "B" in the
4949
order you want. Defaults to "RGB"
50-
50+
:param int width: The total width of the display(s) in Pixels. Defaults to 64.
51+
:param int height: The total height of the display(s) in Pixels. Defaults to 32.
52+
:param bool Serpentine: Used when panels are arranged in a serpentine pattern rather
53+
than a Z-pattern. Defaults to True.
54+
:param int tiles_rows: Used to indicate the number of rows the panels are arranged in.
55+
Defaults to 1.
5156
"""
5257

53-
# pylint: disable=too-few-public-methods,too-many-branches
58+
# pylint: disable=too-few-public-methods,too-many-branches,too-many-statements,too-many-locals
5459
def __init__(
55-
self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None, color_order="RGB"
60+
self,
61+
*,
62+
width=64,
63+
height=32,
64+
bit_depth=2,
65+
alt_addr_pins=None,
66+
color_order="RGB",
67+
serpentine=True,
68+
tile_rows=1
5669
):
5770

71+
panel_height = height // tile_rows
72+
5873
if not isinstance(color_order, str):
5974
raise ValueError("color_index should be a string")
6075
color_order = color_order.lower()
@@ -67,9 +82,9 @@ def __init__(
6782
if "Matrix Portal M4" in os.uname().machine:
6883
# MatrixPortal M4 Board
6984
addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC]
70-
if height > 16:
85+
if panel_height > 16:
7186
addr_pins.append(board.MTX_ADDRD)
72-
if height > 32:
87+
if panel_height > 32:
7388
addr_pins.append(board.MTX_ADDRE)
7489
rgb_pins = [
7590
board.MTX_R1,
@@ -87,13 +102,13 @@ def __init__(
87102
if "nrf52" in os.uname().sysname:
88103
# nrf52840 Style Feather
89104
addr_pins = [board.D11, board.D5, board.D13]
90-
if height > 16:
105+
if panel_height > 16:
91106
addr_pins.append(board.D9)
92107
rgb_pins = [board.D6, board.A5, board.A1, board.A0, board.A4, board.D11]
93108
clock_pin = board.D12
94109
else:
95110
addr_pins = [board.A5, board.A4, board.A3]
96-
if height > 16:
111+
if panel_height > 16:
97112
addr_pins.append(board.A2)
98113
rgb_pins = [
99114
board.D6,
@@ -124,23 +139,50 @@ def __init__(
124139

125140
try:
126141
displayio.release_displays()
127-
matrix = rgbmatrix.RGBMatrix(
128-
width=width,
129-
height=height,
130-
bit_depth=bit_depth,
131-
rgb_pins=(
132-
rgb_pins[red_index],
133-
rgb_pins[green_index],
134-
rgb_pins[blue_index],
135-
rgb_pins[red_index + 3],
136-
rgb_pins[green_index + 3],
137-
rgb_pins[blue_index + 3],
138-
),
139-
addr_pins=addr_pins,
140-
clock_pin=clock_pin,
141-
latch_pin=latch_pin,
142-
output_enable_pin=oe_pin,
143-
)
142+
if tile_rows > 1:
143+
matrix = rgbmatrix.RGBMatrix(
144+
width=width,
145+
height=height,
146+
bit_depth=bit_depth,
147+
rgb_pins=(
148+
rgb_pins[red_index],
149+
rgb_pins[green_index],
150+
rgb_pins[blue_index],
151+
rgb_pins[red_index + 3],
152+
rgb_pins[green_index + 3],
153+
rgb_pins[blue_index + 3],
154+
),
155+
addr_pins=addr_pins,
156+
clock_pin=clock_pin,
157+
latch_pin=latch_pin,
158+
output_enable_pin=oe_pin,
159+
tile=tile_rows,
160+
serpentine=serpentine,
161+
)
162+
else:
163+
matrix = rgbmatrix.RGBMatrix(
164+
width=width,
165+
height=height,
166+
bit_depth=bit_depth,
167+
rgb_pins=(
168+
rgb_pins[red_index],
169+
rgb_pins[green_index],
170+
rgb_pins[blue_index],
171+
rgb_pins[red_index + 3],
172+
rgb_pins[green_index + 3],
173+
rgb_pins[blue_index + 3],
174+
),
175+
addr_pins=addr_pins,
176+
clock_pin=clock_pin,
177+
latch_pin=latch_pin,
178+
output_enable_pin=oe_pin,
179+
)
144180
self.display = framebufferio.FramebufferDisplay(matrix)
181+
except TypeError:
182+
if tile_rows > 1:
183+
raise RuntimeError(
184+
"Make sure you are running CircuitPython 6.2.0.alpha-1 or later"
185+
) from TypeError
186+
raise
145187
except ValueError:
146188
raise RuntimeError("Failed to initialize RGB Matrix") from ValueError

adafruit_matrixportal/matrixportal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class MatrixPortal(PortalBase):
6161
:param string color_order: A string containing the letter "R", "G", and "B" in the
6262
order you want. Defaults to "RGB"
6363
:param debug: Turn on debug print outs. Defaults to False.
64+
:param int width: The total width of the display(s) in Pixels. Defaults to 64.
65+
:param int height: The total height of the display(s) in Pixels. Defaults to 32.
66+
:param bool Serpentine: Used when panels are arranged in a serpentine pattern rather
67+
than a Z-pattern. Defaults to True.
68+
:param int tiles_rows: Used to indicate the number of rows the panels are arranged in.
69+
Defaults to 1.
6470
6571
"""
6672

@@ -83,6 +89,8 @@ def __init__(
8389
debug=False,
8490
width=64,
8591
height=32,
92+
serpentine=True,
93+
tile_rows=1,
8694
):
8795

8896
graphics = Graphics(
@@ -92,6 +100,8 @@ def __init__(
92100
height=height,
93101
alt_addr_pins=alt_addr_pins,
94102
color_order=color_order,
103+
serpentine=serpentine,
104+
tile_rows=tile_rows,
95105
debug=debug,
96106
)
97107

0 commit comments

Comments
 (0)