From f8c0adc107b2ef7cbf383422c9d1fe3d0ad0b48f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Oct 2013 19:58:03 +0200 Subject: [PATCH] Wait for serial port to connect in example - needed for Leonardo, Teensy and other boards with built-in USB CDC serial connection --- examples/Bluetooth/PS3BT/PS3BT.ino | 1 + examples/Bluetooth/PS3Multi/PS3Multi.ino | 1 + examples/Bluetooth/PS3SPP/PS3SPP.ino | 1 + examples/Bluetooth/SPP/SPP.ino | 1 + examples/Bluetooth/SPPMulti/SPPMulti.ino | 1 + examples/Bluetooth/Wii/Wii.ino | 1 + examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino | 1 + examples/Bluetooth/WiiMulti/WiiMulti.ino | 1 + examples/Bluetooth/WiiUProController/WiiUProController.ino | 1 + examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 1 + examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino | 1 + examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino | 1 + examples/HID/USBHIDJoystick/USBHIDJoystick.ino | 1 + examples/HID/USBHID_desc/USBHID_desc.ino | 1 + examples/HID/le3dp/le3dp.ino | 1 + examples/HID/scale/scale.ino | 1 + examples/PS3USB/PS3USB.ino | 1 + examples/USB_desc/USB_desc.ino | 1 + examples/Xbox/XBOXOLD/XBOXOLD.ino | 1 + examples/Xbox/XBOXRECV/XBOXRECV.ino | 1 + examples/Xbox/XBOXUSB/XBOXUSB.ino | 1 + examples/acm/acm_terminal/acm_terminal.ino | 1 + examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 3 ++- examples/adk/adk_barcode/adk_barcode.ino | 1 + examples/adk/demokit_20/demokit_20.ino | 1 + examples/adk/term_test/term_test.ino | 1 + examples/adk/term_time/term_time.ino | 1 + examples/board_qc/board_qc.ino | 1 + examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino | 1 + examples/hub_demo/hub_demo.ino | 1 + examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino | 1 + examples/pl2303/pl2303_gps/pl2303_gps.ino | 1 + examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 1 + examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino | 1 + 34 files changed, 35 insertions(+), 1 deletion(-) diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index df1b34fb..3cb83213 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -19,6 +19,7 @@ boolean printAngle; void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 48335820..d3f172b6 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -23,6 +23,7 @@ void setup() { } Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index e0ba1acb..8f8e751d 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -28,6 +28,7 @@ String output = ""; // We will store the data in this string void setup() { Serial.begin(115200); // This wil lprint the debugging from the libraries + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/SPP/SPP.ino b/examples/Bluetooth/SPP/SPP.ino index fe3d4840..eb91459c 100644 --- a/examples/Bluetooth/SPP/SPP.ino +++ b/examples/Bluetooth/SPP/SPP.ino @@ -18,6 +18,7 @@ boolean firstMessage = true; void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/SPPMulti/SPPMulti.ino b/examples/Bluetooth/SPPMulti/SPPMulti.ino index 8e02d52b..483bdfbd 100644 --- a/examples/Bluetooth/SPPMulti/SPPMulti.ino +++ b/examples/Bluetooth/SPPMulti/SPPMulti.ino @@ -20,6 +20,7 @@ void setup() { SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "1234" for all connections Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index 0aab3776..815c16fe 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -18,6 +18,7 @@ bool printAngle; void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino index f1a3ed72..08aed4e0 100644 --- a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino +++ b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino @@ -30,6 +30,7 @@ uint8_t printObjects; void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/WiiMulti/WiiMulti.ino b/examples/Bluetooth/WiiMulti/WiiMulti.ino index f02a23b5..0eae4d9a 100644 --- a/examples/Bluetooth/WiiMulti/WiiMulti.ino +++ b/examples/Bluetooth/WiiMulti/WiiMulti.ino @@ -23,6 +23,7 @@ void setup() { } Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Bluetooth/WiiUProController/WiiUProController.ino b/examples/Bluetooth/WiiUProController/WiiUProController.ino index 86e22253..6ba5618b 100644 --- a/examples/Bluetooth/WiiUProController/WiiUProController.ino +++ b/examples/Bluetooth/WiiUProController/WiiUProController.ino @@ -16,6 +16,7 @@ WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimot void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index f990a1eb..b3adb558 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -101,6 +101,7 @@ KbdRptParser Prs; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index cd136cb0..92dc226b 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -148,6 +148,7 @@ MouseRptParser MousePrs; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index decf15df..80dbcd4d 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -55,6 +55,7 @@ MouseRptParser Prs; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino index b8160635..d0106e1a 100644 --- a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino +++ b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino @@ -12,6 +12,7 @@ JoystickReportParser Joy(&JoyEvents); void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/HID/USBHID_desc/USBHID_desc.ino b/examples/HID/USBHID_desc/USBHID_desc.ino index d7510c5f..b156cafe 100644 --- a/examples/HID/USBHID_desc/USBHID_desc.ino +++ b/examples/HID/USBHID_desc/USBHID_desc.ino @@ -51,6 +51,7 @@ UniversalReportParser Uni; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/HID/le3dp/le3dp.ino b/examples/HID/le3dp/le3dp.ino index 4414f60c..3728b307 100644 --- a/examples/HID/le3dp/le3dp.ino +++ b/examples/HID/le3dp/le3dp.ino @@ -15,6 +15,7 @@ JoystickReportParser Joy(&JoyEvents); void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/HID/scale/scale.ino b/examples/HID/scale/scale.ino index a88e7196..2f48c4c0 100644 --- a/examples/HID/scale/scale.ino +++ b/examples/HID/scale/scale.ino @@ -17,6 +17,7 @@ ScaleReportParser Scale(&ScaleEvents); void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index 65569187..2a627a93 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -16,6 +16,7 @@ uint8_t state = 0; void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index 75fbaa25..7f4a363a 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -45,6 +45,7 @@ void PrintAddress(uint8_t addr) void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/Xbox/XBOXOLD/XBOXOLD.ino b/examples/Xbox/XBOXOLD/XBOXOLD.ino index f0297bc1..22675172 100644 --- a/examples/Xbox/XBOXOLD/XBOXOLD.ino +++ b/examples/Xbox/XBOXOLD/XBOXOLD.ino @@ -13,6 +13,7 @@ XBOXOLD Xbox(&Usb); void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); // halt diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index eb98e19a..6bd33b0e 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -12,6 +12,7 @@ XBOXRECV Xbox(&Usb); void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/Xbox/XBOXUSB/XBOXUSB.ino b/examples/Xbox/XBOXUSB/XBOXUSB.ino index f78d1d06..a26b4110 100644 --- a/examples/Xbox/XBOXUSB/XBOXUSB.ino +++ b/examples/Xbox/XBOXUSB/XBOXUSB.ino @@ -11,6 +11,7 @@ XBOXUSB Xbox(&Usb); void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print(F("\r\nOSC did not start")); while(1); //halt diff --git a/examples/acm/acm_terminal/acm_terminal.ino b/examples/acm/acm_terminal/acm_terminal.ino index 782a51a4..8fc8edea 100644 --- a/examples/acm/acm_terminal/acm_terminal.ino +++ b/examples/acm/acm_terminal/acm_terminal.ino @@ -43,6 +43,7 @@ ACM Acm(&Usb, &AsyncOper); void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index 14f29b38..23b25ecc 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -15,12 +15,13 @@ ADK adk(&Usb,"TKJElectronics", // Manufacturer Name void setup() { Serial.begin(115200); - Serial.print("\r\nADK demo start"); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection if (Usb.Init() == -1) { Serial.print("\r\nOSCOKIRQ failed to assert"); while(1); //halt } pinMode(LED, OUTPUT); + Serial.print("\r\nArduino Blink LED Started"); } void loop() diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index 481d35b6..b410572a 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -64,6 +64,7 @@ KbdRptParser Prs; void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("\r\nADK demo start"); if (Usb.Init() == -1) { diff --git a/examples/adk/demokit_20/demokit_20.ino b/examples/adk/demokit_20/demokit_20.ino index a92097c6..87662297 100644 --- a/examples/adk/demokit_20/demokit_20.ino +++ b/examples/adk/demokit_20/demokit_20.ino @@ -37,6 +37,7 @@ void init_leds() void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("\r\nADK demo start"); if (Usb.Init() == -1) { diff --git a/examples/adk/term_test/term_test.ino b/examples/adk/term_test/term_test.ino index 492dfb15..dea6533f 100644 --- a/examples/adk/term_test/term_test.ino +++ b/examples/adk/term_test/term_test.ino @@ -14,6 +14,7 @@ ADK adk(&Usb,"Circuits@Home, ltd.", void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("\r\nADK demo start"); if (Usb.Init() == -1) { diff --git a/examples/adk/term_time/term_time.ino b/examples/adk/term_time/term_time.ino index c9657561..39fe3a49 100644 --- a/examples/adk/term_time/term_time.ino +++ b/examples/adk/term_time/term_time.ino @@ -13,6 +13,7 @@ ADK adk(&Usb,"Circuits@Home, ltd.", void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("\r\nADK demo start"); if (Usb.Init() == -1) { diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 71e14f82..cc96d0b3 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -19,6 +19,7 @@ USB Usb; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection E_Notify(PSTR("\r\nCircuits At Home 2011"),0x80); E_Notify(PSTR("\r\nUSB Host Shield Quality Control Routine"),0x80); /* SPI quick test - check revision register */ diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index 27dc1df6..ad3d319e 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -38,6 +38,7 @@ uint32_t next_time; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 10078b95..77c502fe 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -41,6 +41,7 @@ void PrintAddress(uint8_t addr) void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino index 97718214..fea00e52 100644 --- a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino +++ b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino @@ -46,6 +46,7 @@ PL2303 Pl(&Usb, &AsyncOper); void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index 5c8548fc..f756f408 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -49,6 +49,7 @@ uint32_t read_delay; void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1) diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index 6724141c..818df512 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -64,6 +64,7 @@ void setup() { Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version()); Serial.println("by Mikal Hart"); diff --git a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino index 741a2f2c..60a3e15d 100644 --- a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino +++ b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino @@ -46,6 +46,7 @@ PL2303 Pl(&Usb, &AsyncOper); void setup() { Serial.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection Serial.println("Start"); if (Usb.Init() == -1)