Serial Data Being Read is Inconsistent

Hello, this is my first time posting to the forum so please let me know if I’m missing anything.

I want to control a string of WS2812 lights using an Arduino. The plan is to send serial to it from my computer (and eventually from a raspberry pi server) to tell the Arduino what colors each light should be. The problem is that the serial the Arduino is reading from the bus is inconsistent and leaves out several characters. If I send it a short string like !0,0,255,255,255; it can read and parse that no problem. However when I send it a string like !0,0,255,255,255;!1,0,255,255,255;!2,0,255,255,255;!3,0,255,255,255;!4,0,255,255,255;!5,0,255,255,255;!6,0,255,255,255;!7,0,255,255,255;!8,0,255,255,255;!9,0,255,255,255;!10,0,255,255,255; it will starting skipping random characters around the eight command and render the rest of the data useless.

Here’s the code I use to read the serial:

 char data[30];

void readSerial(){
  memset(data, 0, sizeof(data));
  int i = 0;
  unsigned long time = 0;
  while(Serial.available() > 0){
    time = micros();
    char c =;
    if(c != '\n'){
      if(c != '!'){
        data[i] = c;
      //if the end of a command is detected(;) process data[] immediately
      if(c == ';'){
        memset(data, 0, sizeof(data));
        i = -1;
      //Give the serial bus some time for the next character to load in
      if(micros()-time < 2000/dataMod){delayMicroseconds(2000/dataMod);}

Here’s what the serial monitor shows me when I send it 10 commands in one transmission.
I’d appreciate any help I can get to make this communication more consistent.

Have a read of Robin2's excellent tutorial Serial Input Basics to see how to read in serial properly without using delay and waiting for everything.

+1 for using code tags on your first post!

Get rid of this:

 if(micros()-time < 2000/dataMod){delayMicroseconds(2000/dataMod);}

It serves no useful purpose, and is likely allowing the 64 byte receive buffer to over-flow.

Ray L.

Reading Robin2's tutorial (Particularly example 5 about receiving multiple numbers) did the trick. I've been able to bump my baud rate up to 115200 with very minor issues.