From a631e4f834eb18289f40f26728fbf931e0866a24 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 2 Apr 2012 09:07:58 -0400 Subject: [PATCH] Added Serial port check to all examples using Serial statements in the setup --- .../04.Communication/ASCIITable/ASCIITable.ino | 12 ++++++------ .../SerialCallResponseASCII.ino | 6 ++++-- .../CharacterAnalysis/CharacterAnalysis.ino | 4 +++- .../StringAdditionOperator.ino | 5 ++++- .../StringAppendOperator/StringAppendOperator.ino | 5 ++++- .../StringCaseChanges/StringCaseChanges.ino | 4 ++++ .../08.Strings/StringCharacters/StringCharacters.ino | 4 ++++ .../StringComparisonOperators.ino | 5 ++++- .../08.Strings/StringIndexOf/StringIndexOf.ino | 4 ++++ .../08.Strings/StringLengthTrim/StringLengthTrim.ino | 4 ++++ .../08.Strings/StringReplace/StringReplace.ino | 4 ++++ .../StringStartsWithEndsWith.ino | 5 ++++- .../08.Strings/StringSubstring/StringSubstring.ino | 11 ++++++----- .../Ethernet/examples/ChatServer/ChatServer.ino | 6 ++++-- .../DhcpAddressPrinter/DhcpAddressPrinter.ino | 5 ++++- .../examples/DhcpChatServer/DhcpChatServer.ino | 5 ++++- .../Ethernet/examples/DnsWebClient/DnsWebClient.ino | 6 ++++-- .../examples/PachubeClient/PachubeClient.ino | 6 ++++-- .../PachubeClientString/PachubeClientString.ino | 6 ++++-- .../Ethernet/examples/TelnetClient/TelnetClient.ino | 5 ++++- .../examples/TwitterClient/TwitterClient.ino | 5 ++++- .../Ethernet/examples/UdpNtpClient/UdpNtpClient.ino | 4 +++- libraries/Ethernet/examples/WebClient/WebClient.ino | 5 ++++- libraries/Ethernet/examples/WebServer/WebServer.ino | 5 ++++- libraries/SD/examples/CardInfo/CardInfo.ino | 5 ++++- libraries/SD/examples/Datalogger/Datalogger.ino | 5 ++++- libraries/SD/examples/DumpFile/DumpFile.ino | 6 ++++++ libraries/SD/examples/Files/Files.ino | 5 ++++- libraries/SD/examples/ReadWrite/ReadWrite.ino | 5 ++++- libraries/SD/examples/listfiles/listfiles.ino | 5 ++++- .../SoftwareSerialExample/SoftwareSerialExample.ino | 6 +++++- .../examples/TwoPortReceive/TwoPortReceive.ino | 4 +++- 32 files changed, 132 insertions(+), 40 deletions(-) diff --git a/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino b/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino index 5a111027d..35a8a5f53 100644 --- a/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino +++ b/build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -11,7 +11,7 @@ created 2006 by Nicholas Zambetti - modified 30 Aug 2011 + modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -19,10 +19,11 @@ */ -void setup() -{ +void setup() { + //Initialize serial and wait for port to open: Serial.begin(9600); - + while (!Serial) ; + // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } @@ -33,8 +34,7 @@ int thisByte = 33; // for example. '!' is the same as 33, so you could also use this: //int thisByte = '!'; -void loop() -{ +void loop() { // prints value unaltered, i.e. the raw binary version of the // byte. The serial monitor interprets all bytes as // ASCII, so 33, the first number, will show up as '!' diff --git a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index 1cfc5d446..45e95ed94 100644 --- a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -19,7 +19,7 @@ Created 26 Sept. 2005 by Tom Igoe - modified 26 Oct 2011 + modified 2 Apr 2012 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. @@ -35,8 +35,10 @@ int inByte = 0; // incoming serial byte void setup() { - // start serial port at 9600 bps: + // start serial port at 9600 bps and wait for port to open: Serial.begin(9600); + 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 12baca9af..de4ed00a2 100644 --- a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -5,14 +5,16 @@ Send any byte and the sketch will tell you about it. created 29 Nov 2010 + modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. */ void setup() { - // Open serial communications: + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 88938e864..847746e4f 100644 --- a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -5,7 +5,7 @@ You can also add several different data types to string, as shown here: created 27 July 2010 - modified 30 Aug 2011 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringAdditionOperator @@ -17,7 +17,10 @@ String stringOne, stringTwo, stringThree; void setup() { + // initialize serial and wait for port to open: Serial.begin(9600); + while (!Serial) ; + stringOne = String("stringThree = "); stringTwo = String("this string"); stringThree = String (); diff --git a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino index cb902ca6b..43d41e2f7 100644 --- a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino +++ b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -4,7 +4,7 @@ Examples of how to append different data types to strings created 27 July 2010 - modified 30 Aug 2011 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringAppendOperator @@ -14,7 +14,10 @@ String stringOne, stringTwo; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + stringOne = String("Sensor "); stringTwo = String("value"); Serial.println("\n\nAppending to a string:"); diff --git a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino index c180014bd..818894d0c 100644 --- a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino +++ b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -4,6 +4,7 @@ Examples of how to change the case of a string created 27 July 2010 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringCaseChanges @@ -12,7 +13,10 @@ */ void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 8b8d9bbdc..def53f366 100644 --- a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino +++ b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -4,6 +4,7 @@ Examples of how to get and set characters of a String created 27 July 2010 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringCharacters @@ -12,7 +13,10 @@ */ void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 53c7492e5..4ec8ba0b5 100644 --- a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -4,7 +4,7 @@ Examples of how to compare strings using the comparison operators created 27 July 2010 - modified 30 Aug 2011 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringComparisonOperators @@ -15,7 +15,10 @@ String stringOne, stringTwo; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + stringOne = String("this"); stringTwo = String("that"); Serial.println("\n\nComparing Strings:"); diff --git a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino index a60d12783..368ecf96a 100644 --- a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -4,6 +4,7 @@ Examples of how to evaluate, look for, and replace characters in a String created 27 July 2010 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringIndexOf @@ -12,7 +13,10 @@ */ void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 1737b0d95..e6a21aafd 100644 --- a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -4,6 +4,7 @@ Examples of how to use length() and trim() in a String created 27 July 2010 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringLengthTrim @@ -12,7 +13,10 @@ */ void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 c906167d8..25d94c568 100644 --- a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino +++ b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino @@ -4,6 +4,7 @@ Examples of how to replace characters or substrings of a string created 27 July 2010 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringReplace @@ -12,7 +13,10 @@ */ void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 429ec60d9..0d4522148 100644 --- a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -4,7 +4,7 @@ Examples of how to use startsWith() and endsWith() in a String created 27 July 2010 - modified 30 Aug 2011 + modified 2 Apr 2012 by Tom Igoe http://arduino.cc/en/Tutorial/StringStartsWithEndsWith @@ -13,7 +13,10 @@ */ void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 56327c8ea..af443555a 100644 --- a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino +++ b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino @@ -3,8 +3,9 @@ Examples of how to use substring in a String - created 27 July 2010, modified 1 April 2012 - by Tom Igoe + created 27 July 2010, + modified 2 Apr 2012 + by Zach Eveland http://arduino.cc/en/Tutorial/StringSubstring @@ -14,8 +15,8 @@ void setup() { Serial.begin(9600); // Wait for port to be opened: - while (!Serial) - ; + while (!Serial) ; + Serial.println("\n\nString substring():"); } @@ -35,4 +36,4 @@ void loop() { // do nothing while true: while(true); -} \ No newline at end of file +} diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/libraries/Ethernet/examples/ChatServer/ChatServer.ino index de7525769..9e05f7781 100644 --- a/libraries/Ethernet/examples/ChatServer/ChatServer.ino +++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -12,7 +12,7 @@ created 18 Dec 2009 by David A. Mellis - modified 12 March 2012 + modified 2 Apr 2012 by Tom Igoe */ @@ -39,8 +39,10 @@ void setup() { Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); - // open the serial port + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 630dd1711..6e5162437 100644 --- a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino +++ b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -9,6 +9,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 12 April 2011 + modified 2 Apr 2012 by Tom Igoe */ @@ -27,8 +28,10 @@ byte mac[] = { EthernetClient client; void setup() { - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino index 50820542c..ecbd7a281 100644 --- a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino +++ b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -12,6 +12,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 21 May 2011 + modified 2 Apr 2012 by Tom Igoe Based on ChatServer example by David A. Mellis @@ -34,8 +35,10 @@ EthernetServer server(23); boolean gotAMessage = false; // whether or not you got a message from the client yet void setup() { - // open the serial port + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // start the Ethernet connection: Serial.println("Trying to get an IP address using DHCP"); if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino index 5c7a53a65..074210f74 100644 --- a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino +++ b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino @@ -9,7 +9,7 @@ created 18 Dec 2009 by David A. Mellis - modified 12 April 2011 + modified 2 Apr 2012 by Tom Igoe, based on work by Adrian McEwen */ @@ -28,8 +28,10 @@ char serverName[] = "www.google.com"; EthernetClient client; void setup() { - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino index 4d4290d46..9be56f9c8 100644 --- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino +++ b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino @@ -16,7 +16,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 15 March 2010 - updated 16 Mar 2012 + modified 2 Apr 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra http://arduino.cc/en/Tutorial/PachubeClient @@ -53,8 +53,10 @@ boolean lastConnected = false; // state of the connection last t const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com void setup() { - // start serial port: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino index 3535287ac..d6e75a889 100644 --- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino +++ b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino @@ -18,7 +18,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 15 March 2010 - updated 16 Mar 2012 + modified 2 Apr 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra http://arduino.cc/en/Tutorial/PachubeClientString @@ -55,8 +55,10 @@ boolean lastConnected = false; // state of the connection last t const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com void setup() { - // start serial port: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // give the ethernet module time to boot up: delay(1000); // start the Ethernet connection: diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino index 5cf1ad875..816246b43 100644 --- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino +++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -13,6 +13,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 14 Sep 2010 + modified 2 Apr 2012 by Tom Igoe */ @@ -38,8 +39,10 @@ EthernetClient client; void setup() { // start the Ethernet connection: Ethernet.begin(mac, ip); - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting..."); diff --git a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino index a3b397daf..ee47e212b 100644 --- a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino +++ b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino @@ -17,6 +17,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 21 May 2011 + modified 2 Apr 2012 by Tom Igoe This code is in the public domain. @@ -51,8 +52,10 @@ void setup() { currentLine.reserve(256); tweet.reserve(150); - // initialize serial: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // attempt a DHCP connection: Serial.println("Attempting to get an IP address using DHCP:"); if (!Ethernet.begin(mac)) { diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino index b4e24b8ce..d8e48fae7 100644 --- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino +++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -9,7 +9,7 @@ created 4 Sep 2010 by Michael Margolis - modified 17 Sep 2010 + modified 2 Apr 2012 by Tom Igoe This code is in the public domain. @@ -38,7 +38,9 @@ EthernetUDP Udp; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + 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 18068541f..ea488dad4 100644 --- a/libraries/Ethernet/examples/WebClient/WebClient.ino +++ b/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -8,6 +8,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009 + modified 2 Apr 2012 by David A. Mellis */ @@ -26,8 +27,10 @@ IPAddress server(173,194,33,104); // Google EthernetClient client; void setup() { - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index 7cf2c53cf..11aed4d29 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -10,7 +10,7 @@ created 18 Dec 2009 by David A. Mellis - modified 20 Mar 2012 + modified 2 Apr 2012 by Tom Igoe */ @@ -30,7 +30,10 @@ IPAddress ip(192,168,1, 177); EthernetServer server(80); void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); diff --git a/libraries/SD/examples/CardInfo/CardInfo.ino b/libraries/SD/examples/CardInfo/CardInfo.ino index fb2f6c3ca..82251650b 100644 --- a/libraries/SD/examples/CardInfo/CardInfo.ino +++ b/libraries/SD/examples/CardInfo/CardInfo.ino @@ -16,7 +16,7 @@ created 28 Mar 2011 by Limor Fried - modified 16 Mar 2011 + modified 2 Apr 2012 by Tom Igoe */ // include the SD library: @@ -35,7 +35,10 @@ const int chipSelect = 4; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + Serial.print("\nInitializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin diff --git a/libraries/SD/examples/Datalogger/Datalogger.ino b/libraries/SD/examples/Datalogger/Datalogger.ino index 73d81af7b..f38663b46 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.ino +++ b/libraries/SD/examples/Datalogger/Datalogger.ino @@ -13,7 +13,7 @@ ** CS - pin 4 created 24 Nov 2010 - updated 2 Dec 2010 + modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -30,7 +30,10 @@ const int chipSelect = 4; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: diff --git a/libraries/SD/examples/DumpFile/DumpFile.ino b/libraries/SD/examples/DumpFile/DumpFile.ino index 961717fc9..5021d3de5 100644 --- a/libraries/SD/examples/DumpFile/DumpFile.ino +++ b/libraries/SD/examples/DumpFile/DumpFile.ino @@ -12,6 +12,9 @@ ** CS - pin 4 created 22 December 2010 + by Limor Fried + modified 2 Apr 2012 + by Tom Igoe This example code is in the public domain. @@ -27,7 +30,10 @@ const int chipSelect = 4; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: diff --git a/libraries/SD/examples/Files/Files.ino b/libraries/SD/examples/Files/Files.ino index 5ed9fea4e..ed64b9297 100644 --- a/libraries/SD/examples/Files/Files.ino +++ b/libraries/SD/examples/Files/Files.ino @@ -11,7 +11,7 @@ created Nov 2010 by David A. Mellis - updated 2 Dec 2010 + modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -23,7 +23,10 @@ File myFile; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.ino b/libraries/SD/examples/ReadWrite/ReadWrite.ino index 995721800..e9235b338 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.ino +++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -11,7 +11,7 @@ created Nov 2010 by David A. Mellis - updated 2 Dec 2010 + modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -24,7 +24,10 @@ File myFile; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin diff --git a/libraries/SD/examples/listfiles/listfiles.ino b/libraries/SD/examples/listfiles/listfiles.ino index b2435a2c6..2ca0f72b3 100644 --- a/libraries/SD/examples/listfiles/listfiles.ino +++ b/libraries/SD/examples/listfiles/listfiles.ino @@ -11,7 +11,7 @@ created Nov 2010 by David A. Mellis - updated 2 Dec 2010 + modified 2 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -23,7 +23,10 @@ File root; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; + Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index 615d2b363..5d06c6462 100644 --- a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -9,6 +9,7 @@ * TX is digital pin 3 (connect to RX of other device) created back in the mists of time + modified 2 Apr 2012 by Tom Igoe based on Mikal Hart's example @@ -21,7 +22,10 @@ SoftwareSerial mySerial(2, 3); // RX, TX void setup() { - Serial.begin(57600); + // Open serial communications and wait for port to open: + Serial.begin57600; + while(!Serial) ; + Serial.println("Goodnight moon!"); // set the data rate for the SoftwareSerial port diff --git a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index e870c6fc1..430734946 100644 --- a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -17,6 +17,7 @@ * Second serial device's TX attached to digital pin 4, RX to pin 5 created 18 Apr. 2011 + modified 2 Apr 2012 by Tom Igoe based on Mikal Hart's twoPortRXExample @@ -33,8 +34,9 @@ SoftwareSerial portTwo(4, 5); void setup() { - // Start the hardware serial port + // Open serial communications and wait for port to open: Serial.begin(9600); + while(!Serial) ; // Start each software serial port portOne.begin(9600);