MAX7219 on micro:bit

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
MadBashify
Posts: 3
Joined: Tue Jun 21, 2016 8:57 pm

MAX7219 on micro:bit

Post by MadBashify » Tue Jun 21, 2016 9:04 pm

Hi,
I'm a student and I love python, I recently got my hands on a BBC micro:bit and while I was hunting around online I saw someone use a MAX7219 led matrix with micro:bit and the language Sniff. I later ordered the led matrix but I want to know how to get it to work with micropython and micro:bit.
Any help is appreciated.
Thanks
-Will

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

Re: MAX7219 on micro:bit

Post by deshipu » Wed Jun 22, 2016 8:10 am

Hi, I recently wrote a driver for the HT16K33-based LED Matrix backpacks (available at https://bitbucket.org/thesheep/micropython-ht16k33/src), and I think one for MAX7219 could look very similar. There are generally two approaches you can take to write such a driver.
The ambitious way (and usually giving better results) is to search for "max7219 datasheet", download the pdf, read it, figure out what commands need to be sent to the chip to make it work, and do that in the library. The bottom-feeder approach that I took is to take one or more existing libraries for other platforms, see what they do (optionally, using the datasheet, understand why), and do the same thing.

I have a MAX7219-based matrix at hand, so I can help you write the driver, if you want?

MadBashify
Posts: 3
Joined: Tue Jun 21, 2016 8:57 pm

Re: MAX7219 on micro:bit

Post by MadBashify » Wed Jun 22, 2016 2:34 pm

Ok, thanks.
-Will

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

Re: MAX7219 on micro:bit

Post by deshipu » Tue Jun 28, 2016 11:45 am

I took some time and wrote a simple driver for a single matrix: https://bitbucket.org/thesheep/micropyt ... max7219.py
It should work on the microbit fine, you just have to adapt the example code to use microbit's pins.

MadBashify
Posts: 3
Joined: Tue Jun 21, 2016 8:57 pm

Re: MAX7219 on micro:bit

Post by MadBashify » Tue Jun 28, 2016 2:37 pm

thanks, i'll be sure to try it

User avatar
titimoby
Posts: 18
Joined: Thu Sep 29, 2016 6:54 am

Re: MAX7219 on micro:bit

Post by titimoby » Sun Sep 10, 2017 3:22 pm

As soon as I can flash a micro:bit I'll give a try.

In the meantime, I tried with a Wemos D1 Pro flashed with micropython.
I got the following result when I try to get the Spi part :

Code: Select all

>>> import max7219
>>> from machine import Pin, SPI
>>> spi = SPI(10000000, miso=Pin(12), mosi=Pin(13), sck=Pin(14))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError:
Do you have a clue or a way to get additional information?

User avatar
Roberthh
Posts: 1046
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MAX7219 on micro:bit

Post by Roberthh » Sun Sep 10, 2017 3:27 pm

Try:
SPI(1, baudrate=10000000, miso=Pin(12), mosi=Pin(13), sck=Pin(14))

http://docs.micropython.org/en/latest/e ... hlight=spi

User avatar
titimoby
Posts: 18
Joined: Thu Sep 29, 2016 6:54 am

Re: MAX7219 on micro:bit

Post by titimoby » Sun Sep 10, 2017 4:41 pm

I had several issues here.
One was the way to call SPI because I mixed doc from a lib for microbit and one from adafruit (but from deshipu ion the end ;) )

I used the library : https://github.com/adafruit/micropython ... it-max7219
That I needed to edit to replace low() and high() calls with off() and on()

Then I used the exemple code :

Code: Select all

import max7219
from machine import Pin, SPI
spi = SPI(-1, 10000000, miso=Pin(12), mosi=Pin(13), sck=Pin(14))
display = max7219.Matrix8x8(spi, Pin(2))
display.fill(True)
display.pixel(4, 4, False)
display.show()
Now, I have to figure out why I can't load a module on the micro:bit

Thanks for the help.

User avatar
Roberthh
Posts: 1046
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MAX7219 on micro:bit

Post by Roberthh » Sun Sep 10, 2017 6:24 pm

Which error code do you get? The module may be too large, in which case an out-of-memory error is flagged.

The removal of pin.high() and pin.low() cause also some of my code to fail, and in my opinion pin.on() and pin.off() is only intuitive for LEDs or the like. Instead of pin.high() you could have used pin(1), and pin(0) for pin.low().

User avatar
titimoby
Posts: 18
Joined: Thu Sep 29, 2016 6:54 am

Re: MAX7219 on micro:bit

Post by titimoby » Mon Sep 11, 2017 5:43 pm

It works as I described for Wemos, no problem

For the micro:bit, I first had to discover the trick to add a library : flash the code, wait for the whole error message to scroll the micro:bit leds, then use the Files menu of Mu Editor.

But as I still got an import error, I tried to flash the whole library and I discovered that the module machine does not exists.

Code: Select all

>>> import machine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'machine'

Post Reply