ABOUT PORTFOLIO GAMES DEVLOG DOCS TOOLS CONTACT
HOME > DOCS > Embedded / IoT > ESP32 I2S DMA 기반 HUB75 RGB LED 매트릭스 패널 구동 및 더블 버퍼링Driving HUB75 RGB LED Matrix Panels with ESP32 I2S DMA and Double Buffering
Embedded / IoT Advanced ESP-IDF / Arduino

ESP32 I2S DMA 기반 HUB75 RGB LED 매트릭스 패널 구동 및 더블 버퍼링Driving HUB75 RGB LED Matrix Panels with ESP32 I2S DMA and Double Buffering

CPU 개입을 줄이고 I2S 병렬 DMA 엔진이 프레임 버퍼를 LED 패널로 연속 스트리밍하도록 구성하여 플리커 현상 없는 화면을 출력하는 하드웨어 제어 기법입니다.Streaming framebuffers continuously to HUB75 RGB LED matrix panels via the ESP32 I2S parallel DMA engine for flicker-free graphics without CPU bit-banging overhead.

#Embedded #ESP32 #HUB75 #DMA #Hardware
핵심 개념HUB75 규격 LED 매트릭스 패널(64×32 또는 64×64)은 자체 프레임 메모리가 없는 시프트 레지스터 구동 방식이므로, 초당 수천 번의 클럭(CLK), 행 주소(A/B/C/D/E), 래치(LAT), 출력 활성화(OE) 신호를 지속적으로 인가해야 깜빡임이 발생하지 않습니다. ESP32의 I2S 병렬 DMA(Direct Memory Access) 주변장치를 활용하면 CPU 연산 자원을 소모하지 않고도 안정적인 플리커 프리 화면을 출력할 수 있습니다.
Key ConceptHUB75 RGB LED matrix panels (64×32 or 64×64) use shift registers without an onboard framebuffer, requiring thousands of clock (CLK), row address (A/B/C/D/E), latch (LAT), and output-enable (OE) pulses per second to binary-code PWM brightness without flicker. Offloading this bitstream to the ESP32's I2S Parallel DMA (Direct Memory Access) peripheral refreshes the panel in hardware without tying up the CPU.

1. I2S DMA Matrix 패널 셋업 코드1. I2S DMA Matrix Panel Setup Code

hub75_dma_matrix.ino
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>

#define PANEL_RES_X 64
#define PANEL_RES_Y 32
#define PANEL_CHAIN 1

MatrixPanel_I2S_DMA *dma_display = nullptr;

void setup() {
    HUB75_I2S_CFG mxconfig(
        PANEL_RES_X,   // 단일 모듈 가로 픽셀 수
        PANEL_RES_Y,   // 단일 모듈 세로 픽셀 수
        PANEL_CHAIN    // 직렬 체인 연결 개수
    );

    // 하드웨어 핀 매핑 (ESP32 WROOM 기준)
    mxconfig.gpio.r1 = 25; mxconfig.gpio.g1 = 26; mxconfig.gpio.b1 = 27;
    mxconfig.gpio.r2 = 14; mxconfig.gpio.g2 = 12; mxconfig.gpio.b2 = 13;
    mxconfig.gpio.a = 23;  mxconfig.gpio.b = 19;  mxconfig.gpio.c = 5;
    mxconfig.gpio.d = 17;  mxconfig.gpio.e = -1;  // 64x32(1/16 스캔)는 E핀 미사용, 64x64(1/32 스캔)는 지정 필수
    mxconfig.gpio.lat = 4; mxconfig.gpio.oe = 15; mxconfig.gpio.clk = 16;

    mxconfig.double_buff = true; // 화면 찢어짐(Tearing) 방지용 더블 버퍼링 활성화

    dma_display = new MatrixPanel_I2S_DMA(mxconfig);
    dma_display->begin();
    dma_display->setBrightness8(64); // 밝기 설정 (0~255)
}

void loop() {
    dma_display->fillScreen(dma_display->color565(0, 0, 0));
    dma_display->drawString(4, 12, "LYSC*", dma_display->color565(255, 222, 89));
    dma_display->flipDMABuffer(); // 백 버퍼와 프론트 DMA 버퍼 스왑
    delay(33);
}
hub75_dma_matrix.ino
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>

#define PANEL_RES_X 64
#define PANEL_RES_Y 32
#define PANEL_CHAIN 1

