From dabc765db6a98fa70d2b70cdb6b9af90d1de954c Mon Sep 17 00:00:00 2001 From: bluejazzCHN Date: Thu, 7 Jan 2021 22:19:46 +0800 Subject: [PATCH 01/43] update --- adafruit_max7219/max7219.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 530ddd1..9f22c6b 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -149,3 +149,11 @@ def write_cmd(self, cmd, data): self._chip_select.value = False with self._spi_device as my_spi_device: my_spi_device.write(bytearray([cmd, data])) + + 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 From 25b0b3617ad01c73659b732689b765a6505452d1 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Fri, 8 Jan 2021 12:17:55 +0800 Subject: [PATCH 02/43] Update README.rst --- README.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.rst b/README.rst index aaa33a7..e93d1f2 100644 --- a/README.rst +++ b/README.rst @@ -124,3 +124,17 @@ Documentation ============= For information on building library documentation, please check out `this guide `_. + + +Additons +============= + +1. Add rotation func + +.. code-block:: python + + matrix = matrices.Matrix8x8(spi, cs) + matrix.rotation(2) + + + From 785481d1bef9c803259c2eb902fff0b468339bfb Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Fri, 8 Jan 2021 12:19:58 +0800 Subject: [PATCH 03/43] Update README.rst --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index e93d1f2..a87e1e0 100644 --- a/README.rst +++ b/README.rst @@ -73,6 +73,7 @@ adafruit_max7219.Matrix8x8 Example spi = busio.SPI(clk, MOSI=din) display = matrices.Matrix8x8(spi, cs) + display.rotation(1) #change display direction while True: display.brightness(3) From 886581da0a4f65a2ab135d2b240ab4a352a112f2 Mon Sep 17 00:00:00 2001 From: bluejazzCHN Date: Sun, 10 Jan 2021 15:29:35 +0800 Subject: [PATCH 04/43] Add function that display string on mult matrix --- .vscode/settings.json | 22 +++++++++++++ adafruit_max7219/matrices.py | 24 ++++++++++++-- adafruit_max7219/max7219.py | 31 ++++++++++++++++++- .../max7219_disaplay_string_multi_matrix.py | 20 ++++++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/max7219_disaplay_string_multi_matrix.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2fe040b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "MicroPython.executeButton": [ + { + "text": "▶", + "tooltip": "运行", + "alignment": "left", + "command": "extension.executeFile", + "priority": 3.5 + } + ], + "MicroPython.syncButton": [ + { + "text": "$(sync)", + "tooltip": "同步", + "alignment": "left", + "command": "extension.execute", + "priority": 4 + } + ], + "python.linting.pylintEnabled": true, + "python.pythonPath": "/usr/bin/python3" +} \ No newline at end of file diff --git a/adafruit_max7219/matrices.py b/adafruit_max7219/matrices.py index 139076f..19bec26 100644 --- a/adafruit_max7219/matrices.py +++ b/adafruit_max7219/matrices.py @@ -27,6 +27,7 @@ """ from micropython import const from adafruit_max7219 import max7219 +import time __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git" @@ -45,8 +46,8 @@ class Matrix8x8(max7219.MAX7219): :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal """ - def __init__(self, spi, cs): - super().__init__(8, 8, spi, cs) + def __init__(self, spi, cs,num=1): + super().__init__(8, 8, spi, cs,num=num) def init_display(self): for cmd, data in ( @@ -56,7 +57,7 @@ def init_display(self): (_DECODEMODE, 0), (_SHUTDOWN, 1), ): - self.write_cmd(cmd, data) + self._write([cmd,data]*self.num) self.fill(0) self.show() @@ -77,3 +78,20 @@ def clear_all(self): Clears all matrix leds. """ self.fill(0) + + def display_str(self, data, delay=1): + """ + Display string on led matrix by matrix length + + :param str: string that can be of any length. + :param delay: transfer time from one screen to another screen. default value is 1s + + """ + i = -1 + for char in data: + i+=1 + self.fill(0) + self.text(char,1,0) + self.show_char_position(i%self.num) + if i%self.num == self.num -1: + time.sleep(delay) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 9f22c6b..1f09cac 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -66,6 +66,9 @@ _DIGIT0 = const(1) _INTENSITY = const(10) +MAX7219_REG_NOOP = 0x0 + + class MAX7219: """ @@ -81,7 +84,7 @@ class MAX7219: """ def __init__( - self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0 + self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0,num=1 ): self._chip_select = cs @@ -96,6 +99,8 @@ def __init__( self.width = width self.height = height + self.num = num + self.init_display() @@ -157,3 +162,27 @@ def rotation(self, direction): :param direction:set int to change display direction, value 0 (default), 1, 2, 3 """ self.framebuf.rotation = direction + + + def _write(self, data): + """ + Send the bytes (which should comprise of alternating command, data values) over the SPI device. + + :param data: command collections + """ + + self._chip_select.value=False + with self._spi_device as my_spi_device: + my_spi_device.write(bytes(data)) + self._chip_select.value=True + + + def show_char_position(self,position=0): + """ + write data to the position that is one of multi led matrix + + :param position: the position of matrix, value begin 0. + + """ + for ypos in range(8): + self._write([_DIGIT0 + ypos, self._buffer[ypos]]+([MAX7219_REG_NOOP, 0] *(position))) diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py new file mode 100644 index 0000000..445d2c2 --- /dev/null +++ b/examples/max7219_disaplay_string_multi_matrix.py @@ -0,0 +1,20 @@ +# Display string on multi led matrix at any position +# Author: songjiangzhang@hotmail.com +# This sample use EPS32 S2 Board + +from adafruit_max7219 import matrices +import board +import busio +import digitalio + +clk = board.IO4 +din = board.IO2 +cs = digitalio.DigitalInOut(board.IO3) + +spi = busio.SPI(clk, MOSI=din) +display = matrices.Matrix8x8(spi, cs,4) +display.framebuf.rotation =1 # rotate screen + +display.clear_all() +while True: + display.display_str('abc7568123456789asdfghj',2) From 8e8807bc4286e71c10bbdbbf3b65112486168f43 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sun, 10 Jan 2021 16:31:26 +0800 Subject: [PATCH 05/43] Delete settings.json --- .vscode/settings.json | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 2fe040b..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "MicroPython.executeButton": [ - { - "text": "▶", - "tooltip": "运行", - "alignment": "left", - "command": "extension.executeFile", - "priority": 3.5 - } - ], - "MicroPython.syncButton": [ - { - "text": "$(sync)", - "tooltip": "同步", - "alignment": "left", - "command": "extension.execute", - "priority": 4 - } - ], - "python.linting.pylintEnabled": true, - "python.pythonPath": "/usr/bin/python3" -} \ No newline at end of file From a63e02eef71712450536a7e6e2a6314f16687b2e Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sun, 10 Jan 2021 16:44:24 +0800 Subject: [PATCH 06/43] Update max7219_disaplay_string_multi_matrix.py --- examples/max7219_disaplay_string_multi_matrix.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py index 445d2c2..850882c 100644 --- a/examples/max7219_disaplay_string_multi_matrix.py +++ b/examples/max7219_disaplay_string_multi_matrix.py @@ -1,7 +1,3 @@ -# Display string on multi led matrix at any position -# Author: songjiangzhang@hotmail.com -# This sample use EPS32 S2 Board - from adafruit_max7219 import matrices import board import busio From 7562fbea4ee6ccb632652099b0e49ed6ee9c1c76 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 22:20:20 +0800 Subject: [PATCH 07/43] update functions to support the cascaded matrix. You can control the display on any one in the cascaded matrix. --- adafruit_max7219/max7219.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index ff30c32..f373754 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -96,12 +96,14 @@ def brightness(self, value): raise ValueError("Brightness out of range") self.write_cmd(_INTENSITY, value) - def show(self): + def show(self, number = 1): """ Updates the display. + + :param int number: whichi one is in the 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) def fill(self, bit_value): """ @@ -126,10 +128,15 @@ 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): # 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. + """ # print('cmd {} data {}'.format(cmd,data)) self._chip_select.value = False with self._spi_device as my_spi_device: - my_spi_device.write(bytearray([cmd, data])) + my_spi_device.write(bytearray([cmd, data])) # send cmd and data to one(number is) of the cascaded matrixs. + for i in range(number-1): + my_spi_device.write(bytearray([0, 0])) # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. From 2af5d94eeabacbad1955f38df01c848eb562c5fb Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 22:30:07 +0800 Subject: [PATCH 08/43] demo in the cascaded matrix --- examples/max7219_cascade.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/max7219_cascade.py diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py new file mode 100644 index 0000000..6c23534 --- /dev/null +++ b/examples/max7219_cascade.py @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +from adafruit_max7219 import matrices +from board import TX, RX, A2 +import busio +import digitalio +import time +import random + +clk = RX +din = TX +cs = digitalio.DigitalInOut(A2) + +spi = busio.SPI(clk, MOSI=din) +display = matrices.Matrix8x8(spi, cs) +while True: + display.brightness(1) + + display.fill(1) + display.pixel(3, 3) + display.pixel(3, 4) + display.pixel(4, 3) + display.pixel(4, 4) + display.show() + time.sleep(3.0) + + display.clear_all() + s = 'Hello, World!' + display.text(s[random.randint(0,len(s)-1)],0,0) + display.show(1) # show random char in string s on the the first of cascaded matrixs. + for c in range(len(s)*8): + display.fill(0) + display.text(s,-c,0) + display.show(2) # show scrolled string on the second of cascaded matrixs + time.sleep(0.25) From 93e5b3a4b1a18091cb302235b5518673d8e68746 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 22:45:40 +0800 Subject: [PATCH 09/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index 6c23534..96eda80 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -1,12 +1,12 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from adafruit_max7219 import matrices -from board import TX, RX, A2 -import busio -import digitalio import time import random +from board import TX, RX, A1 +import busio +import digitalio +from adafruit_max7219 import matrices clk = RX din = TX @@ -14,6 +14,7 @@ spi = busio.SPI(clk, MOSI=din) display = matrices.Matrix8x8(spi, cs) + while True: display.brightness(1) From 84ea72a27628b646ba41cb2a51ae931eafcd041d Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 22:58:19 +0800 Subject: [PATCH 10/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index 96eda80..bb82588 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -3,7 +3,7 @@ import time import random -from board import TX, RX, A1 +from board import TX, RX, A2 import busio import digitalio from adafruit_max7219 import matrices From 6dc7b99c427967e486b722a6bd2113c7d1ce2d70 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:01:20 +0800 Subject: [PATCH 11/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index bb82588..274ae5b 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -29,9 +29,13 @@ display.clear_all() s = 'Hello, World!' display.text(s[random.randint(0,len(s)-1)],0,0) - display.show(1) # show random char in string s on the the first of cascaded matrixs. + + # show random char in string s on the the first of cascaded matrixs. + display.show(1) for c in range(len(s)*8): display.fill(0) display.text(s,-c,0) - display.show(2) # show scrolled string on the second of cascaded matrixs + + # show scrolled string on the second of cascaded matrixs. + display.show(2) time.sleep(0.25) From 816c5ac4be0778f06a215bf122ce173143c389f9 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:07:23 +0800 Subject: [PATCH 12/43] Update max7219.py --- adafruit_max7219/max7219.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index f373754..3c7513d 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -137,6 +137,8 @@ def write_cmd(self, cmd, data,number = 1): # print('cmd {} data {}'.format(cmd,data)) self._chip_select.value = False with self._spi_device as my_spi_device: - my_spi_device.write(bytearray([cmd, data])) # send cmd and data to one(number is) of the cascaded matrixs. + 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 i in range(number-1): - my_spi_device.write(bytearray([0, 0])) # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. + my_spi_device.write(bytearray([0, 0])) From 2e2a62a0d2e783c4e99b0de9b14be35f01cbc85c Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:24:25 +0800 Subject: [PATCH 13/43] Update max7219.py --- adafruit_max7219/max7219.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 3c7513d..a8a5b8d 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -140,5 +140,5 @@ def write_cmd(self, cmd, data,number = 1): 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 i in range(number-1): + for i in range(0,number-1): my_spi_device.write(bytearray([0, 0])) From dd17d27520d2ac254b1f89f4bea6ebcd0a95e5de Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:26:29 +0800 Subject: [PATCH 14/43] Update max7219.py --- adafruit_max7219/max7219.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index a8a5b8d..9d6a980 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -141,4 +141,5 @@ def write_cmd(self, cmd, data,number = 1): # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. for i in range(0,number-1): - my_spi_device.write(bytearray([0, 0])) + my_spi_device.write(bytearray([0, 0])) + i = 0 From 022855b96ab1328cbe8a1269c3e323b599b3cfca Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:31:27 +0800 Subject: [PATCH 15/43] Update max7219.py --- adafruit_max7219/max7219.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 9d6a980..b75568c 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -140,6 +140,6 @@ def write_cmd(self, cmd, data,number = 1): 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 i in range(0,number-1): + for i in range(number-1): my_spi_device.write(bytearray([0, 0])) i = 0 From a1e3e4af11b17d74cbe6674f9b8138b774387768 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:37:18 +0800 Subject: [PATCH 16/43] Update max7219.py --- adafruit_max7219/max7219.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index b75568c..422018f 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -142,4 +142,4 @@ def write_cmd(self, cmd, data,number = 1): # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. for i in range(number-1): my_spi_device.write(bytearray([0, 0])) - i = 0 + i = i-0 From 6a0081761e8766fbce363404a9a5708f52c4392e Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 5 Apr 2021 23:55:17 +0800 Subject: [PATCH 17/43] Update max7219.py --- adafruit_max7219/max7219.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 422018f..12fe286 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -136,6 +136,7 @@ def write_cmd(self, cmd, data,number = 1): """ # print('cmd {} data {}'.format(cmd,data)) self._chip_select.value = False + with self._spi_device as my_spi_device: my_spi_device.write(bytearray([cmd, data])) From 44f0ced9ca5aee251ddb896b8dedd12436482c12 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 17:26:42 +0800 Subject: [PATCH 18/43] Update max7219.py --- adafruit_max7219/max7219.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 12fe286..8a231a5 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -96,11 +96,12 @@ def brightness(self, value): raise ValueError("Brightness out of range") self.write_cmd(_INTENSITY, value) - def show(self, number = 1): + def show(self, number = 1,t_num=1): """ Updates the display. - :param int number: whichi one is in the cascaded matrixs, default is 1. + :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],number) @@ -128,19 +129,22 @@ 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,number = 1): + def write_cmd(self, cmd, data,number = 1,t_num=1): # pylint: disable=no-member """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 with self._spi_device as my_spi_device: + for i in range(number,t_num): + my_spi_device.write(bytearray([0, 0])) # send Noop to ones behind number Matrix + 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 i in range(number-1): + for i in range(0,number-1): my_spi_device.write(bytearray([0, 0])) - i = i-0 From 91ed196e8d2e6d8f662aaee52ccc9bb4054ef6ab Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 17:27:46 +0800 Subject: [PATCH 19/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index 274ae5b..b96e6b0 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -31,11 +31,11 @@ display.text(s[random.randint(0,len(s)-1)],0,0) # show random char in string s on the the first of cascaded matrixs. - display.show(1) + display.show(1,2) for c in range(len(s)*8): display.fill(0) display.text(s,-c,0) # show scrolled string on the second of cascaded matrixs. - display.show(2) + display.show(2,2) time.sleep(0.25) From 43d103b7468e507bbce2f188048b32293af707c2 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 17:33:26 +0800 Subject: [PATCH 20/43] Update max7219.py --- adafruit_max7219/max7219.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 8a231a5..010e5bf 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -104,7 +104,7 @@ def show(self, number = 1,t_num=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],number) + self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos],number,t_num) def fill(self, bit_value): """ @@ -129,7 +129,7 @@ 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,number = 1,t_num=1): + def write_cmd(self, cmd, data,number = 1, t_num=1): # pylint: disable=no-member """Writes a command to spi device. From 47d9c90bffc8b5e7b44e5ac998e2aa63aea121f0 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 21:14:53 +0800 Subject: [PATCH 21/43] Update max7219.py --- adafruit_max7219/max7219.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 010e5bf..3019bd0 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -148,3 +148,4 @@ def write_cmd(self, cmd, data,number = 1, t_num=1): # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. for i in range(0,number-1): my_spi_device.write(bytearray([0, 0])) + i = i - i From bcbe4136f836e6e240b20387d2a4a558997a9f8b Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 21:38:10 +0800 Subject: [PATCH 22/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index b96e6b0..895bfa1 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -1,6 +1,3 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# SPDX-License-Identifier: MIT - import time import random from board import TX, RX, A2 @@ -17,7 +14,6 @@ while True: display.brightness(1) - display.fill(1) display.pixel(3, 3) display.pixel(3, 4) @@ -25,13 +21,13 @@ display.pixel(4, 4) display.show() time.sleep(3.0) - display.clear_all() s = 'Hello, World!' display.text(s[random.randint(0,len(s)-1)],0,0) # show random char in string s on the the first of cascaded matrixs. - display.show(1,2) + display.show(1,2) + for c in range(len(s)*8): display.fill(0) display.text(s,-c,0) From 76a8dbfa3c4c6f846a89701aa4e3b96c9b8dca6e Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 21:53:01 +0800 Subject: [PATCH 23/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index 895bfa1..dfe8b22 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -13,13 +13,6 @@ display = matrices.Matrix8x8(spi, cs) while True: - display.brightness(1) - display.fill(1) - display.pixel(3, 3) - display.pixel(3, 4) - display.pixel(4, 3) - display.pixel(4, 4) - display.show() time.sleep(3.0) display.clear_all() s = 'Hello, World!' From 3fabbb83818937f16e7cf0b431f6067593b80f20 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 23:10:02 +0800 Subject: [PATCH 24/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index dfe8b22..5cb4f04 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -13,18 +13,27 @@ display = matrices.Matrix8x8(spi, cs) while True: - time.sleep(3.0) - display.clear_all() - s = 'Hello, World!' - display.text(s[random.randint(0,len(s)-1)],0,0) - - # show random char in string s on the the first of cascaded matrixs. - display.show(1,2) - - for c in range(len(s)*8): - display.fill(0) - display.text(s,-c,0) + 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) - # show scrolled string on the second of cascaded matrixs. - display.show(2,2) - time.sleep(0.25) + 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) From ec499b4ff34f67e2c419e5da1bf4c682df772bdb Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 23:27:58 +0800 Subject: [PATCH 25/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index 5cb4f04..61f4a1f 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 bluejazzCHN for Adafruit Industries +# SPDX-License-Identifier: MIT + import time import random from board import TX, RX, A2 From 227a3842ae9cedb05c6c2cd15985ced1cd2ebf62 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 23:44:09 +0800 Subject: [PATCH 26/43] Update max7219_cascade.py --- examples/max7219_cascade.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index 61f4a1f..fcea271 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -22,21 +22,21 @@ #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) + 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) + 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.text(s, -c, 0) + display.show(1, 2) display.fill(0) - display.text(s,-c+8,0) - display.show(2,2) + display.text(s, -c+8, 0) + display.show(2, 2) time.sleep(0.25) From ac117b1402e5c74f05140a15e5efa595110b1319 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 23:50:29 +0800 Subject: [PATCH 27/43] Update max7219.py --- adafruit_max7219/max7219.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 3019bd0..c0c775c 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -96,7 +96,7 @@ def brightness(self, value): raise ValueError("Brightness out of range") self.write_cmd(_INTENSITY, value) - def show(self, number = 1,t_num=1): + def show(self, number=1, t_num=1): """ Updates the display. @@ -104,7 +104,7 @@ def show(self, number = 1,t_num=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],number,t_num) + self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos], number, t_num) def fill(self, bit_value): """ @@ -129,7 +129,7 @@ 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,number = 1, t_num=1): + def write_cmd(self, cmd, data, number=1, t_num=1): # pylint: disable=no-member """Writes a command to spi device. @@ -140,12 +140,12 @@ def write_cmd(self, cmd, data,number = 1, t_num=1): self._chip_select.value = False with self._spi_device as my_spi_device: - for i in range(number,t_num): + for i in range(number, t_num): my_spi_device.write(bytearray([0, 0])) # send Noop to ones behind number Matrix 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 i in range(0,number-1): + for i in range(0, number-1): my_spi_device.write(bytearray([0, 0])) - i = i - i + i = i-i From 18da08cb5b307af7446ba1952800c225c207feeb Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 6 Apr 2021 23:51:21 +0800 Subject: [PATCH 28/43] Update max7219.py --- adafruit_max7219/max7219.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index c0c775c..319b3b6 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -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 From 5d7d62a25dbf94fb5605709c768a3986ec99cf01 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sat, 10 Apr 2021 13:39:12 +0800 Subject: [PATCH 29/43] Update max7219.py --- adafruit_max7219/max7219.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 319b3b6..e42792c 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -150,3 +150,11 @@ def write_cmd(self, cmd, data, number=1, t_num=1): for i in range(0, number-1): my_spi_device.write(bytearray([0, 0])) i = i-i + + 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 From 50cbbd88d0ce8f614b92067ddd0253f05ba3f53f Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sat, 10 Apr 2021 14:31:00 +0800 Subject: [PATCH 30/43] Add files via upload --- examples/max7219_cascade.py | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/max7219_cascade.py b/examples/max7219_cascade.py index fcea271..23f5203 100644 --- a/examples/max7219_cascade.py +++ b/examples/max7219_cascade.py @@ -10,33 +10,33 @@ clk = RX din = TX -cs = digitalio.DigitalInOut(A2) - +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.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) - - 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) + display.fill(0) + display.text(s, -c + 8, 0) + display.show(2, 2) + time.sleep(0.25) From d1e84ff86695be2a0d47ac38095d0adea41bd977 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sat, 10 Apr 2021 14:31:20 +0800 Subject: [PATCH 31/43] Add files via upload --- adafruit_max7219/max7219.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index e42792c..693e6ff 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -139,18 +139,20 @@ def write_cmd(self, cmd, data, number=1, t_num=1): """ # print('cmd {} data {}'.format(cmd,data)) self._chip_select.value = False - + with self._spi_device as my_spi_device: for i in range(number, t_num): - my_spi_device.write(bytearray([0, 0])) # send Noop to ones behind number Matrix - - my_spi_device.write(bytearray([cmd, data])) - + my_spi_device.write( + bytearray([0, 0]) + ) # send Noop to ones behind number Matrix + + 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 i in range(0, number-1): + for i in range(0, number - 1): my_spi_device.write(bytearray([0, 0])) - i = i-i - + i = i - i + def rotation(self, direction): """ Set display direction From f2d029ea3c4096f3ab18881e7b702eef5613bc06 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sat, 10 Apr 2021 14:42:34 +0800 Subject: [PATCH 32/43] Add files via upload From 086edbb2894678a71dd6d08cfe0682dbb4541624 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Sat, 10 Apr 2021 15:11:15 +0800 Subject: [PATCH 33/43] Add files via upload --- adafruit_max7219/max7219.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 693e6ff..1d63530 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -140,11 +140,10 @@ def write_cmd(self, cmd, data, number=1, t_num=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]) - ) # send Noop to ones behind number Matrix + my_spi_device.write(bytearray([0, 0])) my_spi_device.write(bytearray([cmd, data])) From f071e0c0d78d8313e1e118ab0030ca21212fe9e4 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 12 Apr 2021 21:03:43 +0800 Subject: [PATCH 34/43] Add files via upload --- adafruit_max7219/max7219.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 1d63530..50bd06b 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -143,7 +143,7 @@ def write_cmd(self, cmd, data, number=1, t_num=1): # 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([0, 0])) my_spi_device.write(bytearray([cmd, data])) From edabb16604bf6dd390f6f0d54c08ed4297f5fbc6 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 12 Apr 2021 21:10:23 +0800 Subject: [PATCH 35/43] Update max7219.py --- adafruit_max7219/max7219.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 50bd06b..82bd2b0 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -10,31 +10,22 @@ CircuitPython library to support MAX7219 LED Matrix/Digit Display Driver. This library supports the use of the MAX7219-based display in CircuitPython, either an 8x8 matrix or a 8 digit 7-segment numeric display. - See Also ========= * matrices.Maxtrix8x8 is a class support an 8x8 led matrix display * bcddigits.BCDDigits is a class that support the 8 digit 7-segment display - Beware that most CircuitPython compatible hardware are 3.3v logic level! Make sure that the input pin is 5v tolerant. - * Author(s): Michael McWethy - Implementation Notes -------------------- **Hardware:** - * Adafruit `MAX7219CNG LED Matrix/Digit Display Driver - MAX7219 `_ (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 - **Notes:** #. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf """ @@ -55,7 +46,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 @@ -90,7 +80,6 @@ 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: @@ -110,7 +99,6 @@ def show(self, number=1, t_num=1): 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) @@ -118,7 +106,6 @@ def fill(self, 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 @@ -155,7 +142,6 @@ def write_cmd(self, cmd, data, number=1, t_num=1): 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 From 03f37cb1553cfa1f3a37b1fdf79b378981b69fc7 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 12 Apr 2021 21:16:32 +0800 Subject: [PATCH 36/43] Update max7219.py --- adafruit_max7219/max7219.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 82bd2b0..3c98849 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -137,7 +137,6 @@ def write_cmd(self, cmd, data, number=1, t_num=1): # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. for i in range(0, number - 1): my_spi_device.write(bytearray([0, 0])) - i = i - i def rotation(self, direction): """ From 0d7548db84b18c08fc9a2bdcbc23f9e42ca54566 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Mon, 12 Apr 2021 22:42:26 +0800 Subject: [PATCH 37/43] Update max7219.py --- adafruit_max7219/max7219.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 3c98849..82bd2b0 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -137,6 +137,7 @@ def write_cmd(self, cmd, data, number=1, t_num=1): # send Noop to all before number, if you want to know why, please ref to MAX7219.pdf. for i in range(0, number - 1): my_spi_device.write(bytearray([0, 0])) + i = i - i def rotation(self, direction): """ From 6b08cb93f207897f673d5dc32065554020ae2b80 Mon Sep 17 00:00:00 2001 From: BluejazzCHN Date: Sat, 29 May 2021 00:28:12 +0800 Subject: [PATCH 38/43] run pylint --- adafruit_max7219/max7219.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 82bd2b0..73c73b7 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -89,7 +89,6 @@ def brightness(self, value): 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. """ @@ -120,7 +119,6 @@ def scroll(self, delta_x, delta_y): def write_cmd(self, cmd, data, number=1, t_num=1): # pylint: disable=no-member """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. """ From 8f1ac59098cc1e8cbc6633b900e1b8930c93c9cc Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 28 May 2021 13:24:01 -0400 Subject: [PATCH 39/43] solvind_docs --- adafruit_max7219/max7219.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index 73c73b7..b0458f6 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -10,22 +10,32 @@ CircuitPython library to support MAX7219 LED Matrix/Digit Display Driver. This library supports the use of the MAX7219-based display in CircuitPython, either an 8x8 matrix or a 8 digit 7-segment numeric display. + See Also ========= * matrices.Maxtrix8x8 is a class support an 8x8 led matrix display * bcddigits.BCDDigits is a class that support the 8 digit 7-segment display + Beware that most CircuitPython compatible hardware are 3.3v logic level! Make sure that the input pin is 5v tolerant. + * Author(s): Michael McWethy + Implementation Notes -------------------- **Hardware:** -* Adafruit `MAX7219CNG LED Matrix/Digit Display Driver - + +* `Adafruit MAX7219CNG LED Matrix/Digit Display Driver - MAX7219 `_ (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 """ From 562c9a3a8aed4e81eff48dd15fcad28877729b9c Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 31 May 2021 11:27:34 -0400 Subject: [PATCH 40/43] solving_docs --- README.rst | 5 +---- adafruit_max7219/matrices.py | 17 +++++++------- adafruit_max7219/max7219.py | 22 +++++++++---------- .../max7219_disaplay_string_multi_matrix.py | 12 ++++++---- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/README.rst b/README.rst index a87e1e0..383b1cb 100644 --- a/README.rst +++ b/README.rst @@ -133,9 +133,6 @@ Additons 1. Add rotation func .. code-block:: python - + matrix = matrices.Matrix8x8(spi, cs) matrix.rotation(2) - - - diff --git a/adafruit_max7219/matrices.py b/adafruit_max7219/matrices.py index 8e3f81b..f32c127 100644 --- a/adafruit_max7219/matrices.py +++ b/adafruit_max7219/matrices.py @@ -6,9 +6,10 @@ `adafruit_max7219.matrices.Matrix8x8` ==================================================== """ +import time from micropython import const from adafruit_max7219 import max7219 -import time + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git" @@ -27,8 +28,8 @@ class Matrix8x8(max7219.MAX7219): :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal """ - def __init__(self, spi, cs,num=1): - super().__init__(8, 8, spi, cs,num=num) + def __init__(self, spi, cs, num=1): + super().__init__(8, 8, spi, cs, num=num) def init_display(self): for cmd, data in ( @@ -38,7 +39,7 @@ def init_display(self): (_DECODEMODE, 0), (_SHUTDOWN, 1), ): - self._write([cmd,data]*self.num) + self._write([cmd, data] * self.num) self.fill(0) self.show() @@ -70,9 +71,9 @@ def display_str(self, data, delay=1): """ i = -1 for char in data: - i+=1 + i += 1 self.fill(0) - self.text(char,1,0) - self.show_char_position(i%self.num) - if i%self.num == self.num -1: + self.text(char, 1, 0) + self.show_char_position(i % self.num) + if i % self.num == self.num - 1: time.sleep(delay) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index f033930..0333476 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -53,7 +53,6 @@ MAX7219_REG_NOOP = 0x0 - class MAX7219: """ MAX2719 - driver for displays based on max719 chip_select @@ -68,7 +67,7 @@ class MAX7219: """ def __init__( - self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0,num=1 + self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0, num=1 ): self._chip_select = cs @@ -85,7 +84,6 @@ def __init__( self.height = height self.num = num - self.init_display() def init_display(self): @@ -147,21 +145,20 @@ def rotation(self, direction): """ self.framebuf.rotation = direction - def _write(self, data): """ - Send the bytes (which should comprise of alternating command, data values) over the SPI device. - + Send the bytes (which should comprise of alternating command, data values) + over the SPI device. + :param data: command collections """ - self._chip_select.value=False + self._chip_select.value = False with self._spi_device as my_spi_device: my_spi_device.write(bytes(data)) - self._chip_select.value=True - + self._chip_select.value = True - def show_char_position(self,position=0): + def show_char_position(self, position=0): """ write data to the position that is one of multi led matrix @@ -169,4 +166,7 @@ def show_char_position(self,position=0): """ for ypos in range(8): - self._write([_DIGIT0 + ypos, self._buffer[ypos]]+([MAX7219_REG_NOOP, 0] *(position))) + self._write( + [_DIGIT0 + ypos, self._buffer[ypos]] + + ([MAX7219_REG_NOOP, 0] * (position)) + ) diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py index 850882c..930b49f 100644 --- a/examples/max7219_disaplay_string_multi_matrix.py +++ b/examples/max7219_disaplay_string_multi_matrix.py @@ -1,16 +1,20 @@ -from adafruit_max7219 import matrices +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + + import board import busio import digitalio +from adafruit_max7219 import matrices clk = board.IO4 din = board.IO2 cs = digitalio.DigitalInOut(board.IO3) spi = busio.SPI(clk, MOSI=din) -display = matrices.Matrix8x8(spi, cs,4) -display.framebuf.rotation =1 # rotate screen +display = matrices.Matrix8x8(spi, cs, 4) +display.framebuf.rotation = 1 # rotate screen display.clear_all() while True: - display.display_str('abc7568123456789asdfghj',2) + display.display_str("abc7568123456789asdfghj", 2) From 030fa8a575847aa7667b01a625095f03015598e6 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Tue, 1 Jun 2021 10:06:11 +0800 Subject: [PATCH 41/43] Revert "Pull/29" --- README.rst | 12 ------- adafruit_max7219/matrices.py | 25 ++------------ adafruit_max7219/max7219.py | 34 +------------------ .../max7219_disaplay_string_multi_matrix.py | 20 ----------- 4 files changed, 4 insertions(+), 87 deletions(-) delete mode 100644 examples/max7219_disaplay_string_multi_matrix.py diff --git a/README.rst b/README.rst index 383b1cb..aaa33a7 100644 --- a/README.rst +++ b/README.rst @@ -73,7 +73,6 @@ adafruit_max7219.Matrix8x8 Example spi = busio.SPI(clk, MOSI=din) display = matrices.Matrix8x8(spi, cs) - display.rotation(1) #change display direction while True: display.brightness(3) @@ -125,14 +124,3 @@ Documentation ============= For information on building library documentation, please check out `this guide `_. - - -Additons -============= - -1. Add rotation func - -.. code-block:: python - - matrix = matrices.Matrix8x8(spi, cs) - matrix.rotation(2) diff --git a/adafruit_max7219/matrices.py b/adafruit_max7219/matrices.py index f32c127..955e050 100644 --- a/adafruit_max7219/matrices.py +++ b/adafruit_max7219/matrices.py @@ -6,11 +6,9 @@ `adafruit_max7219.matrices.Matrix8x8` ==================================================== """ -import time from micropython import const from adafruit_max7219 import max7219 - __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git" @@ -28,8 +26,8 @@ class Matrix8x8(max7219.MAX7219): :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal """ - def __init__(self, spi, cs, num=1): - super().__init__(8, 8, spi, cs, num=num) + def __init__(self, spi, cs): + super().__init__(8, 8, spi, cs) def init_display(self): for cmd, data in ( @@ -39,7 +37,7 @@ def init_display(self): (_DECODEMODE, 0), (_SHUTDOWN, 1), ): - self._write([cmd, data] * self.num) + self.write_cmd(cmd, data) self.fill(0) self.show() @@ -60,20 +58,3 @@ def clear_all(self): Clears all matrix leds. """ self.fill(0) - - def display_str(self, data, delay=1): - """ - Display string on led matrix by matrix length - - :param str: string that can be of any length. - :param delay: transfer time from one screen to another screen. default value is 1s - - """ - i = -1 - for char in data: - i += 1 - self.fill(0) - self.text(char, 1, 0) - self.show_char_position(i % self.num) - if i % self.num == self.num - 1: - time.sleep(delay) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index a665ed7..b0458f6 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -52,8 +52,6 @@ _DIGIT0 = const(1) _INTENSITY = const(10) -MAX7219_REG_NOOP = 0x0 - class MAX7219: """ @@ -68,7 +66,7 @@ class MAX7219: """ def __init__( - self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0, num=1 + self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0 ): self._chip_select = cs @@ -83,7 +81,6 @@ def __init__( self.width = width self.height = height - self.num = num self.init_display() @@ -93,7 +90,6 @@ 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: @@ -112,7 +108,6 @@ def show(self, number=1, t_num=1): 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) @@ -120,7 +115,6 @@ def fill(self, 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 @@ -159,29 +153,3 @@ def rotation(self, direction): :param direction:set int to change display direction, value 0 (default), 1, 2, 3 """ self.framebuf.rotation = direction - - def _write(self, data): - """ - Send the bytes (which should comprise of alternating command, data values) - over the SPI device. - - :param data: command collections - """ - - self._chip_select.value = False - with self._spi_device as my_spi_device: - my_spi_device.write(bytes(data)) - self._chip_select.value = True - - def show_char_position(self, position=0): - """ - write data to the position that is one of multi led matrix - - :param position: the position of matrix, value begin 0. - - """ - for ypos in range(8): - self._write( - [_DIGIT0 + ypos, self._buffer[ypos]] - + ([MAX7219_REG_NOOP, 0] * (position)) - ) diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py deleted file mode 100644 index 930b49f..0000000 --- a/examples/max7219_disaplay_string_multi_matrix.py +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# SPDX-License-Identifier: MIT - - -import board -import busio -import digitalio -from adafruit_max7219 import matrices - -clk = board.IO4 -din = board.IO2 -cs = digitalio.DigitalInOut(board.IO3) - -spi = busio.SPI(clk, MOSI=din) -display = matrices.Matrix8x8(spi, cs, 4) -display.framebuf.rotation = 1 # rotate screen - -display.clear_all() -while True: - display.display_str("abc7568123456789asdfghj", 2) From 0b53afa9ae44c62cef9705312dc519c65a0bb5e0 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Wed, 2 Jun 2021 10:27:03 +0800 Subject: [PATCH 42/43] Delete max7219_disaplay_string_multi_matrix.py this demo is for old API in the early PR. so delete it --- .../max7219_disaplay_string_multi_matrix.py | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 examples/max7219_disaplay_string_multi_matrix.py diff --git a/examples/max7219_disaplay_string_multi_matrix.py b/examples/max7219_disaplay_string_multi_matrix.py deleted file mode 100644 index 930b49f..0000000 --- a/examples/max7219_disaplay_string_multi_matrix.py +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# SPDX-License-Identifier: MIT - - -import board -import busio -import digitalio -from adafruit_max7219 import matrices - -clk = board.IO4 -din = board.IO2 -cs = digitalio.DigitalInOut(board.IO3) - -spi = busio.SPI(clk, MOSI=din) -display = matrices.Matrix8x8(spi, cs, 4) -display.framebuf.rotation = 1 # rotate screen - -display.clear_all() -while True: - display.display_str("abc7568123456789asdfghj", 2) From 004be6b95f25996b9dc3f3bb341fb47bc9cd9810 Mon Sep 17 00:00:00 2001 From: OldCodeFans Date: Fri, 20 Aug 2021 23:02:51 +0800 Subject: [PATCH 43/43] Update max7219.py --- adafruit_max7219/max7219.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index a665ed7..bc80f21 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -149,9 +149,8 @@ def write_cmd(self, cmd, data, number=1, t_num=1): 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 i in range(0, number - 1): + for _ in range(0, number - 1): my_spi_device.write(bytearray([0, 0])) - i = i - i def rotation(self, direction): """