8000 GitHub - enchant97/micropython-max7219: MicroPython driver for MAX7219 8x8 LED matrix modules, cascadable and with framebuf
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

enchant97/micropython-max7219

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroPython Max7219 8x8 LED Matrix

PyPI PyPI - Implementation PyPI - Python Version PyPI - License PyPI - Downloads

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)

Format Options

Setting the different format options for the display.

#Test Different Format Options

from framebuf import MONO_HLSB, MONO_HMSB, MONO_VLSB

display = max7219.Matrix8x8(spi, ss, 1, MONO_VLSB)
display.fill(0)
display.text("P")
display.show()
time.sleep(0.5)
display = max7219.Matrix8x8(spi, ss, 1, MONO_HMSB)
display.fill(0)
display.text("P")
display.show()
time.sleep(0.5)
display = max7219.Matrix8x8(spi, ss, 1, MONO_HLSB)
display.fill(0)
display.text("P")
display.show()

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

License

Licensed under the MIT License, found in LICENSE.txt.

About

MicroPython driver for MAX7219 8x8 LED matrix modules, cascadable and with framebuf

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages

  • Python 100.0%
0