LED Dot Matrix Display with ESP32 and MAX7219 (2024)

In this tutorial, we will learn to interface MAX7219 LED Dot matrix display with ESP32 development board. Firstly, we will look into the introduction, pinout of MAX7219 LED dot matrix display module. It is an LED array used to display various types of texts, symbols, and images in the form of dots which consists of LEDs. Through this tutorial, we will familiarize you with the MAX7219 dot matrix display and program ESP32 to show various demonstrations of displaying texts. These will include displaying and scrolling text on the dot matrix.

LED Dot Matrix Display with ESP32 and MAX7219 (1)

We have a similar guide with Arduino and ESP8266 NodeMCU:

  • MAX7219 LED Dot Matrix Display Interfacing with Arduino
  • MAX7219 LED Dot Matrix Display with ESP8266 NodeMCU

Table of Contents

MAX7219 LED Dot Matrix Display

MAX7219 LED Dot matrix display is one of the popular ones available in the market and used by students, electronics hobbyists, and especially in industrial display applications. There are two types of modules generally available. These are the FC-16 module and the generic module.

LED Dot Matrix Display with ESP32 and MAX7219 (2)

Each module consists of two units. One is the 8X8 LED dot matrix and the other is the MAX7219 IC.

LED Dot Matrix Display with ESP32 and MAX7219 (3)

You can find more information about MAX7219 here:

MAX7219 8-Digit LED Display Driver

LED Dot Matrix

LED dot matrices are available in various dimensions (7×5,8×8, 7×15, etc). The typical 8×8 LED matrix is shown below which comprises of 64 LEDs, 8 for each row and column. Each LED is addressed by its row and column number. Each LED is referred to as a dot.

For making an 8×8 dot matrix all the anodes terminals are connected together in rows R1 to R8, similarly, the cathodes are connected together in columns C1 to C8. The reason for connecting all rows and columns together is to save the required number of pins to control each LED dot. By doing this, the required number of I/O pins has been reduced to 16. Otherwise, we will need 64 pins to control an 8×8 LED matrix. This method of controlling a large number of LEDs with few pins is known as multiplexing.

To Turn on a specific do, we need to apply a positive voltage to the respective row of that dot and negative or ground to the respective column of that dot. If the row gets positive voltage and the column gets negative then only a particular LED will glow.

For example, If you want to glow an LED connected between R2 and C1, we have to apply 00000010 logic on row R2 and 11111110 on column C1. If R5 is pulled high and C4 pulled low, then the LED in the fifth row and the fourth column would be high. Similar logic can also be applied to other rows and columns to turn on and off each row and column LED. Furthermore, to display text on the dot matrix, we control each LED very fast speed that the human eye feels like LEDs are constantly on.

LED Dot Matrix Display with ESP32 and MAX7219 (4)

MAX7219 IC

MAX7219is a common-cathode display driver IC with serial inputs and output pins. It has an adjustable current capability which can be set using only one external resistor. In addition to that, it has a four-wire serial interface that can be easily connected to all microprocessors. It can drive 64 individual LEDs connected at its output pins using only 4 wires by using the microcontroller. Furthermore, it can drivedot matrix displays,7-Segments displays,and bar graphs.

LED Dot Matrix Display with ESP32 and MAX7219 (5)

On top of that, MAX7219 has a built-in BCD decoder that makes it easy to use with seven segment numeric displays. Additionally, it has an 8×8 static RAM that we can use to store numbers. It is one of the most popular displays driver IC.

Some key features of MAX7219 include:

  1. It is an LED driver display IC with a 10MHz serial interface which allows the user to select the decode/No-Decode digit.
  2. Its operation is specified in a voltage range of +4.0 to +5.5V. Normally, the voltage supply of +5V is used.
  3. It provides a feature of digital and analog brightness intensity control and a 150µA shutdown mode in which the current of all segments is pulled to ground.
  4. It consumes very low power.
  5. The data is displayed on segments with a delay time of 2.2ms.
  6. MAX7219 works well in a temperature range of 0°C to +70°C.
  7. The maximum current for each segment pin is 100mA and for each DIGIT ground pin is 500mA

MAX7219 Dot Matrix Module Pinout

The MAX7219 module has 5 terminals consisting of SPI and power supply terminals. Both types of modules have the same connections on two sides. On one side are the input connections and on the other side are the output connections Below you can view the pinout of the generic module.

LED Dot Matrix Display with ESP32 and MAX7219 (6)

