// USB Serial Transmit Bandwidth Test
// Written by Paul Stoffregen, paul@pjrc.com
// This benchmark code is in the public domain.
//
// Within 5 seconds of opening the port, this program
// will send a message as rapidly as possible, for 10 seconds.
//
// To run this benchmark test, use serial_read.exe (Windows) or
// serial_listen (Mac, Linux) program can read the data efficiently
// without saving it.
// http://www.pjrc.com/teensy/serial_listen.c
// http://www.pjrc.com/teensy/serial_read.c
// http://www.pjrc.com/teensy/serial_read.exe
//
// You can also run a terminal emulator and select the option
// to capture all text to a file. However, some terminal emulators
// may limit the speed, depending upon how they update the screen
// and how efficiently their code processes the imcoming data. The
// Arduino Serial Monitor is particularly slow. Only use it to
// verify this sketch works. For actual benchmarks, use the
// efficient receive tests above.
//
// Full disclosure: Paul is the author of Teensyduino.
//
// Results can vary depending on the number of other USB devices
// connected. For fastest results, disconnect all others.
//#define USBSERIAL Serial // for Leonardo, Teensy, Fubarino
#define USBSERIAL SerialUSB // for Due, Maple
void setup()
{
USBSERIAL.begin(115200);
}
void loop()
{
// wait for serial port to be opened
while (!USBSERIAL) ;
// give the user 5 seconds to enable text capture in their
// terminal emulator, or do whatever to get ready
for (int n=5; n; n--) {
USBSERIAL.print("10 second speed test begins in ");
USBSERIAL.print(n);
USBSERIAL.println(" seconds.");
if (!USBSERIAL) break;
delay(1000);
}
// send a string as fast as possible, for 10 seconds
unsigned long beginMillis = millis();
do {
USBSERIAL.print("USB Fast Serial Transmit Bandwidth Test, capture this text.\r\n");
} while (millis() - beginMillis < 10000);
USBSERIAL.println("done!");
// after the test, wait forever doing nothing,
// well, at least until the terminal emulator quits
while (USBSERIAL) ;
}