Home

Awesome

SmartMatrix::GFX, Control Scan Based Matrices with SmartMatrix and Adafruit GFX API

Please have a look at this blog post for more details and pictures: http://marc.merlins.org/perso/arduino/post_2019-04-01_SmartMatrix_-SmartMatrix-Shield-v4-for-Teensy_-ESP32-shield-with-level-shifter_-and-SmartMatrix_GFX.html

for details, how these panels actually works have a look on this sparkfun post.they have a nice article if you want to understand in depth. https://www.sparkfun.com/news/2650

Adafruit_GFX and FastLED-compatible library for RGBPanels (row scan matrices).
This library requires FastLED and Adafruit_GFX libraries as well as this base class library:

Example demo code: https://github.com/marcmerlin/FastLED_NeoMatrix/blob/master/examples/MatrixGFXDemo/MatrixGFXDemo.ino388

This library requires SmartMatrix, Adafruit_GFX, and FastLED libraries.

(technically it can work without FastLED, but it's convenient to use the FastLED CRGB representation and in turn, it gives extra primitives that can be used against pixels, defined here: https://github.com/FastLED/FastLED/blob/master/pixeltypes.h#L90 )

This library offers the same API than https://github.com/marcmerlin/FastLED_NeoMatrix/ , but for a SmartMatrix backend (the mapping function not being that useful since SmartMatrix takes care of giving X/Y coordinate mapping for you, but in theory if you have a weird SmartMatrix panel chaining layout not supported by SmartMatrix itself, SmartMatrix::GFX's mapping function could take care of this for you).

As explained below, you can target these 3 APIs and SmartMatrix::GFX will support them on top of SmartMatrix:

You can find a lot of demo code here:
https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos as well as a big integrated demo here: https://github.com/marcmerlin/NeoMatrix-FastLED-IR

This code was taken from FastLED_NeoMatrix and adapted to work with the SmartMatrix library. SmartMatrix is used to drive row scan panels. They are not as good as NeoPixel based panels which you can run with FastLED::NeoMatrix instead, but you should consider SmartMatrix driven panels if one of those reasons apply to you:

While I do recommend that you use Neopixel matrices whenever you can as for their much better display quality, brightness, and being easier to drive, if you decide to use scan based matrices for the reasons above and you'd like Adafruit::GFX compatibility, then this library is for you.

It also offers FastLED compatibility if you'd like to use those primitives against your virtual display (like nblend, fade, etc...).

Here is an example of FastLED LEDMatrix code running on top of SmartMatrix::GFX. This is an example of 64x96 mirrored for a total of 128x96: image

SmartMatrix and SmartMatrix::GFX on ESP32

Have a look at http://marc.merlins.org/perso/arduino/post_2019-04-01_SmartMatrix_-SmartMatrix-Shield-v4-for-Teensy_-ESP32-shield-with-level-shifter_-and-SmartMatrix_GFX.html#ESP32 for tips on how to use SmartMatrix on ESP32.
Here is a picture of protoboard with level shifters vs a nicer shielf from Jason Coon: image

Basic GFX Demo and Matrix config (SmartMatrix or FastLED NeoMatrix)

Sample code: https://github.com/marcmerlin/SmartMatrix_GFX/blob/master/examples/MatrixGFXDemo/MatrixGFXDemo.ino
MatrixGFXDemo.ino hardcodes the SmartMatrix config and it's the simplest implementation.

All other demos however use this common config.h which can be adjusted to use:

See: https://github.com/marcmerlin/SmartMatrix_GFX/blob/master/examples/config.h
Sample usage: https://github.com/marcmerlin/SmartMatrix_GFX/blob/master/examples/fontzoom/fontzoom.ino Many more demos compatible with SmartMatrix::GFX:
https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/

Here is an example of https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/blob/master/FastLED/Sublime_Demos/Sublime_Demos.ino running on 2 64x64 Matrices. Top one is run by teensy 3.6 with SmartShield v4, and bottom one is ESP32 on a protoboard with level shifters: image

RGB Panels vs NeoPixels and other addressable LEDs

Neopixels and other pixels like APA102 have their own chip for each pixel that
take care of accepting a 24bit (or better) color value and then refreshing the
LED to get that color value for you with no work from you.
RGB Panels have no such smarts and require you to constantly refresh every LED and even create colors by flashing each R G B pixel between on and off at the right speed to create intensities and color mixes. RGB Panels are cheaper, not as bright, and have much better density (due to lack of per pixel controlling chips).

Tutorials:

Adafruit::GFX vs SmartMatrix vs FastLED APIs

Years ago, back when we only had 8x8 displays, Adafruit wrote a nice API, https://github.com/adafruit/Adafruit-GFX-Library . It is in no means perfect or exhaustive, but it does what most people need, including font support. Its huge strength is how it works many different hardware backends, all the way back to 8x8 matrices. See this example of code working on 3 different hardware backends all using the same GFX demo code: http://marc.merlins.org/perso/arduino/post_2017-04-24_Adafruit-GFX-on-NeoMatrix-and-RGB-Matrix-Panel-Demo.html https://www.youtube.com/watch?tv=9yGZLtewmfI

Now Adafruit::GFX has a drawback nowadays which is how it only supports color in 16 bits (RGB 565). Honestly it is good enough for most displays that aren't good enough to show 16,777,216 colors, and if you care, there is a bypass to drawPixel that lets you draw in 24bit color.

Now, SmartMatrix comes with a much fancier API with multiple layers (used for scrolling on top of drawings), better color resolution, and many more things. It's just a better API all around, but it is not compatible with Adafruit::GFX code.
This is where https://github.com/marcmerlin/SmartMatrix_GFX comes in: it adds Adafruit::GFX support to SmartMatrix. Similarly, you can use https://github.com/mrfaptastic/ESP32-RGB64x32MatrixPanel-I2S-DMA which also offers GFX support to a more limited set of RGB panels but with DMA support on ESP32 (read below for differences).

FastLED is not a 2D API per se, but used along with https://github.com/marcmerlin/FastLED_NeoMatrix you can get GFX API support while adding FastLED primitives like nscale and fade. SmartMatrix::GFX adds support for both GFX and FastLED API support to the SmartMatrix backend.

If you will ever only use SmartMatrix, you should use its superior API. If you'd like to be compatible with other backends, including better FastLED supported matrices (Neopixels and better addressable LEDs don't flicker, are brighter and easier to drive), and the GFX API is good enough for you, you should use it, along with SmartMatrix::GFX and you'll be able to trivially port your code to many other hardware backends.

Adafruit_RGB_matrix_Panel vs SmartMatrix vs ESP32-RGB64x32MatrixPanel-I2S-DMA vs SmartMatrix::GFX

The first 3 libraries all support HUB75 RGB Panels, although not in the same way.

How to integrate SmartMatrix::GFX with your project

Have a look at neomatrix_config.h.it explains pretty much everything. It is where you need to define smartMatrix/neomatrix/fasled arguments. For more details as to why neomatrix_config.h, see http://marc.merlins.org/perso/arduino/post_2020-03-16_Framebuffer_GFX_-Choosing-between-its-3-2D-APIs_-FastLED-XY_-NeoMatrix_-and-LEDMatrix_-and-detail-of-its-many-supported-hardware-backends.html
and lots of demos here:
https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos

Microcontroller support and level shifters

If you use the newer and faster microcontrollers, they are 3.3V and it is greatly recommended that you use level shifters (74HCT245 or equivalent).

For ESP32 and/or Smartmatrix with SmartMatrix::GFX have a look on this blog post. http://marc.merlins.org/perso/arduino/post_2019-04-01_SmartMatrix_-SmartMatrix-Shield-v4-for-Teensy_-ESP32-shield-with-level-shifter_-and-SmartMatrix_GFX.html