Input Connections

The input connections of the LED matrix are connected with the ESP32 board.

  • VCC: This pin supplies power to the MAX7219 module. It is connected with Vin pin of ESP32 if the brightness is set to half value.
  • GND: This is the ground pin which should be connected with the ground pin of ESP32.
  • DIN: This is the data in pin. It is used as the SPI input to the module.
  • CS: This is the Chip Select pin for SPI communication.
  • CLK: This is called the ‘Serial Clock’ pin which is used in SPI serial clock output.

Output Connections

The output connections of the LED matrix are connected with the next module if there is a need to attach more units.

  • VCC: It is connected to VCC (5V) on the next module
  • GND: It is connected to the GND on the next module
  • DOUT: This is the Data out pin. It is connected to DIN pin of the next module.
  • CS: This is connected to the CS pin of the next module
  • CLK: This is connected to the CLK pin of the next module

MAX7219 LED Dot Matrix Module Interfacing with ESP32

Following components are required:

  • ESP32 board
  • MAX7219 module
  • Connecting Wires

For this project, we will be using the FC-16 module consisting of four units.

LED Dot Matrix Display with ESP32 and MAX7219 (7)

Now, we will show you how to connect the MAX7219 module and the ESP32 board together. The table below shows the default SPI pins for ESP32.

Pin NamesESP32 Pin
MOSIGPIO23
MISOGPIO19
SCKGPIO18
CSGPIO5

The figure below shows the default SPI pins of ESP32.

LED Dot Matrix Display with ESP32 and MAX7219 (8)

Now let us see how to connect the MAX7219 module and the ESP32 board. The table below shows the connections between the two devices:

MAX7219 ModuleESP32 Pin
VCCVin
GNDGND
DINGPIO23
CSGPIO5
CLKGPIO18

As shown from the table, we will connect the VCC terminal of the MAX7219 module with the Vin of the ESP32 board. This is because we will keep the brightness of the display at minimum inside the program sketch. Otherwise, use a separate 5V supply. Both grounds will be common. The default SPI GPIO pins of ESP32 are being used to connect with each of the remaining SPI terminals of the MAX7219 module.

LED Dot Matrix Display with ESP32 and MAX7219 (9)

Installing MAX7219 Arduino Libraries

We will use Arduino IDE to program our ESP32. Make sure you have the latest version of the IDE installed in your system. To program our ESP32 board with the MAX7219 module we will be required to install two libraries: MD_MAX72XX by MajicDesigns and MD_Parola. These two libraries will make it very easy to program our development board.

We will use the Arduino Library Manager to install these two libraries. Open your Arduino IDE and go to Sketch > Library > Manage Libraries. Type ‘MD_MAX72XX’ in the search bar and press enter. Install the library that is highlighted below.

LED Dot Matrix Display with ESP32 and MAX7219 (11)

Now type ‘MD_Parola’ in the search bar and press enter. Install the library that is highlighted below.

LED Dot Matrix Display with ESP32 and MAX7219 (12)

After installing both the libraries, restart your IDE.

ESP32 with MAX7219 LED Matrix: Arduino Sketches

In this section, we will show you how to use MAX7219 LED matrix with two sketches. We will be able to print various texts in different alignments on the LED matrix. Additionally, we will also scroll a simple text from right to left.

MAX7219 Dot Matrix displaying texts Arduino Sketch

Open your Arduino IDE and go to File > New. Copy the code below in that file. This sketch will display a simple text on the LED matrix in the following alignments:

  • Left
  • Right
  • Centre
  • Background invert

You will have to specify your model type and the maximum number of devices (dot matrix displays) for the sketch given below to work properly.

#include <MD_Parola.h>#include <MD_MAX72xx.h>#include <SPI.h>// Uncomment according to your hardware type#define HARDWARE_TYPE MD_MAX72XX::FC16_HW//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW// Defining size, and output pins#define MAX_DEVICES 4#define CS_PIN 5MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);void setup() { Display.begin(); Display.setIntensity(0); Display.displayClear();}void loop() { Display.setTextAlignment(PA_LEFT); Display.print("ESP32"); delay(2000); Display.setTextAlignment(PA_CENTER); Display.print("ESP32"); delay(2000); Display.setTextAlignment(PA_RIGHT); Display.print("ESP32"); delay(2000); Display.setTextAlignment(PA_CENTER); Display.setInvert(true); Display.print("ESP32"); delay(2000); Display.setInvert(false); delay(2000);}

