1. Introduction
This demonstration show you how to connect a LED Matrix module to Arduino ESP32 via MAX7219 module to display information from ESP32. There are 2 ways to connect ESP32 to LED Matrix module:
4. Result
This demonstration show you how to connect a LED Matrix module to Arduino ESP32 via MAX7219 module to display information from ESP32. There are 2 ways to connect ESP32 to LED Matrix module:
- Connect directly. By using this way, ESP32 will waste many GPIO pins (at lest 8x8 for 8x8 Led matrix).
- Connect via MAX7219 module. By using this way, ESP32 will only use 3 GPIO pins which act as SPI MOSI, CLK and CS pins. MAX7219 will be responsible for converting SPI data to LED Matrix data and control signals.
Figure: Led matrix
2. Hardware
Connect the pins of ESP32 to the pins of LED matrix:
[ESP32 GPIO14 - LED
CLK]
[ESP32 GPIO12 - LED DIN (MOSI)]
[ESP32 GPIO15 - LED CS]
[ESP32 GND - LED GND]
[ESP32 GND - LED GND]
[LED VCC - 5V]
or follow picture below:
Figure: ESP32 connect to LED matrix module
3. Software
We will use the
library MAX7219LedMatrix
that is made for Arduino but I modified a little to compatible with
ESP32. You can download the library here:
After downloading, unzip
and copy the unzipped folder under folder:
The library supplied
some functions:
- init(): to initialize library
- setText(): set the text to print on LED Matrix
- scrollTextLeft(): scroll text to left effect
- clear(): clear the display
- drawText(): start drawing text to buffer
- commit(): commit the text from buffer to LED Matrix
In order to use
these function you need to create an instance of LedMatrix
with constructor:
LedMatrix
ledMatrix=LedMatrix(NUMBER_OF_DEVICES, CLK_PIN, MISO_PIN, MOSI_PIN,
CS_PIN)
Note: NUMBER_OF_DEVICES number of cascading LED Matrix in a serial mode
Figure: 4 LED
Matrix in a serial mode
Finally, you create
an Arduino project and save it as esp32ledmatrix
with code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <SPI.h> #include "LedMatrix.h" #define NUMBER_OF_DEVICES 3 //number of led matrix connect in series #define CS_PIN 15 #define CLK_PIN 14 #define MISO_PIN 2 //we do not use this pin just fill to match constructor #define MOSI_PIN 12 LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN); void setup() { ledMatrix.init(); ledMatrix.setText("EasyIoT"); } void loop() { ledMatrix.clear(); ledMatrix.scrollTextLeft(); ledMatrix.drawText(); ledMatrix.commit(); delay(50); } |
4. Result
Figure: ESP32 connect to LED matrix
6 Comments
Nice job.
I've purchase a 4in1 display module and i've try your program.
The problem is the scroling direction.
Your program scrol the text left to right (or right to the left).
But the module are conected from the bottom to the top.
So i need o modify your program in order to scrol the text from the top of the lower display to the bottom of the next display.
(ie: i need to shift the data not on the column but on the row)
I don't kown if it's possible.
Cserélje ki a < LedMatrix.cpp > -ben a 102.sorban "void LedMatrix::commit()" részt az alábbiakra:
void LedMatrix::commit() { //shift the data not on the column but on the row
byte Jav_cols[32];
for (byte digit = 0; digit < 4; digit++){
for (byte sor = 0; sor < 8; sor++){
for (byte oszlop = 0; oszlop < 8; oszlop++){
bitWrite(Jav_cols[7-sor +(digit*8)], oszlop, bitRead(cols[oszlop+(digit*8)], sor)); }}}
for (byte digit = 0; digit < 4; digit++){
for (byte oszlop = 0; oszlop < 8; oszlop++){
sendByte(digit, oszlop, (Jav_cols[oszlop+24-digit*8]));
}}}
Im using your code but it has a line "ON" over the text. And text stay one pixel bellow... Do you know why?
I tried to see the code cpp but I dont understand so much :(
void LedMatrix::commit() {
//shift the data not on the column but on the row
byte Jav_cols[myNumberOfDevices * 8];
for (byte digit = 0; digit < 4; digit++) {
for (byte row = 0; row < 8; row++) {
for (byte column = 0; column < 8; column++) {
bitWrite(Jav_cols[7-row +(digit*8)], column, bitRead(cols[column+(digit*8)], row));
}
}
}
for (byte digit = 0; digit < 4; digit++){
for (byte column = 0; column < 8; column++){
sendByte(digit, column+1, (Jav_cols[column+24-digit*8]));
}}
}
how can I display static text ?
thanx
WAT CAN BE WRONG?