Search code examples
javaplotserial-portprocessingreal-time

Jerky real time plot from serial port (USB UART interface - FTDI) in Processing


I'm a newbie of Processing and I'm trying to plot some data received from the serial port. I have a lot of accelerometers (~10) and I verify that the sketch receives all the data at 100Hz. I want to plot only the data from one accelerometer at time. If I stream the data from only one accelerometer the plot work flawlessy, but if I try to stream three of them (plotting only the first one) the plot works jerky. The strange thing happens when I try to stream 4 or more of them, because unexpectedly the plot starts to work better and better when I increase the number of streaming accelerometers.

I notice that the serialEvent() and the draw() works correctly on two indipendents threads, but their alternance change in a strange way when I add more accelerometers.

In the worst condition, if I print the System.currentTimeMillis() for the draw() ["#" symbol] and the "add-value-of-the-first-accelerometer-to-the-array()" inside the serialEvent() ["_" symbol] I have something like:

#1453211104631
#1453211104648
#1453211104664
#1453211104681
#1453211104698
#1453211104714
#1453211104730
#1453211104747
#1453211104765
#1453211104782
#1453211104797
#1453211104813
#1453211104832
#1453211104847
#1453211104864
#1453211104882
#1453211104897
#1453211104914
#1453211104931
#1453211104948
#1453211104964
#1453211104982
#1453211104998
_1453211105000
_1453211105000
_1453211105000
_1453211105000
_1453211105001
_1453211105001
_1453211105001
_1453211105001
_1453211105002
_1453211105002
_1453211105002
_1453211105002
_1453211105002
_1453211105003
_1453211105003
_1453211105003
_1453211105003
_1453211105003
_1453211105004
_1453211105004
_1453211105004
_1453211105004
_1453211105005
_1453211105005
_1453211105005
_1453211105005
_1453211105005
_1453211105006
_1453211105006
_1453211105006
_1453211105006
_1453211105006
_1453211105007
_1453211105008
_1453211105008
_1453211105008
_1453211105008
_1453211105008
_1453211105009
#1453211105014
#1453211105032
#1453211105049
#1453211105064
#1453211105082
#1453211105097
#1453211105114
#1453211105130
#1453211105148
#1453211105165
#1453211105181
#1453211105198
#1453211105214

so at #1453211105014 the draw() plot the previous 39 points (~390ms) in one shot, then nothing for 200ms and then another block of points and so on. The final effect is a jerky plotting of the data.

This doesn't happen when the sketch receive few data (one accelerometer) or a lot of data (more than 6 accelerometers).

Where I'm wrong?

Thank you very much for any help!


Solution

  • I find the solution! I have to change the settings of the USB UART interface (FTDI). Infact I found that the data latency is related to the USB Buffer Size and the Latency Timer (Device Manager -> COM Ports -> USB Serial Port -> Properties -> Advanced). For further information: http://www.ftdichip.com/Support/Documents/AppNotes/AN232B-04_DataLatencyFlow.pdf.

    I hope it could be useful!