How the Code Works?

In this part we will discuss how the code works.

Including Libraries

Firstly, we will include all the necessary libraries for this project. We are including SPI.h as we are using SPI communication protocol between the two devices. Moreover, we have included the MAX7219 module libraries that we previously installed for the proper functionality of the LED matrix.

#include <MD_Parola.h>#include <MD_MAX72xx.h>#include <SPI.h>

Defining LED matrix type

Secondly, it is very important to define the correct type of MAX7219 LED matrix that you are using. We are using FC16. If you are using the generic model instead of FC16 then uncomment the second line and comment the line where we are defining FC_16HW.

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_H

Defining number of MAX7219 ICs

Thirdly, we will define the maximum number of ICs in our LED matrix. As we are using FC16 model thus it consists of four 8×8 LED arrays. Hence our maximum devices are 4.

#define MAX_DEVICES 4

The next step is to specify the CS pin’s connection with the ESP32. It is pin 5.

#define CS_PIN 5

We will then create an instance of MD_Parola library called ‘Display’ that will be set to the MD_Parola() function which takes in three arguments. The first argument is the hardware type. The second argument is the ESP32 pin connected with CS. Lastly, the third argument is the number of MAX7219 ICs. We have defined all of these parameters earlier.

MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

setup()

Inside the setup() function, we will initialize the LED matrix by using the begin() function.

Display.begin();

We will set the brightness to a minimum by passing 0 as a parameter inside setIntensity(). This function takes in values from 0-15 where 15 is the highest intensity. Moreover, we will clear the display by using displayClear().

Display.setIntensity(0);Display.displayClear();

loop()

Inside the loop() function we will continuously change the alignment of the text “ESP32.” After every 2 seconds, we will change the alignment of the text.

First we will set the text “ESP32” aligned to the left for 2 seconds. This will be achieved by using setTextAlignment() and passing ‘PA_LEFT’ as a parameter inside it.

Display.setTextAlignment(PA_LEFT); Display.print("ESP32"); delay(2000);

Likewise, we will align the ESP32 text to centre and right as well by passing the respective alignment as an argument inside the setTextAlignment() function.

 Display.setTextAlignment(PA_CENTER); Display.print("ESP32"); delay(2000); Display.setTextAlignment(PA_RIGHT); Display.print("ESP32"); delay(2000);

Next, we can also invert the display by using the setInvert() function and passing ‘true’ as a parameter inside it. Moreover, if we pass ‘false’ as an argument inside the function then the display goes back to its initial one.

 Display.setTextAlignment(PA_CENTER); Display.setInvert(true); Display.print("ESP32"); delay(2000); Display.setInvert(false); delay(2000);

Demonstration

To see the demonstration of the above code, upload the code to the ESP32 board. But, before uploading code, make sure to select ESP32 Dev Module from Tools > Board and also select the correct COM port to which the ESP32 board is connected from Tools > Port.

LED Dot Matrix Display with ESP32 and MAX7219 (13)

Once the code is uploaded to ESP32, the LED matrix will start displaying the text in various alignments.

Watch the video below:

MAX7219 Dot Matrix Arduino Sketch: Scrolling Text

Open your Arduino IDE and go to File > New. Copy the code below in that file. This sketch will scroll a text from right to left at a set speed.

#include <MD_Parola.h>#include <MD_MAX72xx.h>#include <SPI.h>// Uncomment according to your hardware type#define HARDWARE_TYPE MD_MAX72XX::FC16_HW//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW#define MAX_DEVICES 4#define CS_PIN 5MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);void setup() { Display.begin(); Display.setIntensity(0); Display.displayClear(); Display.displayScroll("SCROLL", PA_RIGHT, PA_SCROLL_LEFT, 150);}void loop() { if (Display.displayAnimate()) { Display.displayReset(); }}

How does Code Works?

We will discuss the parts where we are incorporating the scrolling feature. Rest of the code is similar to the one which we discussed above.

setup()

Inside the setup() function, after initializing the LED matrix, setting its brightness and clearing the display, we will call the displayScroll() function to set up the scrolling action. This function takes in four arguments. The first parameter is the text that you want to scroll. In our case the text is ‘SCROLL.’ The second parameter is the alignment of the text in case of a delay. This we have set to ‘PA_RIGHT’. The third argument is the direction of the scroll. We have set it to ‘PA_SCROLL_LEFT’ that means the text will scroll towards the left side. Lastly, the fourth parameter is the time in milliseconds between the text frames. The higher the value the slower will be the movement of the text.

 Display.displayScroll("SCROLL", PA_RIGHT, PA_SCROLL_LEFT, 150);

