Skip to content

add the cascaded matrix support #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
dabc765
update
bluejazzCHN Jan 7, 2021
25b0b36
Update README.rst
bluejazzCHN Jan 8, 2021
785481d
Update README.rst
bluejazzCHN Jan 8, 2021
886581d
Add function that display string on mult matrix
bluejazzCHN Jan 10, 2021
21a76f6
Merge branch 'master' of https://github.com/bluejazzCHN/Adafruit_Circ…
bluejazzCHN Jan 10, 2021
8e8807b
Delete settings.json
bluejazzCHN Jan 10, 2021
a63e02e
Update max7219_disaplay_string_multi_matrix.py
bluejazzCHN Jan 10, 2021
7562fbe
update functions to support the cascaded matrix.
bluejazzCHN Apr 5, 2021
2af5d94
demo in the cascaded matrix
bluejazzCHN Apr 5, 2021
93e5b3a
Update max7219_cascade.py
bluejazzCHN Apr 5, 2021
84ea72a
Update max7219_cascade.py
bluejazzCHN Apr 5, 2021
6dc7b99
Update max7219_cascade.py
bluejazzCHN Apr 5, 2021
816c5ac
Update max7219.py
bluejazzCHN Apr 5, 2021
2e2a62a
Update max7219.py
bluejazzCHN Apr 5, 2021
dd17d27
Update max7219.py
bluejazzCHN Apr 5, 2021
022855b
Update max7219.py
bluejazzCHN Apr 5, 2021
a1e3e4a
Update max7219.py
bluejazzCHN Apr 5, 2021
6a00817
Update max7219.py
bluejazzCHN Apr 5, 2021
44f0ced
Update max7219.py
bluejazzCHN Apr 6, 2021
91ed196
Update max7219_cascade.py
bluejazzCHN Apr 6, 2021
43d103b
Update max7219.py
bluejazzCHN Apr 6, 2021
47d9c90
Update max7219.py
bluejazzCHN Apr 6, 2021
bcbe413
Update max7219_cascade.py
bluejazzCHN Apr 6, 2021
76a8dbf
Update max7219_cascade.py
bluejazzCHN Apr 6, 2021
3fabbb8
Update max7219_cascade.py
bluejazzCHN Apr 6, 2021
ec499b4
Update max7219_cascade.py
bluejazzCHN Apr 6, 2021
227a384
Update max7219_cascade.py
bluejazzCHN Apr 6, 2021
ac117b1
Update max7219.py
bluejazzCHN Apr 6, 2021
18da08c
Update max7219.py
bluejazzCHN Apr 6, 2021
5d7d62a
Update max7219.py
bluejazzCHN Apr 10, 2021
50cbbd8
Add files via upload
bluejazzCHN Apr 10, 2021
d1e84ff
Add files via upload
bluejazzCHN Apr 10, 2021
f2d029e
Add files via upload
bluejazzCHN Apr 10, 2021
086edbb
Add files via upload
bluejazzCHN Apr 10, 2021
f071e0c
Add files via upload
bluejazzCHN Apr 12, 2021
edabb16
Update max7219.py
bluejazzCHN Apr 12, 2021
03f37cb
Update max7219.py
bluejazzCHN Apr 12, 2021
0d7548d
Update max7219.py
bluejazzCHN Apr 12, 2021
e5f2a48
Merge branch 'adafruit:master' into master
bluejazzCHN May 28, 2021
6b08cb9
run pylint
bluejazzCHN May 28, 2021
8f1ac59
solvind_docs
jposada202020 May 28, 2021
587688c
Merge remote-tracking branch 'Adafruit/master' into pull/29
jposada202020 May 31, 2021
562c9a3
solving_docs
jposada202020 May 31, 2021
395cced
Merge branch 'bluejazzCHN_master' into pull/29
jposada202020 May 31, 2021
3cefe12
Merge pull request #1 from jposada202020/pull/29
bluejazzCHN Jun 1, 2021
030fa8a
Revert "Pull/29"
bluejazzCHN Jun 1, 2021
0b53afa
Delete max7219_disaplay_string_multi_matrix.py
bluejazzCHN Jun 2, 2021
c1f2792
Merge branch 'adafruit:main' into master
bluejazzCHN Aug 20, 2021
004be6b
Update max7219.py
bluejazzCHN Aug 20, 2021
7de8922
Merge pull request #2 from bluejazzCHN/revert-1-pull/29
bluejazzCHN Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions adafruit_max7219/max7219.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: 2016 Philip R. Moyer for Adafruit Industries
# SPDX-FileCopyrightText: 2016 Radomir Dopieralski for Adafruit Industries
# SPDX-FileCopyrightText: 2021 bluejazzCHN for Adafruit Industries
#
# SPDX-License-Identifier: MIT