MatrixPanel_I2S_DMA *dma_display = nullptr;

void setup() {
    HUB75_I2S_CFG mxconfig(
        PANEL_RES_X,   // Single module width in pixels
        PANEL_RES_Y,   // Single module height in pixels
        PANEL_CHAIN    // Number of daisy-chained modules
    );

    // Custom hardware GPIO mapping (for ESP32-WROOM)
    mxconfig.gpio.r1 = 25; mxconfig.gpio.g1 = 26; mxconfig.gpio.b1 = 27;
    mxconfig.gpio.r2 = 14; mxconfig.gpio.g2 = 12; mxconfig.gpio.b2 = 13;
    mxconfig.gpio.a = 23;  mxconfig.gpio.b = 19;  mxconfig.gpio.c = 5;
    mxconfig.gpio.d = 17;  mxconfig.gpio.e = -1;  // Unused on 64x32 (1/16 scan); required on 64x64 (1/32 scan)
    mxconfig.gpio.lat = 4; mxconfig.gpio.oe = 15; mxconfig.gpio.clk = 16;

    mxconfig.double_buff = true; // Enable double buffering to eliminate tearing

    dma_display = new MatrixPanel_I2S_DMA(mxconfig);
    dma_display->begin();
    dma_display->setBrightness8(64); // Brightness level (0~255)
}

void loop() {
    dma_display->fillScreen(dma_display->color565(0, 0, 0));
    dma_display->drawString(4, 12, "LYSC*", dma_display->color565(255, 222, 89));
    dma_display->flipDMABuffer(); // Swap back buffer and front DMA buffer
    delay(33);
}

2. 실무 적용 및 주의사항2. Practical Considerations and Caveats

  • 3.3V-5V 로직 레벨 시프터(74HCT245) 권장: ESP32의 GPIO 출력은 3.3V인 반면 HUB75 패널 드라이버 IC는 5V CMOS 로직 레벨을 기대합니다. 직결 시에도 동작하는 경우가 있으나 전원 전압이 조금만 흔들려도 픽셀 노이즈나 고스팅이 발생하므로 고속 버퍼 IC(74HCT245)를 거치는 것이 안정적입니다.
  • DMA 전용 내부 SRAM(Internal DRAM) 메모리 한계: I2S DMA 디스크립터와 비트플레인 버퍼는 외부 PSRAM이 아닌 내장 SRAM에 할당되어야 합니다. double_buff = true 활성화 시 메모리 사용량이 2배로 증가하므로, 다중 패널 체인이나 높은 색 깊이(setPanelBrightness) 설정 시 남은 힙 메모리를 반드시 확인해야 합니다.
  • 64×64 패널의 E 주소 핀(gpio.e) 설정: 64×32 패널은 1/16 스캔 방식이라 주소선이 A, B, C, D 4개뿐이지만, 64×64 패널은 1/32 스캔 방식을 사용하므로 커넥터의 8번 핀(또는 4번 핀)에 연결된 mxconfig.gpio.e 핀 번호(예: GPIO 18 또는 32)를 명시해야 화면 절반이 비는 현상을 막을 수 있습니다.
  • Use 3.3V-to-5V Level Shifters (74HCT245): While ESP32 GPIOs output 3.3V logic, HUB75 shift registers are 5V CMOS devices. Driving panels directly at 3.3V can cause pixel glitches or ghosting when supply voltage fluctuates; buffer data and clock lines through 74HCT245 transceivers.
  • Internal DMA-Capable SRAM Limits: I2S DMA bitplane buffers must reside in internal DRAM rather than external SPI PSRAM. Enabling double_buff = true doubles DMA RAM usage, so monitor free internal heap when chaining multiple panels.
  • Assign gpio.e for 64×64 (1/32 Scan) Panels: While 64×32 panels use 1/16 scan (4 row address pins: A, B, C, D), 64×64 panels use 1/32 scan and require a 5th address line (mxconfig.gpio.e) mapped to a valid GPIO.

I2S 병렬 DMA 스트리밍과 더블 버퍼링을 결합하면, Wi-Fi 통신이나 물리 연산이 동시에 도는 상황에서도 주사율 저하 없이 선명한 RGB 매트릭스 그래픽을 유지할 수 있습니다.

Combining I2S parallel DMA streaming with double buffering delivers tear-free, high-refresh RGB matrix rendering while leaving the ESP32 CPU cores free for Wi-Fi and game logic.

참고자료 & 관련 링크