Paul Stof­fre­gen was kind enough to send my a free Teensy 2.0 sam­ple board to ana­lyze the Arduino ser­ial latency issue — and this board is shock­ing small:


We wrote a very sim­ple firmware to per­form some basic bench­marks — Paul wrote a sim­ple c tool to mea­sure the native latency, I wrote a sim­ple tool in Java using rxtx lib to mea­sure the latency in Java.

Long story short, here are the results:



Hint: These results are made on my Mac­Book (Model 5,1), Intel Core 2 Duo, 2GHz, uname out­put: “Dar­win xxx 10.7.0 Dar­win Ker­nel Ver­sion 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386”

Con­clu­sion:

  • Java latency is at least 20ms
  • The Arduino UNO may be slower than the Arduino 2009 if small a amount of ser­ial bytes (<12b) are transferred
  • The Teensy 2.0 board may be up to 18 times faster than an Arduino board

So this 20ms latency using the rxtx library looks quite promis­ing… hmm take a look at this code snipped from the file SerialImp.c:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void report_serial_events( struct event_info_struct *eis )
{
    /* JK00: work around for Multi IO cards with­out TIOCSERGETLSR */

<…>

            usleep(20000);
#if !defined(__sun__)
    /* FIXME: No time to test on all OS’s for pro­duc­tion */
            usleep(20000);
#endif /* !__sun__ */
            return;
        }
        report(“report_serial_events: send­ing DATA_AVAILABLE\n”);
        if(!send_event( eis, SPE_DATA_AVAILABLE, 1 ))
        {
            /* select wont block */
    /* FIXME: No time to test on all OS’s for pro­duc­tion */
/* REMOVE goes around usleep */
#if !defined(__sun__)
#endif /* !__sun__ */
        }
        usleep(20000);
    }
}

Replace this 20’000ms delay with a shorter (I used 2000ms), recom­pile and enjoy decreased latency!

Files used for this arti­cle:
- Per­for­mance test files
- RXTX TEST library, only 64b Mac OSX!

The rxtx lib is not very well tested (not at all!) — so leave a feed­back if the lib is work­ing fine for you!

Any­way, here are the results on OSX with the patched rxtx library:


Update 16.05.2011:
Paul did some more native per­for­mance tests, here are the results:



0diggsdigg