Expand All @@ -24,15 +25,16 @@
--------------------
**Hardware:**

* Adafruit `MAX7219CNG LED Matrix/Digit Display Driver -
* `Adafruit MAX7219CNG LED Matrix/Digit Display Driver -
MAX7219 <https://www.adafruit.com/product/453>`_ (Product ID: 453)

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
https://github.com/adafruit/circuitpython/releases

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
* Adafruit's Bus Device library:
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

**Notes:**
#. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf
Expand All @@ -54,7 +56,6 @@
class MAX7219:
"""
MAX2719 - driver for displays based on max719 chip_select

:param int width: the number of pixels wide
:param int height: the number of pixels high
:param object spi: an spi busio or spi bitbangio object
Expand Down Expand Up @@ -89,32 +90,31 @@ def init_display(self):
def brightness(self, value):
"""
Controls the brightness of the display.

:param int value: 0->15 dimmest to brightest
"""
if not 0 <= value <= 15:
raise ValueError("Brightness out of range")
self.write_cmd(_INTENSITY, value)

def show(self):
def show(self, number=1, t_num=1):
"""
Updates the display.
:param int number: which one is in the cascaded matrixs, default is 1.
:param int t_num: total number of cascaded Matrixs,default is 1.
"""
for ypos in range(8):
self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos])
self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos], number, t_num)

def fill(self, bit_value):
"""
Fill the display buffer.

:param int bit_value: value > 0 set the buffer bit, else clears the buffer bit
"""
self.framebuf.fill(bit_value)

def pixel(self, xpos, ypos, bit_value=None):
"""
Set one buffer bit

:param xpos: x position to set bit
:param ypos: y position to set bit
:param int bit_value: value > 0 sets the buffer bit, else clears the buffer bit
Expand All @@ -126,10 +126,29 @@ def scroll(self, delta_x, delta_y):
"""Srcolls the display using delta_x,delta_y."""
self.framebuf.scroll(delta_x, delta_y)

def write_cmd(self, cmd, data):
def write_cmd(self, cmd, data, number=1, t_num=1):
# pylint: disable=no-member
"""Writes a command to spi device."""
"""Writes a command to spi device.
:param int number: whichi one is in the cascaded matrixs, default is 1.
:param int t_num: total number of cascaded Matrixs,default is 1.
"""
# print('cmd {} data {}'.format(cmd,data))
self._chip_select.value = False

# send Noop to ones behind number Matrix
with self._spi_device as my_spi_device:
for i in range(number, t_num):
my_spi_device.write(bytearray([0, 0]))

my_spi_device.write(bytearray([cmd, data]))

# send Noop to all before number, if you want to know why, please ref to MAX7219.pdf.
for _ in range(0, number - 1):
my_spi_device.write(bytearray([0, 0]))

def rotation(self, direction):
"""
Set display direction
:param direction:set int to change display direction, value 0 (default), 1, 2, 3
"""
self.framebuf.rotation = direction
42 changes: 42 additions & 0 deletions examples/max7219_cascade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-FileCopyrightText: 2021 bluejazzCHN for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import random
from board import TX, RX, A2
import busio
import digitalio
from adafruit_max7219 import matrices

clk = RX
din = TX
cs = digitalio.DigitalInOut(A2)

spi = busio.SPI(clk, MOSI=din)
display = matrices.Matrix8x8(spi, cs)

while True:
display.clear_all()
s = "Hello, World!"

# Demo One: cascaded matrix with two max7219
# show random char in string s on the the first of cascaded matrixs.
# show scroll string s on the second of cascaded matrixs.
display.text(s[random.randint(0, len(s) - 1)], 0, 0)
display.show(1, 2)

for c in range(len(s) * 8):
display.fill(0)
display.text(s, -c, 0)
display.show(2, 2)
time.sleep(0.25)

# Demo two: scroll string s on the cascaded matrix with two max7219
for c in range(len(s) * 8):
display.fill(0)
display.text(s, -c, 0)
display.show(1, 2)
display.fill(0)
display.text(s, -c + 8, 0)
display.show(2, 2)
time.sleep(0.25)