Hello today I am going to show you how to effectively control a MAX7219 with an ESP32 using micropython, don't worry this will be extremely easy and I will try to explain it as best as possible.
Let's go to the objects we are going to use in this project:
First of all we will obviously need an ESP32, but also a MAX7219, remember that the MAX7219 is only a controller to be able to modify 8 LEDs as we want, but nothing prevents us from assembling 4 of these MAX7219 and controlling one total of 32 independent LEDs.
I'm not going to teach you a physics lesson, but if you want me to explain to you in a very detailed way how the MAX7219 works, don't hesitate to ask me questions in the comments.
But the simple operation is; we send a signal from our ESP32 and we announce to the MAX7219 which led we want to flash and at what frequency, so simple that we will immediately see how to connect it to our ESP32 to make it work in the best possible way:
You will have to follow exactly this connection to be able to continue in this example, but nothing prevents you from connecting the CS and the CLK where you want. Following this bravo you have made the most complicated of the work what remains is quite easy.
First of all in your prefer IDE you will have to import the library that I would put you here:
Only the "max7219.py" file is needed, then in your main you need to import it like this:
import max7219
from machine import Pin, SPI
import time
import machine
Then you will have to do this so that the ESP32 can know where it is the MAX7219
spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(4), mosi=Pin(2))
ss = Pin(5, Pin.OUT)
display = max7219.Matrix8x8(spi, ss, 4)
Of course you can change the "display" variable to anything, but I would use that for now.
Okay, you're just done, to display any text you do this:
display.text("TechMo the best",0,0,1)
With that you put your text in the parentheses and the x and y position of the text in the MAX7219 and the color in 1 because otherwise we do not see anything.
Oh yes. Remember you must always put this at the end of what you want to display because otherwise it will simply not be displayed:
display.show()
And There you go.
The tutorial is finished, I wish you a very pleasant day :)
Comments