Set buffer from serial data

I’m trying to set the matrix data from data streaming over Serial, coming from my animation library:
I used to use the old FastLED interface, but needed to update to SM3 so that I could use the > 32x32 matrix size functionality. However, I cannot find any real details on setting the buffer all in one go. So far, I’ve got the follow (simplified for clarity):

#define COLOR_DEPTH 24                  // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 32;        // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 32;       // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36;       // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4;       // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN;   // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE);      // see for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);

uint16_t numLEDs = (kMatrixWidth * kMatrixHeight);
rgb24 * _LEDS;

void setup(){
    _LEDS = (rgb24*)malloc(sizeof(rgb24)*numLEDs);
    memset(_LEDS, 0, sizeof(rgb24)*numLEDs);


void loop() {
    static uint16_t size = 0;
    static uint16_t count = 0;
    static uint16_t packSize = numLEDs * 3;
    if (Serial.available())
        count = 0;
        while (count < packSize - 1)
            c = Serial.readBytes(((char*)_LEDS) + count, packSize - count);
            count += c;


All I could find that even looked close was setBackBuffer on the BackgroundLayer class, but event though it looks like the data is getting sent over, nothing ever appears on the matrix.

Is there a better way to do this?

Hi Adam,

The FastLED_Functions example uses backbuffer, maybe you can start with that and modify it to meet your needs. The backgroundBuffer already includes two rgb24 buffers, one currently being used for refresh and another for drawing, so you (probably) don’t need to use malloc in your sketch.

If you need to have a third buffer so you can receive data during the brief period where both buffers are being used after a swapBuffers() call, then you’d have to use setBackBuffer(). I don’t know of any currently working sketches that use setBackBuffer(). I believe it was added by Daniel Garcia from FastLED for the now broken “SMART_MATRIX” controller in FastLED. If you really need it, post back and we’ll get it figured out.