LED - 8. RGB LED Matrix Drive with ESP 8266 and Electrogragon shield

last updated 2020.04.17 : update for ESP32

I like MCUs like arduino uno, esp8266, esp32. But I prefer single-board computers like Raspberry Pi and Jetson Nano. This is because a single-board computer can install Linux and use great tools like OpenCV. However, many makers are using the Arduino-based mcu and often produce amazing results. The RGB LED drive library for the ESP8266 and ESP32, which will be introduced in this post, also demonstrates great features.

I received an RGB LED matrix shield for ESP8266 from Electrodragon a few days ago.
After receiving this product, I also looked at how to drive the RGB LED matrix using the ESP8266.
<Electrodragon ESP8266 RGB LED sheild>

This product has the same pin configuration as the shiled product made by Brian Lough. Brian Lough's products are available at https://www.tindie.com/products/brianlough/d1-mini-matrix-shield/ for 14$. And Electrodragon products are available for purchase for $ 3.4 at https://www.electrodragon.com/product/rgb-dot-matrix-display-drive-wifi-board-esp8266/.


The RGB LED matrix receives and operates a 5V signal. However, the ESP8266's digital pins turn the 3.3V voltage on and off. Therefore, depending on your RGB LED Matrix, the following may or may not work.  The following is a part of datasheet of P3 64X32 RGB LED Matrix.


Depending on the 74HC245 series chips used in the RGB LED Matrix, the 3.3V voltage may not be recognized.
It can also be more affected by the voltage drop along the length and thickness of your signal cable. Using a 5V logic voltage with a level shifter is the safest way. The Raspberry Pi HAT introduced earlier in my other blogs contains a chip that boosts the 3.3V logic voltage to 5V.
If you've worked correctly after following Brian Lough's article, and you don't get it to work, the cause may be a logic level. In this case, don't use the shield and try using the level shifter to change the logic voltage between the D0-D8 pins of the ESP8266 board and the HUB75 connector. However, the 64X32, 64X64-sized Chinese matrices I tested worked fine at 3.3V.

Much of this post has been taken in the article by Brian Lough.


Installing ESP8266 software to your Arduino IDE

This article assumes you have Arduino IDE installed on your computer and know how to use it.
To use the display we are also going to need to install some ESP8266 libraries.
The first one we need to install is the PXMatrix Library by 2Dom. It is in the process of being released to the library manager but at the time of writing this Instructable the library is only available through Github.





