ESP8266 - LED Matrix

This tutorial instructs you how to use ESP8266 with LED matrix display. In detail, we will learn:

Once that is done, it will be simple to modify the code for other LED matrices, such as a 16x8 LED matrix or a 64x8 LED matrix ...

Hardware Preparation

1×ESP8266 NodeMCU
1×Micro USB Cable
1×FC-16 LED Matrix 32x8
1×FC-16 LED Matrix 8x8
1×Generic LED Matrix 8x8
1×Jumper Wires
1×Breadboard
1×DC Power Jack
1×5V Power Adapter for ESP8266
1×(Optional) Screw Terminal Expansion Board for ESP8266

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of LED Matrix

LED matrix displays are commonly referred to as LED displays or dot matrix displays.

LED Matrix display

LED Matrix come in many varieties. The MAX7219-based LED matrix is popularly used with ESP8266. It has the following characteristics:

  • A single block consists of an 8x8 LED matrix (64 LED) and a MAX7219 driver.
  • There are two common types of blocks: generic module and FC-16 module.
  • You can either purchase a pre-made multi-block LED Matrix (e.g. 4-in-1, 8-in-1) or wire multiple blocks together to create a LED matrix of your desired size.
  • The size of the LED matrix you use must be declared in the ESP8266 code.

The LED Matrix Pinout

LED Matrix pinout

A LED Matrix is made up of one or more blocks. Each block has two sets of pins:

  • Input pins group:
    • VCC: connected to 5V power supply.
    • GND: connected to ground.
    • DIN: Data pin, connected to any digital pin of the ESP8266.
    • CS: Chip Select, connected to any digital pin of the ESP8266.
    • CLK: Clock pin, connected to any digital pin of the ESP8266.
  • Output pins group:
    • VCC: connects to VCC on the next block.
    • GND: connects to GND on the next block.
    • DOUT: Data Out, connects to the DIN pin of the next block.
    • CS: connects to CS on the next block.
    • CLK connects to CLK on the next block.

Wiring Diagram

If the LED matrix is made of a single block:

  • Connect the input pins to ESP8266
  • Leave the output pins unconnected
The wiring diagram between ESP8266 NodeMCU and 8x8 LED matrix FC-16

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

The wiring diagram between ESP8266 NodeMCU and 8x8 LED matrix generic

This image is created using Fritzing. Click to enlarge image

If the LED matrix is pre-built of multiple blocks:

  • Connect the input pins group to ESP8266
  • Leave the output pins group unconnected
The wiring diagram between ESP8266 NodeMCU and LED matrix display

This image is created using Fritzing. Click to enlarge image

If you are making the LED matrix out of multiple blocks:

  • Connect the input pins groups of the first block to ESP8266
  • Connect the output pins groups of each block to the input pins groups of the subsequent block
  • Leave the output pins group of the final block unconnected
ESP8266 NodeMCU 32x8 LED matrix wiring FC-16 diagram

This image is created using Fritzing. Click to enlarge image

Due to the high current draw of the display (up to 1A at maximum brightness):

  • Avoid powering it from the 5V pin of ESP8266.
  • Utilize an external 5V power supply instead. ESP8266 and LED matrix can both be powered by a single 5V power adapter.

Since ESP8266 is connected to the LED matrix through SPI pins:

  • Pin D5 (SCK) and D7 (MOSI) on the ESP8266 must be utilized. If a different ESP8266 board is being used, consult the official documentation to find the equivalent SPI pins.
  • Pin D8 (CS) can be set to any pin on the ESP8266 board.

How To Program For LED Matrix

It is not a simple task to control the LED matrix. Fortunately, libraries are available which make it much easier. Here is a step-by-step guide on how to write ESP8266 code for controlling the LED matrix:

  • Incorporate libraries:
#include <MD_Parola.h> #include <MD_MAX72xx.h>
  • Specify the type of hardware to be utilized: GENERIC_HW or FC16_HW.
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
  • Specify the number of LED blocks used. For instance, a 4-in-1 LED matrix contains 4 blocks.
#define MAX_DEVICES 4
  • Specify the pin that is connected to the CS pin of the LED matrix. For instance, pin D3.
#define CS_PIN D8
  • Generate a MD_Parola object to be used with the LED matrix display.
MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  • Code located in the setup() function:
void setup() { ledMatrix.begin(); // initialize the object ledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15) ledMatrix.displayClear(); // clear led matrix display }
  • Display text, numerical values, and animated effects: refer to the following section.

ESP8266 - LED Matrix Code

This code is suitable for a 32x8 FC-16 LED matrix display consisting of four blocks. It can be easily adapted to other sizes such as 8x8, 16x8, and 64x8.

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-led-matrix */ #include <MD_Parola.h> #include <MD_MAX72xx.h> #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 // 4 blocks #define CS_PIN D8 // create an instance of the MD_Parola class MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void setup() { ledMatrix.begin(); // initialize the LED Matrix ledMatrix.setIntensity(15); // set the brightness of the LED matrix display (from 0 to 15) ledMatrix.displayClear(); // clear LED matrix display } void loop() { ledMatrix.setTextAlignment(PA_LEFT); ledMatrix.print("Left"); // display text delay(2000); ledMatrix.setTextAlignment(PA_CENTER); ledMatrix.print("Center"); // display text delay(2000); ledMatrix.setTextAlignment(PA_RIGHT); ledMatrix.print("Right"); // display text delay(2000); ledMatrix.setTextAlignment(PA_CENTER); ledMatrix.setInvert(true); ledMatrix.print("Invert"); // display text inverted delay(2000); ledMatrix.setInvert(false); ledMatrix.print(1234); // display number delay(2000); }

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Connect ESP8266 to the LED matrix as shown in the wiring diagram.
  • Connect the ESP8266 to a PC with a USB cable.
  • Click to the Libraries icon on the left bar of the Arduino IDE.
  • Search for “MD_Parola”, then locate the MD_Parola library.
  • Press the Install button.
ESP8266 NodeMCU MD_Parola library
  • You will be asked to install the “MD_MAX72XX” library
  • Click Install All button to install the dependency.
ESP8266 NodeMCU MD_MAX72XX library
  • The message
  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button on the Arduino IDE to compile and upload the code to the ESP8266.
  • Check out the LED matrix displaying the message.

ESP8266 LED Matrix Code – Scrolling Text

If a message is too lengthy to be displayed on a LED matrix, the scroll text effect can be used. This allows for the entire message to be seen.

This ESP8266 code illustrates how to scroll a message across a LED matrix display.

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-led-matrix */ #include <MD_Parola.h> #include <MD_MAX72xx.h> #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 // 4 blocks #define CS_PIN D8 // create an instance of the MD_Parola class MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void setup() { ledMatrix.begin(); // initialize the object ledMatrix.setIntensity(15); // set the brightness of the LED matrix display (from 0 to 15) ledMatrix.displayClear(); // clear led matrix display ledMatrix.displayScroll("ESP8266", PA_CENTER, PA_SCROLL_LEFT, 100); } void loop() { if (ledMatrix.displayAnimate()) { ledMatrix.displayReset(); } }

If you are looking for further text effects, check out the MD_Parola Library Reference.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!