ESP32 32x8 LedMatrix
#include <>
Demo 5: How to use Arduino ESP32 to display information on SPI LED matrix
Tech It Yourself 8:53 AM
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:
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]
[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:

https://github.com/nhatuan84/esp32-led-matrix

After downloading, unzip and copy the unzipped folder under folder:

C:/Users/[YOUR_USER_NAME]/Documents/Arduino/libraries

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:
/*H********************************************************************
*
**********************************************************************/
#include 
#include "LedMatrix.h"

//************************* DEFINES ************************************

//************************* PROTOTYPES ************************************

//************************* VARIABLES ************************************
#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);

/*F********************************************************************
*
**********************************************************************/
void 
setup() 
{
	ledMatrix.init();
	ledMatrix.setText("EasyIoT");
}
/*F********************************************************************
*
**********************************************************************/
void 
loop() 
{
	ledMatrix.clear();
	ledMatrix.scrollTextLeft();
	ledMatrix.drawText();
	ledMatrix.commit();
	delay(50);
}
4. Result


Figure: ESP32 connect to LED matrix