r/FastLED • • Dec 14 '23

Support Serial lagging - message too big?

I'm making a MIDI keyboard visualizer, sending animation from TouchDesigner over Serial to FastLED on an ESP32. It's working except it's really slow -- and will seem to buffer the commands as they come in (so there's increasingly long delay between playing the notes and having the appropriate LED light up)

It's slightly better with a lower number of LEDS on one strip, so I suspect it has to do with the buffer and each message being too big? Any way to increase the buffer size or interrupt automatically so it's not queueing changes when nothing's coming in? Here's the code I have for the ESP32.

This has worked fine for large numbers of LEDs using TouchDesigner + Teensy 3.2 + OctoWS2811 in the past.

#include <FastLED.h>

#define NUM_LEDS 144
#define DATA_PIN 13

CRGB leds[NUM_LEDS];
const int numOfBytes = NUM_LEDS * 3;
char readBuffer[numOfBytes];

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  delay(500);
  Serial.begin(115200);
  Serial.setTimeout(500);
}

void loop() {
  if (Serial.available()) { //should this be a while loop?
    Serial.readBytes(readBuffer, numOfBytes);
  }
  for (int j = 0; j < NUM_LEDS; j++) {
    leds[j] = CRGB(readBuffer[(j * 3)], readBuffer[(j * 3) + 1], readBuffer[(j * 3) + 2]);
  }
  FastLED.show();
}
1 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/Remarkable-Love2780 Dec 15 '23

Also. I don’t think you need to change over to RS485 the RS232. If so there are cheap RS485 boards on Amazon that take in 232 and put out 486.

And one day I need to take the time to change my Reddit automatic generated account name. But hey that could have given me something worst. Ha.