First visit the esp8266 github page(https://github.com/esp8266/Arduino#installing-with-boards-manager).  Read the README.md  file carefully.

Installing with Boards Manager

  • Install the current upstream Arduino IDE at the 1.8.7 level or later. The current version is on the Arduino website.
  • Start Arduino and open the File -> Preferences window.
  • Enter https://arduino.esp8266.com/stable/package_esp8266com_index.json into the Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  • Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).
If you installed ESP8266 libraries successfully, you might check the result at Tools->Board Manager..

Installing USB drivers

Many Chinese clones use the CH340 USB chip. If your ESP8266 uses a CH340 chip, download and install the driver from the following site(https://wiki.wemos.cc/downloads)
If you are using the CP2104 chip, download and install the driver from the following page(https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers).
For reference, you can read the model number from the board's USB chip.

Testing the ESP8266

After installation, connect the ESP8266 to your PC using a USB cable and select the port from the Arduino IDE menu Tool-> Port.

  • In File->Examples->ESP8266->Blink, select the "Blink" example. 
  • Click the upload icon, then the source code is compiled and transfer the ececutable to the ESP 8266.
  • After the trasfering is completed, the ESP8266's LED might blink.
If you are having trouble getting to this point, the following YouTube videos will help you.

Installing PxMatrix library to your Arduino IDE

At https://github.com/2dom/PxMatrix, download the zip file.


Go to the "Sketch ->Include Library -> Add .ZIP Library", then select the zip file you downloaded. This youtube video will help you.




Installing the Adafruit GFX library to your Arduino IDE

Go to the "Sketch ->Include Library ->Manage Libraries", then search "Adafruit GFX library", then install it.



Electrodragon ESP8266 shield Wiring

Once the software installation is complete, it is time to connect the ESP8266 shield and the RGB LED matrix. 

The shiled I received looks like this.

 <https://www.electrodragon.com/product/rgb-dot-matrix-display-drive-wifi-board-esp8266/>


Because this product has a simple structure, I made a circuit diagram using a multimeter.

If both dip switches are ON, the connection is as follows.


The above picture is the same configuration as the following picture shown at http://blough.ie/d1mat/ explained by Brion Lough.
<picture from http://blough.ie/d1mat/>

Dip switch configuration

In the picture above, please look closely at the line connected to the D3 pin of ESP8266. If you are using 1/32 scan mode, you should use this pin. In the figure below, the C and D pins are used in most cases, so there is no need to worry.


Some of the pins are not needed depending on what display you have, these are the C, D and E pins. The library lists instructions for when you need to connect up these pins based on the scan rate of your display:

Display PinESP8266 PinNote
C15 (D8)Only for 1/8, 1/16, 1/32 scan
D12 (D6)Only for 1/16, 1/32 scan
E0 (D3)Only for 1/32 scan

The best way to check if they are required for your display is they seem to be connected to ground on displays where they are not needed. Get your multimeter in continuity mode and check these pins against the ground pin, if the pin is connected to ground you don't need it.


  • If the C pin of your matrix is connected to the GND, turn off number 5 on the bottom dip switch.
  • If the D pin of your matrix is connected to the GND, turn off number 3 on the bottom dip switch.
  • If the E pin of your matrix is connected to the GND, turn off number 4 on the top dip switch.


In most case, 64X64 matrix has 1/32 scan mode and we must supply E pin signal. 


64X64 Matrix and Electrodragon Shield

Connect shiled to RGB LED matrix and connect to HUB75 cable as the following picture. Since the E pin will also be used, turn all dip switches on. It is not necessary to connect the 5V power supply of the RGB LED matrix in shiled. You can connect them separately as shown. In this case, the 5V power supplied to the shield is used to operate the ESP8266.


<ESP8266 RGB shield on the 64 X 64 RGB LED matrix>

The two HUB75 out sockets on the shield are exactly the same, so you can connect them to either.


Test

In your Arduino IDE, go to File -> Examples -> Px Matrix and open the pixeltime example.

Then modify this code for your wiring configuration. If D, E pin is connected, use the last line, or only D pin is connected, use the second line.

//PxMATRIX display(32,16,P_LAT, P_OE,P_A,P_B,P_C);
//PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
PxMATRIX display(64,64,P_LAT, P_OE,P_A,P_B,P_C,P_D,P_E);
<original code>

And modify the matrix size. I' using the 64X64 size and I connected D, E pins. So my last modified code is like this.

//PxMATRIX display(32,16,P_LAT, P_OE,P_A,P_B,P_C);
//PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
PxMATRIX display(64,64,P_LAT, P_OE,P_A,P_B,P_C,P_D,P_E);
...........
  
#define matrix_width 64
#define matrix_height 64

...........

display.begin(32);

<customized code>

Raise the frequency of the ESP8266 to 160 MHz. Go to "Tools-> CPU Frequency" and set it to 160MHz.
Then upload the code to the ESP8266.

Tip : There is no need to define ESP8266 separately. This value is set by default inside the library. Define it only when using ESP32("#define ESP32" at the code beginning).

 

More fun

Download the source code from https://github.com/2dom/PxMatrix/blob/master/examples/mario_image_fm6216a_esp32/mario_image_fm6126a_esp32.ino . This sample is named esp32, but it works well on esp8266. And since the example is tailored to a 64X64 matrix, there is not much to modify.
However, since the test code is not properly customized in the loop function, it is better to test it after modifying it.


int cnt = 0;
void loop() {
  cnt++;
  delay(1000);
  display.clearDisplay();

  // drawImage2(0, 16);

  uint32_t x = 1;
  uint32_t y = 1;
  if(cnt == 1)
  {
     drawImage2(0, 0);
//    drawImage(x, y, myWHITE);
    Serial.println("test white");
  }
  else if(cnt == 2){
    drawImage2(0, 8);
//    drawImage(x, y, myRED);
    Serial.println("test red");
    // cnt = 0;
  }
  else if(cnt == 3){
    drawImage2(0, 16);
//    drawImage(x, y, myGREEN);
    Serial.println("test green");
    // cnt = 0;
  }
  else if(cnt == 4){
    drawImage2(0, 24);
//    drawImage(x, y, myBLUE);
    Serial.println("test blue");
    //cnt = 0;
  }
  else if(cnt == 5){
    drawImage2(0, 32);
    Serial.println("test blue");
    // cnt = 0;
  }
  else if(cnt == 6){
    drawImage2(0, 0);
    Serial.println("test reset");
    cnt = 0;
  }

}


If you see this animation, it works perperly.


Driving the 64X32 LED matrix with Electrodragon HAT

This time, we will drive the 64X32 RGB LED matrix. There are many interesting examples of this size matrix. There are many examples you can test on Brian Lough's github.

Disable E pin with the upper dip switch on the shield


Pitch (mm) Size Resolution Rows-scan pattern
P6 192mmx96mm 32x16 1/2, 1/4 or 1/8
P10 320mmx160mm 32x16 1/2, 1/4 or 1/8
P4 128mmx128mm 32x32 1/8 or 1/16
P5 160mmx160mm 32x32 1/8 or 1/16
P6 192mmx192mm 32x32 1/8 or 1/16
P7.62 244mmx244mm 32x32 1/8 or 1/16
P2.5 160mmx80mm 64x32 1/16
P4 256mmx128mm 64x32 1/16
P5 320mmx160mm 64x32 1/16
P2.5 160mmx160mm 64x64 1/32
P3 192mmx192mm 64x64 1/32

As you can see from the table above, most 64x32 matrix has 1/16 scan mode. Therefore, there is no need to use the E pin. Turn off number 4 of the upper dip switch to which the E pin is connected.

Midifying the shield

There was no problem when the shield was inserted into the matrix of 64X64 size, but when the shield was inserted into the matrix of 64X64 size, a slight problem occurred. Cut out the protruding part at the bottom of the shield as shown in the following figure.



Test

This time, we will use Brian Lough's banana example(https://github.com/witnessmenow/LED-Matrix-Display-Examples/blob/master/LED-Matrix-Banana-Dance-Display/LED-Matrix-Banana-Dance-Display.ino).

Customize the code

The content below may vary slightly depending on the type of LED matrix you use. If it doesn't work, try changing the settings to find the one that fits your matrix.


// PxMATRIX display(32,16,P_LAT, P_OE,P_A,P_B,P_C);
// PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
PxMATRIX display(64, 32, P_LAT, P_OE, P_A, P_B, P_C, P_D, P_E);
<original code>


// PxMATRIX display(32,16,P_LAT, P_OE,P_A,P_B,P_C);
PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
//PxMATRIX display(64, 32, P_LAT, P_OE, P_A, P_B, P_C, P_D, P_E);
<modified code>

The setup function contains "display.begin(16)". The 16 means 1/16 scan mode. And this value works fine for most 64X32 matrices. If your matrix is ​​not in 1/16 scan mode, test it by modifying this value to 4,8,16,32. In my case, there was no need to modify.


void setup() {
  display.begin(16);
  display.clearDisplay();
  
  display_ticker.attach(0.002, display_updater);
  yield(); 
}

Now build the source code in the Arduino IDE.

Trouble Shooting


When running for the first time, it was found that only half of the screen is displayed as follows.


You can find the answer of this problem at https://github.com/2dom/PxMatrix .

  • Some panels have a slow multiplexer and only a partial image is displayed. To remedy this you can add some delay to the multiplexing using, for example, display.setMuxDelay(1,1,1,1,1) which would add a 1us delay to each of the A-E channels.
So I added display.setMuxDelay(1,1,1,1,1) at the setup function.
void setup() {
  display.setMuxDelay(1,1,1,1,1);
  display.begin(16);
  display.clearDisplay();
  
  display_ticker.attach(0.002, display_updater);
  yield(); 
}

Now it looks good!


This is my 64X32 matrix and the Electrodragon shield.


WiFi-Tetris-Clock

I have tested Brian Lough's Tetris watch. But it does not work on ESP8266 with this error message. Brian also says that the ESP8266 sample code does not work.

User exception (panic/abort/assert)
Panic core_esp8266_main.cpp:121 __yield

You can check the source code here(https://github.com/witnessmenow/WiFi-Tetris-Clock).
If you want to implement the Tetris-Clock, use ESP32 instead of ESP8266. I don't know if Electrodragon sells a shield for ESP32, but Brian sells this product at https://www.tindie.com/products/brianlough/esp32-matrix-shield-mini-32/. You can also use this product or connect a Dupont cable directly to the ESP32 board without a shield.
Oneday, I will see how to connect ESP32 directly to the RGB matrix.

I've post a ESP32 related article at the https://iot-for-maker.blogspot.com/2020/04/led-9-rgb-led-matrix-drive-with-esp-32.html. In this post, Wifi-Tetris-Clock is implemented.

Wrapping up

RGB LED Matrix control using ESP8266 and ESP32 is difficult to support multiple LEDs using daisy connection. Therefore, in my opinion, using Raspberry Pi Hat seems more stable and scalable. And one thing to keep in mind is the logic voltage. Arduino uses 5V logic voltage, so there is no problem, but boards like ESP8266, ESP32, Teensy use 3.3V logic voltage. Fortunately the above example worked, but there is no guarantee that the RGB LED matrix using 5V logic voltage will operate at 3.3V logic voltage. In addition to Electrodragon's shield, Brian Lough's shield does not use a logic level shifter. Due to this structural weakness, new RGB panels may not work at any moment.

You can download the source codes at https://github.com/raspberry-pi-maker/IoT/tree/master/led8-esp8266 .




댓글

  1. LED 디스플레이를 제어하는 법을 검색하다 우연히 발견했습니다.
    딱 제가 찾던 내용이네요.
    정말 감사합니다.
    그런데 electrodragon 홈페이지에서 구매하실 때 배송 옵션은 무엇을 선택하셨나요?

    답글삭제
    답글
    1. 아마도 가장 저렴한 DHL-Packet Plus: DHL eCommerce Post로 했던 것 같습니다.
      이곳이 가격도 저렴한 편이고 물건도 잘 만듭니다.

      삭제

댓글 쓰기

이 블로그의 인기 게시물

LED-12. Displaying HDMI Contents

LED - 5. Raspberry Pi 4 + DietPi Buster + Electrodragon HAT - Part 1

LED-11. Make a very big size 384 X 512 RGB Matrix #6(final)