MicroPython Max7219 8x8 LED Matrix
A MicroPython library for the MAX7219 8x8 LED matrix driver using the SPI interface. Supporting custom fonts and cascading matrices.
Features
- Cascading matrices together
- Custom font support
- Extends the FrameBuffer class
- Removes the need to specify offset for text method
- Extendable
Examples
Raspberry Pi Pico
| Pico | max7219 |
|---|---|
| 40 (VBUS) | VCC 5V |
| 38 (GND) | GND |
| 5 (GP3) | DIN |
| 7 (GP5) | CS |
| 4 (GP2) | CLK |
from machine import Pin, SPI
from max7219 import Matrix8x8
spi = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))
ss = Pin(5, Pin.OUT)
display = Matrix8x8(spi, ss, 4)
# change brightness 1-15
display.brightness(5)
# clear display
display.zero()
display.show()
# show text using FrameBuffer's font
display.text("CODE")
display.show()
Docs
- For any change to the
FrameBufferto appear, call the.show()method - You may have to add delays when calling methods, these are documented in the datasheet
- Tested on 1.19.1
Display Text
display = Matrix8x8(...)
display.zero()
display.text("HI!")
display.show()
Custom Fonts
Custom fonts (glyphs) can be provided, each glyph must be 8x8. Missing characters will use default characters from FrameBuffer.
GLYPHS = {
"X": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
}
display = Matrix8x8(...)
display.text_from_glyph("X", GLYPHS)
Shutdown / Wake
Shutting down and waking up the display is supported. This should allow a device to consume just 150μA when it's not needed. When the display is woken from shutdown the previous display should appear.
# shutdown display
display.shutdown()
# wake from shutdown
display.wake()
Test Mode
Test mode will enable all pixels, shutdown mode has no effect when testing mode is enabled.
# enable test mode
display.test()
# disable test mode
display.test(False)
Extending
Scrolling Text
Although not built-in you could add scrolling text like shown in the following example:
from utime import sleep_ms
from max7219 import Matrix8x8
class Matrix8x8Ext(Matrix8x8):
def scroll_text(self, s, ms_delay=100):
s_width = len(s) * 8
n_pixels = self.num * 8
while True:
for x in range(n_pixels, -s_width, -1):
self.zero()
self.text(s, x)
self.show()
sleep_ms(ms_delay)
return s_width
Attribution
- Original code by @mcauser
- Data-Sheet
License
Licensed under the MIT License, found in LICENSE.txt.
Metadata
Release files for micropython-max7219 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| micropython-max7219-0.2.0.tar.gz | 4.2 kB | Without provenance | Details for micropython-max7219-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| micropython_max7219-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for micropython_max7219-0.2.0-py3-none-any.whl |
Total release size: 8.9 kB
Release files / micropython-max7219-0.2.0.tar.gz
| Download URL | micropython-max7219-0.2.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a55ccca514df51a05f19ff47667ab5a5bec21f15901e9eaa991e642b8930fdd
|
|
BLAKE2b-256 checksum How to use checksums |
bd8fc2dc9f5ae8dd1b7b695498bb4ca8cb5e2871dc4263435c5d9237fa7ffe5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / micropython_max7219-0.2.0-py3-none-any.whl
| Download URL | micropython_max7219-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d70b0c3ebf1485ef5d678a3ccfa8df7090003765d48771e9cbaffa2fa61889ab
|
|
BLAKE2b-256 checksum How to use checksums |
e0428c0686f4bc4eee3467326f89d07e97b89cc0211bb4c3c4b857acff9a5d20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for micropython-max7219 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.