Serial control of 128 LED with TLC5940, buffer size problem?


I’m trying to send a string of 128 digits (each from 0 to 9) from a third party software through serial to arduino to have individual control over each of the 128 LED.
Right now i’m using only one TLC5940, but i’m planning to daisy chain 7 more for the final project.
Everything is almost working, but i’m facing a refresh rate problem.
I would ideally like to send 24 strings / seconds, to get a 24fps “video display”, which would make a 30720 bit/s.
I tried to play with the number of digits and the refresh rate to see how things are reacting.
What I get so far is:
24Hz for 8 digits / 12Hz for 32 digits / 6Hz for 128 digits.

Somebody suggested it could be a problem with arduino’s serial buffer size. I tried to change it to 256 bytes, looking to different tutorials, I don’t know if I actually managed, but nothing changed in my application.

Other possibility would be that the cycle of the Tlc5940 is too slow, but then it shouldn’t work at the expected speed when i’m sending only 8 digits, since my code is going through 128 values anyway…

Here is my code bellow, any suggestion is welcomed since i’m really stucked now…


String readString;

int valn = 0;

void setup() {

void loop() {
  while (Serial.available()) {
    char c =;  //gets one byte from serial buffer
    readString += c; //makes the string readString
  } //slow looping to allow buffer to fill with next character
for (int i = 0; i<128 ; i++) {
  if (readString.length() >0) { 
    valn = (readString.substring(i,i+1)).toInt();
    valn = map(valn,0,9,0,4095);
    Tlc.set(i , valn);
      readString = "";

You are troubled by speed and yet you put a 2mS delay in and expect that to help!

Either check that there are as many bytes as you want to read already in the buffer before you read them OR check there is something in the buffer before you read each one.

Why play about with strings anyway? It is very inefficient. If you pack them you can get two LEDs worth of data in three bytes.

So 128 LEDs at 1.5 bytes per LED is 192 bytes. In serial you need 10 bits per byte so that is 1920 bits per refresh and 24 refreshes per second is 4096 bauds. So your serial baud rate of 115200 is fine.

Thanks @Grumpy_Mike ! You actually got it right in!

That was actually do to this delay.... (bad idea to stupidly copy and paste parts of code without thinking...) erasing the delay was actually causing some flickering on the LED, but I turned it down to 200 microseconds, and it's working perfectly now!