From 202bb102a0de4ccaf69c23ccbf9c6e1bed3eed27 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 2 Apr 2012 11:11:46 -0400 Subject: [PATCH] Updated all serial in setup examples with a note about the serial check --- .../examples/04.Communication/ASCIITable/ASCIITable.ino | 1 + .../SerialCallResponseASCII/SerialCallResponseASCII.ino | 2 ++ .../08.Strings/CharacterAnalysis/CharacterAnalysis.ino | 4 +++- .../StringAdditionOperator/StringAdditionOperator.ino | 2 ++ .../08.Strings/StringAppendOperator/StringAppendOperator.ino | 4 +++- .../08.Strings/StringCaseChanges/StringCaseChanges.ino | 4 +++- .../examples/08.Strings/StringCharacters/StringCharacters.ino | 4 +++- .../StringComparisonOperators/StringComparisonOperators.ino | 4 +++- .../examples/08.Strings/StringIndexOf/StringIndexOf.ino | 4 +++- .../examples/08.Strings/StringLengthTrim/StringLengthTrim.ino | 4 +++- .../examples/08.Strings/StringReplace/StringReplace.ino | 4 +++- .../StringStartsWithEndsWith/StringStartsWithEndsWith.ino | 4 +++- .../examples/08.Strings/StringSubstring/StringSubstring.ino | 2 ++ libraries/Ethernet/examples/ChatServer/ChatServer.ino | 4 +++- .../examples/DhcpAddressPrinter/DhcpAddressPrinter.ino | 4 +++- libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino | 4 +++- libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino | 4 +++- libraries/Ethernet/examples/PachubeClient/PachubeClient.ino | 4 +++- .../examples/PachubeClientString/PachubeClientString.ino | 4 +++- libraries/Ethernet/examples/TelnetClient/TelnetClient.ino | 4 +++- libraries/Ethernet/examples/TwitterClient/TwitterClient.ino | 4 +++- libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino | 4 +++- libraries/Ethernet/examples/WebClient/WebClient.ino | 4 +++- libraries/Ethernet/examples/WebServer/WebServer.ino | 4 +++- libraries/SD/examples/CardInfo/CardInfo.ino | 4 +++- libraries/SD/examples/Datalogger/Datalogger.ino | 4 +++- libraries/SD/examples/DumpFile/DumpFile.ino | 4 +++- libraries/SD/examples/Files/Files.ino | 4 +++- libraries/SD/examples/ReadWrite/ReadWrite.ino | 4 +++- libraries/SD/examples/listfiles/listfiles.ino | 4 +++- .../examples/SoftwareSerialExample/SoftwareSerialExample.ino | 4 +++- .../SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino | 4 +++- 32 files changed, 91 insertions(+), 28 deletions(-) diff --git a/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino b/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino index 35a8a5f53..e993c2137 100644 --- a/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino +++ b/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -22,6 +22,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); + // this check is only needed on the Leonardo: while (!Serial) ; // prints title with ending line break diff --git a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index 45e95ed94..2c4f3cd88 100644 --- a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -37,7 +37,9 @@ void setup() { // start serial port at 9600 bps and wait for port to open: Serial.begin(9600); + // this check is only needed on the Leonardo: while (!Serial) ; + ; pinMode(2, INPUT); // digital sensor is on digital pin 2 establishContact(); // send a byte to establish contact until receiver responds diff --git a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino index de4ed00a2..ce86094fe 100644 --- a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -14,7 +14,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // send an intro: Serial.println("send any byte and I'll tell you everything I can about it"); diff --git a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino index 847746e4f..40176c883 100644 --- a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -19,7 +19,9 @@ String stringOne, stringTwo, stringThree; void setup() { // initialize serial and wait for port to open: Serial.begin(9600); + // this check is only needed on the Leonardo: while (!Serial) ; + ; stringOne = String("stringThree = "); stringTwo = String("this string"); diff --git a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino index 43d41e2f7..0e253512c 100644 --- a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino +++ b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -16,7 +16,9 @@ String stringOne, stringTwo; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; stringOne = String("Sensor "); stringTwo = String("value"); diff --git a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino index 818894d0c..ed0fc76e8 100644 --- a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino +++ b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -15,7 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("\n\nString case changes:"); } diff --git a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino index def53f366..71f10a068 100644 --- a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino +++ b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -15,7 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("\n\nString charAt() and setCharAt():"); } diff --git a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino index 4ec8ba0b5..223982c59 100644 --- a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -17,7 +17,9 @@ String stringOne, stringTwo; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; stringOne = String("this"); stringTwo = String("that"); diff --git a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino index 368ecf96a..99fee0a39 100644 --- a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -15,7 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("\n\nString indexOf() and lastIndexOf() functions:"); diff --git a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino index e6a21aafd..646eaa913 100644 --- a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -15,7 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("\n\nString length() and trim():"); } diff --git a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino index 25d94c568..f96e3f2c7 100644 --- a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino +++ b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino @@ -15,7 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("\n\nString replace:"); } diff --git a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino index 0d4522148..ec707f3aa 100644 --- a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -15,7 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("\n\nString startsWith() and endsWith():"); diff --git a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino index af443555a..6d1e8f5ad 100644 --- a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino +++ b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino @@ -15,7 +15,9 @@ void setup() { Serial.begin(9600); // Wait for port to be opened: + // this check is only needed on the Leonardo: while (!Serial) ; + ; Serial.println("\n\nString substring():"); } diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/libraries/Ethernet/examples/ChatServer/ChatServer.ino index 9e05f7781..a61d17e54 100644 --- a/libraries/Ethernet/examples/ChatServer/ChatServer.ino +++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -41,7 +41,9 @@ void setup() { server.begin(); // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("Chat server address:"); Serial.println(Ethernet.localIP()); diff --git a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino index 6e5162437..6ae5253fe 100644 --- a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino +++ b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -30,7 +30,9 @@ EthernetClient client; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino index ecbd7a281..222251a94 100644 --- a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino +++ b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -37,7 +37,9 @@ boolean gotAMessage = false; // whether or not you got a message from the client void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start the Ethernet connection: Serial.println("Trying to get an IP address using DHCP"); diff --git a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino index 074210f74..f15b835f9 100644 --- a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino +++ b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino @@ -30,7 +30,9 @@ EthernetClient client; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino index 9be56f9c8..3b5ce9c13 100644 --- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino +++ b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino @@ -55,7 +55,9 @@ const unsigned long postingInterval = 10*1000; //delay between updates to Pachub void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino index d6e75a889..dda28db82 100644 --- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino +++ b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino @@ -57,7 +57,9 @@ const unsigned long postingInterval = 10*1000; //delay between updates to Pachu void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // give the ethernet module time to boot up: delay(1000); diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino index 816246b43..b9a22947f 100644 --- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino +++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -41,7 +41,9 @@ void setup() { Ethernet.begin(mac, ip); // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // give the Ethernet shield a second to initialize: delay(1000); diff --git a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino index ee47e212b..b704f4f62 100644 --- a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino +++ b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino @@ -54,7 +54,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // attempt a DHCP connection: Serial.println("Attempting to get an IP address using DHCP:"); diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino index d8e48fae7..7367af8b0 100644 --- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino +++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -40,7 +40,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start Ethernet and UDP if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/WebClient/WebClient.ino b/libraries/Ethernet/examples/WebClient/WebClient.ino index ea488dad4..054a13e27 100644 --- a/libraries/Ethernet/examples/WebClient/WebClient.ino +++ b/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -29,7 +29,9 @@ EthernetClient client; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index 11aed4d29..57368489a 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -32,7 +32,9 @@ EthernetServer server(80); void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // start the Ethernet connection and the server: Ethernet.begin(mac, ip); diff --git a/libraries/SD/examples/CardInfo/CardInfo.ino b/libraries/SD/examples/CardInfo/CardInfo.ino index 82251650b..0fa864740 100644 --- a/libraries/SD/examples/CardInfo/CardInfo.ino +++ b/libraries/SD/examples/CardInfo/CardInfo.ino @@ -37,7 +37,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("\nInitializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. diff --git a/libraries/SD/examples/Datalogger/Datalogger.ino b/libraries/SD/examples/Datalogger/Datalogger.ino index f38663b46..9e1d8e7ce 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.ino +++ b/libraries/SD/examples/Datalogger/Datalogger.ino @@ -32,7 +32,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to diff --git a/libraries/SD/examples/DumpFile/DumpFile.ino b/libraries/SD/examples/DumpFile/DumpFile.ino index 5021d3de5..9de34c4c8 100644 --- a/libraries/SD/examples/DumpFile/DumpFile.ino +++ b/libraries/SD/examples/DumpFile/DumpFile.ino @@ -32,7 +32,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to diff --git a/libraries/SD/examples/Files/Files.ino b/libraries/SD/examples/Files/Files.ino index ed64b9297..983c67fac 100644 --- a/libraries/SD/examples/Files/Files.ino +++ b/libraries/SD/examples/Files/Files.ino @@ -25,7 +25,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.ino b/libraries/SD/examples/ReadWrite/ReadWrite.ino index e9235b338..5d1037404 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.ino +++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -26,7 +26,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. diff --git a/libraries/SD/examples/listfiles/listfiles.ino b/libraries/SD/examples/listfiles/listfiles.ino index 2ca0f72b3..1faef1184 100644 --- a/libraries/SD/examples/listfiles/listfiles.ino +++ b/libraries/SD/examples/listfiles/listfiles.ino @@ -25,7 +25,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index 5d06c6462..a19307b14 100644 --- a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -24,7 +24,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin57600; - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; Serial.println("Goodnight moon!"); diff --git a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index 430734946..bc0ae725c 100644 --- a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -36,7 +36,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - while(!Serial) ; + // this check is only needed on the Leonardo: + while (!Serial) ; + ; // Start each software serial port portOne.begin(9600);