loop()

Inside the loop() function, we will use an if statement with the displayAnimate() function that will start the scrolling of the text. This will return true after each scroll is completed then the displayReset() function will be called to reset the display. Thus, the text scrolls indefinitely.

void loop() { if (Display.displayAnimate()) { Display.displayReset(); }}

Demonstration

To see the demonstration of the above code, upload the code to ESP32. But, before uploading code, make sure to select the ESP32 board from Tools > Board and also select the correct COM port to which the ESP32 board is connected from Tools > Port.

LED Dot Matrix Display with ESP32 and MAX7219 (14)

Once the code is uploaded to ESP32, the SCROLL text will start scrolling towards the left side. This will happen continuously.

Conclusion

In conclusion, we have learned to interface MAX7219 dot LED matrix display module with ESP32. We have examined two example sketches. These sketches familiarized us with displaying plain text on the display in various alignments and also scrolling it at a set speed.

You may also prefer to study other examples on MAX7219:

  • 8×8 LED Matrix Interfacing with MAX7219 and Pic Microcontroller
  • MAX7219 Interfacing with 8-digit 7 Segment Display and PIC16F877A
LED Dot Matrix Display with ESP32 and MAX7219 (2024)

FAQs

How does MAX7219 work? ›

MAX7219CNG is a programmable display driver integrated circuit that is used to control a large array of LEDs while consuming a relatively small number of GPIO pins. It receives input commands via four SPI pins, and uses these commands to drive either an 8x8 matrix of LEDs, or an eight-digit seven-segment display.

What does the MAX7219 module do? ›

Lesson 15 MAX7219 LED Dot Matrix Module - YouTube

What is MAX7219? ›

MAX7219 IC is a serial input/output common-cathode display driver that is used to connect microprocessors with a 7-segment LED display or 64 individual LEDs or bar-graph displays.

How does an LED dot matrix work? ›

You turn on an individual LED by setting its row and column pins to the proper polarity. For example, referring to figure 3, in the CCAR matrix on the left the switch in row 1 is closed (shown in red) causing a positive voltage level to be applied to the anodes of all of the LEDs in that row.

How do you control LED matrix? ›

To control an individual LED, you set its column LOW and its row HIGH. To control multiple LEDs in a row, you set the row HIGH, then take the column high, then set the columns LOW or HIGH as appropriate; a LOW column will turn the corresponding LED ON, and a HIGH column will turn it off.

How do you drive a dot matrix display? ›

So you can drive a row of LEDs by pulling the column connection to ground. A dot matrix led display is simply a grid of LEDs arranged for use by multiplexing.
...
Project details.
Dot matrix LED display Project
CompilerMikroelectronika MikroC Compiler Free!
Project version1.04
6 more rows

How do I create a dot matrix display? ›

Large LED Dot Matrix Display Board - YouTube

How do you make a dot matrix with LED? ›

Make Your Own LED Matrix Display Using Arduino With ... - YouTube

What is 8x8 LED matrix? ›

As you can observe, an 8×8 LED Matrix consists of 16 pins: 8 Rows and 8 Columns. Usually, the Rows are associated with the Anodes of the LEDs and the Columns are associated with the Cathodes of the LEDs.

How many dots are on 8x8 dot matrix? ›

The Dot Matrix Display

A typical single color 8×8 dot matrix unit has 16 pins, 8 for each row and 8 for each column.

What is a LED driver IC? ›

An LED driver IC is an integrated circuit (IC) that provides brightness control and backlighting color control. They are usually found in an LED driver circuit, which can be used to test an LED in order to maintain brightness and increase LED life.

How use 8x8 LED matrix Arduino? ›

How to control 8x8 1088AS LED Matrix with Arduino, without drivers ...

What is the meaning of LED display? ›

a flat-screen device in which an array of light-emitting diodes can be selectively activated to display numerical and alphabetical information, used esp in pocket calculators, digital timepieces, measuring instruments, and in some microcomputers.

What is a LED matrix? ›

An LED matrix or LED display is a large, low-resolution form of dot-matrix display, useful both for industrial and commercial information displays as well as for hobbyist human–machine interfaces. It consists of a 2-D diode matrix with their cathodes joined in rows and their anodes joined in columns (or vice versa).

Top Articles
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 5958

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.