Anyone working on a MAX7219 8x8 LED matrix display library?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by mcauser » Sun Oct 01, 2017 2:16 pm

The visualisation tool produce bytes in the wrong format.
eg. "1" == 0x7e1818181c181800 == b'\x7e\x18\x18\x18\x1c\x18\x18\x00'
You'd need to reverse that to be b'\x00\x18\x18\x1c\x18\x18\x18\x7e'
Then convert from lsb to msb b'\x00\x18\x18\x38\x18\x18\x18\x7e'
Then draw each in the byte array down a single 8x8 segment.

Worth noting, my quad 8x8 module draws characters upside down compared to my individual 8x8 module boards.

Image

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by deshipu » Sun Oct 01, 2017 6:01 pm

I noticed you are mixing tabs and spaces in your code. This is a recipe for hard to find bugs, I really recommend configuring your text editor to use spaces all the time for Python code.

Otherwise, great work!

User avatar
benalb
Posts: 25
Joined: Fri May 19, 2017 1:23 pm

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by benalb » Sun Oct 01, 2017 6:01 pm

Is this library exclusive for pyboard?. I have tried wiht an esp8266 module (lolin nodemcu) with:

esp8266 max7219
3v VCC
GND GND
d7(Pin 13) MOSI DIN
d8(Pin 15) CS CS
d5(Pin 14) SCK CLK
And then:

Code: Select all

import max7219
from machine import Pin, SPI
spi = SPI(1)
display = max7219.Matrix8x8(spi, Pin(15), 1)
display.text('1',0,0,1)
display.show()
But the display lights all the leds, and nothing more.

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by mcauser » Sun Oct 01, 2017 11:29 pm

@deshipu fixed the tabs -> spaces. Thanks for that.

@benalb added ESP8266 eg to the readme. Had to drop the SPI freq from 80MHz to 10MHz to make it work.

User avatar
benalb
Posts: 25
Joined: Fri May 19, 2017 1:23 pm

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by benalb » Mon Oct 02, 2017 6:28 am

mcauser wrote:@benalb added ESP8266 eg to the readme. Had to drop the SPI freq from 80MHz to 10MHz to make it work.
:D It works now, Thank you, great work.

d4ß
Posts: 6
Joined: Thu Sep 28, 2017 10:19 am

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by d4ß » Thu Feb 15, 2018 5:02 pm

mcauser wrote:
Sun Oct 01, 2017 1:50 pm
I added cascading to deshipu's driver, and added framebuf to give text and shape support:
Works on my single 8x8 matrix, quad 8x8 matrices and 2x quad 8x8 matrices.
https://github.com/mcauser/micropython-max7219

Image

If you have a chain of 4x 8x8 matrices and you want to only update the 2nd matrix (closest to the DIN matrix), you need to send NOOPs to each of the other matrices. You write to the furthest away from DIN matrix first. For each row, the right most pixel is the least significant bit.

eg. Light the top row of the 2nd matrix and leave the others unchanged.

Code: Select all

_NOOP = const(0)

cs.low()
spi.write(bytearray([_NOOP, _NOOP]))
spi.write(bytearray([_NOOP, _NOOP]))
spi.write(bytearray([1, 255]))
spi.write(bytearray([_NOOP, _NOOP]))
cs.high()
Thank you mcauser.
Works well, only the scroll function is not performing as expected (maybe my bad?).
But I wrote my own:

Code: Select all

import max7219
from machine import Pin, SPI
import utime

class max7219_Scroll:  
    def __init__(self,CS,modules):
        self.CS = CS
        self.modules = modules
        self.spi = SPI(1, baudrate=10000000, polarity=0, phase=0)
        self.display = max7219.Matrix8x8(self.spi, Pin(self.CS), self.modules)
        
    def Scroll(self,tex, hell, repeat):
        self.display.brightness(hell)
        for r in range (0,repeat,1):
            for e in range (self.modules*8,-8*(self.modules+len(tex)),-1):
                self.display.fill(0)
                self.display.text(tex,e,0,1)
                self.display.show()
                utime.sleep(0.01)

DotMx=max7219_Scroll(2,4)
DotMx.Scroll(str('Hello, uPy!!!'),5,2)
{I am unable to attach a *.gif or *.m4a file to demonstrate the effect.}

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by mattyt » Fri Feb 16, 2018 3:24 am

Actually, I have a (currently quite hacky!) async scroll working against @mcauser's code somewhere. If anyone is interested I can polish it up and submit is as a pull request?

It's really not very different to @d4ß's solution (as I recall, add an async, sprinkle an await.asyncio.sleep...) but is non-blocking.

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by mcauser » Fri Feb 16, 2018 3:42 am

@d4ß The scroll method points to the FrameBuffer.scroll method:
http://docs.micropython.org/en/latest/w ... fer.scroll
It just shifts the contents of the FrameBuffer, leaving artefacts from the original buffer behind.
ie. if you scroll 1px from left to right, the 2 right most columns will be identical.

Your solution is similar to the one I recently created for a guy who emailed me asking similar.
We called it .marquee() after the obsolete html <marquee> tag.
https://developer.mozilla.org/en-US/doc ... nt/marquee
Currently supports left -> right, right -> left, up -> down, down -> up.
I wanted to add diagonal scrolling before I made a PR.
I'll share it soon.

I'm also working on a version where you can rotate individual matrices and arrange them in any order.
eg. 3x quad displays stacked in the shape of an S, or mixing quad displays with individual ones from different manufacturers where the orientation is different.

@mattyt an asyncio version sounds nice. I haven't played much with asyncio yet.
If you've got it working, submit a PR and I'll merge it in.
I'm going to add an examples folder with a ton of useful real world examples soon too.

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by mattyt » Sun Feb 18, 2018 9:56 pm

@mcauser if you have a neat marquee method then could you share that and I'll asyncify it? Better than having competing scroll methods, especially since my hacky solution only scrolls in one direction. :)

User avatar
RobH
Posts: 91
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: Anyone working on a MAX7219 8x8 LED matrix display library?

Post by RobH » Wed Apr 11, 2018 7:03 pm

Mike,
The MAX7219 driver works fine for me when using 'graphics' like pixel(), hline(), rect(), etc. but refuses to display text. And with scroll() the display blanks completely. I've tried with a single 8x8 and a quad 8x8, both with software-SPI and with ESP32 and ESP8266 with the latest firmware without success and without a clue what I could be doing wrong ;-) See also my code below.
Any suggestion?
Regards, Rob.

Code: Select all

# test quadruple 8x8 led matrix with max7219 controller on ESP8266
from machine import Pin, SPI
import max7219
from time import sleep
spi = SPI(-1, baudrate=1000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(0), miso=Pin(5))
d = max7219.Matrix8x8(spi, Pin(4), 4)
d.brightness(4)
d.text=("7219",0,0,1)
d.show()

Post Reply