MAX7219 on micro:bit
-
- Posts: 3
- Joined: Tue Jun 21, 2016 8:57 pm
MAX7219 on micro:bit
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
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
Re: MAX7219 on micro:bit
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?
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?
Re: MAX7219 on micro:bit
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.
It should work on the microbit fine, you just have to adapt the example code to use microbit's pins.
-
- Posts: 3
- Joined: Tue Jun 21, 2016 8:57 pm
Re: MAX7219 on micro:bit
thanks, i'll be sure to try it
Re: MAX7219 on micro:bit
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 :
Do you have a clue or a way to get additional information?
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:
Re: MAX7219 on micro:bit
Try:
SPI(1, baudrate=10000000, miso=Pin(12), mosi=Pin(13), sck=Pin(14))
http://docs.micropython.org/en/latest/e ... hlight=spi
SPI(1, baudrate=10000000, miso=Pin(12), mosi=Pin(13), sck=Pin(14))
http://docs.micropython.org/en/latest/e ... hlight=spi
Re: MAX7219 on micro:bit
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 :
Now, I have to figure out why I can't load a module on the micro:bit
Thanks for the help.
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()
Thanks for the help.
Re: MAX7219 on micro:bit
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().
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().
Re: MAX7219 on micro:bit
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.
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'