A MicroPython library for the Max7219 8x8 LED matrix driver
Project description
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
FrameBuffer
to 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
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file micropython-max7219-0.2.0.tar.gz
.
File metadata
- Download URL: micropython-max7219-0.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a55ccca514df51a05f19ff47667ab5a5bec21f15901e9eaa991e642b8930fdd |
|
MD5 | e6019dcd2dd07d61daeeaa6c0f96da8d |
|
BLAKE2b-256 | bd8fc2dc9f5ae8dd1b7b695498bb4ca8cb5e2871dc4263435c5d9237fa7ffe5c |
File details
Details for the file micropython_max7219-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: micropython_max7219-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70b0c3ebf1485ef5d678a3ccfa8df7090003765d48771e9cbaffa2fa61889ab |
|
MD5 | 9c78d6faefe2c5953c66b2166decf71b |
|
BLAKE2b-256 | e0428c0686f4bc4eee3467326f89d07e97b89cc0211bb4c3c4b857acff9a5d20 |