esp32-hub75-matrixpanel-dma
repository·master·Indexed 23 days ago
https://github.com/mrcodetastic/esp32-hub75-matrixpanel-dmaA high-performance ESP32 library for driving HUB75/HUB75E RGB LED matrix panels using hardware-backed DMA (LCD Mode). It supports various driver chips including FM6126A, ICN2038S, FM6124, and MBI5124. The library includes the VirtualMatrix class for chaining multiple panels into a single virtual display grid and provides support for ESP-IDF and Arduino frameworks. Features include animated GIF decoding via the AnimatedGIF library, XBM bitmap conversion, and tools for calibrating pixel mapping on four scan panels.
What's inside esp32-hub75-matrixpanel-dma
- The repository contains several examples designed for different skill levels and hardware configurations. Use these to understand how to display shapes, patterns, GIFs, and bitmaps, or how to handle specific panel types like FM6126 or chained panels.
Estimating fillrate for DMA buffer operations
masterWhen calculating the performance of your LED matrix application, note that filling the DMA buffer involves heavy bit-level memory operations rather than simple byte/word stores. This makes the process computationally intensive for both the ESP32 core and the compiler.
Performance varies significantly based on the method used to update the screen. For example, using specialized 'Fast' methods (like
fast-V-lineorfast-H-line) is substantially more efficient than using standarddrawPixelmethods. When benchmarking your own setup, consider the following patterns used in testing:clearScreen(): Full blanking of the buffer.fillScreenRGB888(): Filling with monochrome or gray colors.drawPixel(): Individual pixel updates.fillRect(): Drawing rectangles over the matrix.- Line drawing: Using standard vs. fast line methods.
Brightness control for FM6126A chips via REG1
masterThe FM6126A chip features two control registers: REG1 (written with 12 clock pulses) and REG2 (written with 13 clock pulses).
Users can achieve fine-grained hardware brightness control across the entire matrix by toggling specific bits in REG1 instead of bitbanging RGB or EO pins. This can significantly reduce power consumption and offload processing from the ESP32.
REG1 Bit Mapping
- Bits 6 to 11: Increase brightness (relative to all-zeroes).
- Bits 2 to 5: Decrease brightness.
- Bit 1: Unclear influence on brightness/power.
Power Consumption Reference
For 2x 64x64 panels filled with white, the following bit patterns in REG1 correspond to approximate current draws:
REG1 Bit Pattern Current (Amps) 0111111 00000>5.000 A 0100010 000003.890 A 0010000 000002.490 A 0001000 000001.750 A 0000000 000000.995 A 0000000 111100.686 A How the Animated GIF SDCard example works
masterThe
AnimatedGIFPanel_SDexample uses the 'Animated GIF' library by Larry Bank and the Espressif SD/File system library for Arduino.Note on Pin Configuration: Because the SD Card requires specific pins, some default HUB75 pins must be remapped to accommodate the SD Card hardware. Refer to the wiring diagram in the repository for the specific pinout used in this example.
Understand External RAM (PSRAM) performance and restrictions on ESP32-S3
masterUsing External RAM on the ESP32-S3 introduces specific behaviors regarding cache and memory access:
- Cache Dependency: External RAM shares the same cache region as external flash. Accessing large chunks of data (>32 KB) may exceed cache capacity, causing performance to fall back to the slower external RAM access speed. This can also 'push out' cached flash, potentially slowing down code execution.
- Flash Cache Disabling: If the flash cache is disabled (e.g., during a flash write operation), External RAM becomes inaccessible. Any attempt to read or write to it during this time will trigger an
illegal cache access exception. - Task Stacks: By default,
xTaskCreate()and similar functions allocate task stacks and TCBs in internal memory, not external RAM, to avoid issues when the flash cache is disabled.
Supported ESP32 variants and hardware requirements
masterThis library utilizes the ESP32's 'LCD Mode' DMA for high-speed data output.
Supported Hardware:
- Original ESP32 (ESP-WROOM-32 / ESP32-D0WDQ6)
- ESP32-S2
- ESP32-S3
Unsupported Hardware:
- RISC-V ESP32s (e.g., ESP32-C3) because they lack 'LCD mode' support.
- ESP32-S3 boards with poor PCB design (e.g., Adafruit MatrixPortal S3) may experience WiFi interference due to high-frequency DMA output.
Memory Considerations:
- The DMA buffer consumes internal SRAM. For the original ESP32, you are limited to the available free internal SRAM (typically ~200KB).
- For the ESP32-S3, you can use OCTAL SPI-RAM (PSRAM) (e.g., N8R8 variant) to drive the DMA buffer, but this limits the maximum output frequency to ~13MHz, which may cause flicker when chaining multiple panels. Do not use QUAD SPI (Q-SPI) PSRAM as it is too slow.
Chain multiple LED Matrix Panels using VirtualMatrixPanel
masterTo create a larger display by connecting multiple LED Matrix Panels, use the
VirtualMatrixPanelclass. Examples demonstrating this include:ChainedPanels: Basic implementation of chaining panels.ChainedPanelsAuroraDemo: Demonstrates a large-scale plasma animation across chained panels.ChainedPanelsScreenBuffer: CombinesVirtualMatrixPanelwith a FastLED off-screen pixel buffer for advanced rendering techniques.
Chain multiple LED matrix panels
masterYou can chain multiple HUB75 panels together to create larger displays:
- Horizontal Chaining: Connect panels in series using the HUB75 ribbon cable to create a single long virtual matrix (e.g., two 64x32 panels to make a 128x32 display). You must configure the class constructor to treat them as "one long virtual matrix chain". See the
Pattern Plasmaexample for configuration details. - Grid Chaining (2x2, etc.): To create a grid (e.g., four 64x32 panels in a 2x2 arrangement to make a 128x64 display), use the
VirtualMatrixPanelorAuroraDemoexamples for the necessary configuration logic.
Warning: Resolutions exceeding 128x64 are prone to crashes due to ESP32 SRAM memory constraints.
- Horizontal Chaining: Connect panels in series using the HUB75 ribbon cable to create a single long virtual matrix (e.g., two 64x32 panels to make a 128x32 display). You must configure the class constructor to treat them as "one long virtual matrix chain". See the
Hardware requirements: Power supply and Capacitors
masterA robust power supply is critical. For chained LED panels, it is highly recommended to solder a 1000-2000uF capacitor across the GND and VCC pins of each LED panel. This prevents 'flashy' graphics caused by current/power draw peaks and troughs when many LEDs turn on or off simultaneously.
Note on Voltage: Some panels may not work well with the 3.3V signal provided by the ESP32 GPIO pins.
How VirtualMatrixPanel_T works for pixel re-mapping
masterThe
VirtualMatrixPanel_Tclass is an abstraction used to perform pixel re-mapping. It allows you to decouple the logical display coordinates from the physical wiring of the LED panels. This is useful for two primary scenarios:- Creating larger displays from chained panels: When panels are connected in a non-standard physical order (like a grid or a serpentine/zig-zag pattern),
VirtualMatrixPanel_Tmaps a single large virtual display area to the multiple physical panels. - Supporting non-standard scan types: It provides support for panels with non-standard pixel mapping, such as 1/4 scan outdoor panels, which are not natively supported by the core library.
By using this class, you can draw to a single large virtual display, and the library handles the complex math of routing those pixels to the correct physical location and scan sequence.
- Creating larger displays from chained panels: When panels are connected in a non-standard physical order (like a grid or a serpentine/zig-zag pattern),
Understand the Aurora Demo architecture
masterThe Aurora Demo is a complex example that demonstrates how to combine multiple libraries to create a large-scale visual display. It uses three core components:
- ESP32-HUB75-MatrixPanel-DMA: Used to drive physical LED panels. It utilizes the
VirtualMatrixclass to chain multiple physical panels together into a single, larger virtual display grid. - GFX_Lite: A simplified graphics library used to draw effects on the virtual display. It is a fork of
AdaFruitGFXandFastLEDdesigned for ease of use. - VirtualMatrix: An abstraction within the DMA library that allows graphical effects to treat a collection of chained panels as one continuous coordinate system.
- ESP32-HUB75-MatrixPanel-DMA: Used to drive physical LED panels. It utilizes the
How to use 64x64px (HUB75E) panels
masterTo use a 64x64 pixel square panel, which is typically a HUB75E panel, you must configure a validE_PINin your pin mapping and connect it to the 'E' pin on the LED matrix panel.