How to synchronize serial data with data visualization?

edited February 2018 in Arduino

Hi Guys!

So I am working on a serial Grapher for my diploma thesis and I stumbled over a problem. The serial data which I am receiving is beeing written in the standard serial buffer, but my data visualization is extremely deferred! I've tried to clear the buffer everytime I put the data in the graph but I am using a serial protocoll called SvVis which also send the ID of the Channel. An now it messes some of my channels up because it's not matching anymore because some data is missing everytime.

      cha = serialPort.readChar();
        ch = cha;   
         if(ch == 10){  //ID = 10 -> String: end marked with 0
            String message=SvVisReadString(serialPort);
          else if(ch>0 && ch< 10)//2 Byte Data in 3.13 format
            println("3.13 Format");

          else if(ch>10 && ch<21){ //2 Byte Data (short Little Endian)
            println("Port "+ch+ " Data: " + data);
            String datastring = Integer.toString(data);

          else if(ch>20 && ch<31){ //4 Byte Data (float Little Endian)
            println("ID" + id + " Data: " + float_data);
            String datastring = Float.toString(float_data);


Is there a working way to synchronize my serial data input with my visualization? I've tried different solutions with lastChar() and buffer() but i didn't get it to work.


  • one way that i've found to synchronize serial data (coming from an arduino) is putting a timestamp on the serial data

  • Hey!

    So I've worked on this Problem a bit now and here is something to put things into perspective. I am running my Communication at 155200 Baud (it has to be so high), Data comes in like this ID:1Byte (defines datatype) + 2 or 4 Data Bytes. So when i just use one Channel in short. I get 3 Bytes for one Value.

    155200 bit per sec / 8 = 14 400 Bytes per sec / 3-> 4800 Values per sec

    So i tried using a thread which runs in a while(true) loop with a boolean and it works in realtime but the Thread is also not synchronized.

  • As @erwrow said, one way to check for data lost is to place a timer tag to every data token. Alternatively, you can do an auto-increment counter. When sending data

    ctr = ctr + 1

    then in Processing you rebuild your data and check for the counter to see if they are contiguous. If they are not, then you lost data.

    Usually you don't clear the buffer. Instead, you pool the buffer until it is empty. The concept is that if your softwareis sending lots of data, the buffer will accumulate all this data and the when Processing gets a handle of the buffer via serialEvent(), it will retrieve every byte in the buffer and process it in proper order. If you don't retrieve all the data but you clear the buffer, potentially you are throwing away some of your data.


Sign In or Register to comment.