Skip to content

Commit a631e4f

Browse files
author
Tom Igoe
committed
Added Serial port check to all examples using Serial statements in the setup
1 parent e9a00eb commit a631e4f

File tree

32 files changed

+132
-40
lines changed

32 files changed

+132
-40
lines changed

build/shared/examples/04.Communication/ASCIITable/ASCIITable.ino

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
1212
created 2006
1313
by Nicholas Zambetti
14-
modified 30 Aug 2011
14+
modified 2 Apr 2012
1515
by Tom Igoe
1616
1717
This example code is in the public domain.
1818
1919
<http://www.zambetti.com>
2020
2121
*/
22-
void setup()
23-
{
22+
void setup() {
23+
//Initialize serial and wait for port to open:
2424
Serial.begin(9600);
25-
25+
while (!Serial) ;
26+
2627
// prints title with ending line break
2728
Serial.println("ASCII Table ~ Character Map");
2829
}
@@ -33,8 +34,7 @@ int thisByte = 33;
3334
// for example. '!' is the same as 33, so you could also use this:
3435
//int thisByte = '!';
3536

36-
void loop()
37-
{
37+
void loop() {
3838
// prints value unaltered, i.e. the raw binary version of the
3939
// byte. The serial monitor interprets all bytes as
4040
// ASCII, so 33, the first number, will show up as '!'

build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
Created 26 Sept. 2005
2121
by Tom Igoe
22-
modified 26 Oct 2011
22+
modified 2 Apr 2012
2323
by Tom Igoe and Scott Fitzgerald
2424
2525
This example code is in the public domain.
@@ -35,8 +35,10 @@ int inByte = 0; // incoming serial byte
3535

3636
void setup()
3737
{
38-
// start serial port at 9600 bps:
38+
// start serial port at 9600 bps and wait for port to open:
3939
Serial.begin(9600);
40+
while (!Serial) ;
41+
4042
pinMode(2, INPUT); // digital sensor is on digital pin 2
4143
establishContact(); // send a byte to establish contact until receiver responds
4244
}

build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
Send any byte and the sketch will tell you about it.
66
77
created 29 Nov 2010
8+
modified 2 Apr 2012
89
by Tom Igoe
910
1011
This example code is in the public domain.
1112
*/
1213

1314
void setup() {
14-
// Open serial communications:
15+
// Open serial communications and wait for port to open:
1516
Serial.begin(9600);
17+
while(!Serial) ;
1618

1719
// send an intro:
1820
Serial.println("send any byte and I'll tell you everything I can about it");

build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
You can also add several different data types to string, as shown here:
66
77
created 27 July 2010
8-
modified 30 Aug 2011
8+
modified 2 Apr 2012
99
by Tom Igoe
1010
1111
http://arduino.cc/en/Tutorial/StringAdditionOperator
@@ -17,7 +17,10 @@
1717
String stringOne, stringTwo, stringThree;
1818

1919
void setup() {
20+
// initialize serial and wait for port to open:
2021
Serial.begin(9600);
22+
while (!Serial) ;
23+
2124
stringOne = String("stringThree = ");
2225
stringTwo = String("this string");
2326
stringThree = String ();

build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Examples of how to append different data types to strings
55
66
created 27 July 2010
7-
modified 30 Aug 2011
7+
modified 2 Apr 2012
88
by Tom Igoe
99
1010
http://arduino.cc/en/Tutorial/StringAppendOperator
@@ -14,7 +14,10 @@
1414
String stringOne, stringTwo;
1515

1616
void setup() {
17+
// Open serial communications and wait for port to open:
1718
Serial.begin(9600);
19+
while(!Serial) ;
20+
1821
stringOne = String("Sensor ");
1922
stringTwo = String("value");
2023
Serial.println("\n\nAppending to a string:");

build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Examples of how to change the case of a string
55
66
created 27 July 2010
7+
modified 2 Apr 2012
78
by Tom Igoe
89
910
http://arduino.cc/en/Tutorial/StringCaseChanges
@@ -12,7 +13,10 @@
1213
*/
1314

1415
void setup() {
16+
// Open serial communications and wait for port to open:
1517
Serial.begin(9600);
18+
while(!Serial) ;
19+
1620
Serial.println("\n\nString case changes:");
1721
}
1822

build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Examples of how to get and set characters of a String
55
66
created 27 July 2010
7+
modified 2 Apr 2012
78
by Tom Igoe
89
910
http://arduino.cc/en/Tutorial/StringCharacters
@@ -12,7 +13,10 @@
1213
*/
1314

1415
void setup() {
16+
// Open serial communications and wait for port to open:
1517
Serial.begin(9600);
18+
while(!Serial) ;
19+
1620
Serial.println("\n\nString charAt() and setCharAt():");
1721
}
1822

build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Examples of how to compare strings using the comparison operators
55
66
created 27 July 2010
7-
modified 30 Aug 2011
7+
modified 2 Apr 2012
88
by Tom Igoe
99
1010
http://arduino.cc/en/Tutorial/StringComparisonOperators
@@ -15,7 +15,10 @@
1515
String stringOne, stringTwo;
1616

1717
void setup() {
18+
// Open serial communications and wait for port to open:
1819
Serial.begin(9600);
20+
while(!Serial) ;
21+
1922
stringOne = String("this");
2023
stringTwo = String("that");
2124
Serial.println("\n\nComparing Strings:");

build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Examples of how to evaluate, look for, and replace characters in a String
55
66
created 27 July 2010
7+
modified 2 Apr 2012
78
by Tom Igoe
89
910
http://arduino.cc/en/Tutorial/StringIndexOf
@@ -12,7 +13,10 @@
1213
*/
1314

1415
void setup() {
16+
// Open serial communications and wait for port to open:
1517
Serial.begin(9600);
18+
while(!Serial) ;
19+
1620
Serial.println("\n\nString indexOf() and lastIndexOf() functions:");
1721

1822
}

build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Examples of how to use length() and trim() in a String
55
66
created 27 July 2010
7+
modified 2 Apr 2012
78
by Tom Igoe
89
910
http://arduino.cc/en/Tutorial/StringLengthTrim
@@ -12,7 +13,10 @@
1213
*/
1314

1415
void setup() {
16+
// Open serial communications and wait for port to open:
1517
Serial.begin(9600);
18+
while(!Serial) ;
19+
1620
Serial.println("\n\nString length() and trim():");
1721
}
1822

build/shared/examples/08.Strings/StringReplace/StringReplace.ino

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Examples of how to replace characters or substrings of a string
55
66
created 27 July 2010
7+
modified 2 Apr 2012
78
by Tom Igoe
89
910
http://arduino.cc/en/Tutorial/StringReplace
@@ -12,7 +13,10 @@
1213
*/
1314

1415
void setup() {
16+
// Open serial communications and wait for port to open:
1517
Serial.begin(9600);
18+
while(!Serial) ;
19+
1620
Serial.println("\n\nString replace:");
1721
}
1822

build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Examples of how to use startsWith() and endsWith() in a String
55
66
created 27 July 2010
7-
modified 30 Aug 2011
7+
modified 2 Apr 2012
88
by Tom Igoe
99
1010
http://arduino.cc/en/Tutorial/StringStartsWithEndsWith
@@ -13,7 +13,10 @@
1313
*/
1414

1515
void setup() {
16+
// Open serial communications and wait for port to open:
1617
Serial.begin(9600);
18+
while(!Serial) ;
19+
1720
Serial.println("\n\nString startsWith() and endsWith():");
1821

1922
}

build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
44
Examples of how to use substring in a String
55
6-
created 27 July 2010, modified 1 April 2012
7-
by Tom Igoe
6+
created 27 July 2010,
7+
modified 2 Apr 2012
8+
by Zach Eveland
89
910
http://arduino.cc/en/Tutorial/StringSubstring
1011
@@ -14,8 +15,8 @@
1415
void setup() {
1516
Serial.begin(9600);
1617
// Wait for port to be opened:
17-
while (!Serial)
18-
;
18+
while (!Serial) ;
19+
1920
Serial.println("\n\nString substring():");
2021
}
2122

@@ -35,4 +36,4 @@ void loop() {
3536

3637
// do nothing while true:
3738
while(true);
38-
}
39+
}

libraries/Ethernet/examples/ChatServer/ChatServer.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
created 18 Dec 2009
1414
by David A. Mellis
15-
modified 12 March 2012
15+
modified 2 Apr 2012
1616
by Tom Igoe
1717
1818
*/
@@ -39,8 +39,10 @@ void setup() {
3939
Ethernet.begin(mac, ip, gateway, subnet);
4040
// start listening for clients
4141
server.begin();
42-
// open the serial port
42+
// Open serial communications and wait for port to open:
4343
Serial.begin(9600);
44+
while(!Serial) ;
45+
4446
Serial.print("Chat server address:");
4547
Serial.println(Ethernet.localIP());
4648
}

libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Ethernet shield attached to pins 10, 11, 12, 13
1010
1111
created 12 April 2011
12+
modified 2 Apr 2012
1213
by Tom Igoe
1314
1415
*/
@@ -27,8 +28,10 @@ byte mac[] = {
2728
EthernetClient client;
2829

2930
void setup() {
30-
// start the serial library:
31+
// Open serial communications and wait for port to open:
3132
Serial.begin(9600);
33+
while(!Serial) ;
34+
3235
// start the Ethernet connection:
3336
if (Ethernet.begin(mac) == 0) {
3437
Serial.println("Failed to configure Ethernet using DHCP");

libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Ethernet shield attached to pins 10, 11, 12, 13
1313
1414
created 21 May 2011
15+
modified 2 Apr 2012
1516
by Tom Igoe
1617
Based on ChatServer example by David A. Mellis
1718
@@ -34,8 +35,10 @@ EthernetServer server(23);
3435
boolean gotAMessage = false; // whether or not you got a message from the client yet
3536

3637
void setup() {
37-
// open the serial port
38+
// Open serial communications and wait for port to open:
3839
Serial.begin(9600);
40+
while(!Serial) ;
41+
3942
// start the Ethernet connection:
4043
Serial.println("Trying to get an IP address using DHCP");
4144
if (Ethernet.begin(mac) == 0) {

libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
created 18 Dec 2009
1111
by David A. Mellis
12-
modified 12 April 2011
12+
modified 2 Apr 2012
1313
by Tom Igoe, based on work by Adrian McEwen
1414
1515
*/
@@ -28,8 +28,10 @@ char serverName[] = "www.google.com";
2828
EthernetClient client;
2929

3030
void setup() {
31-
// start the serial library:
31+
// Open serial communications and wait for port to open:
3232
Serial.begin(9600);
33+
while(!Serial) ;
34+
3335
// start the Ethernet connection:
3436
if (Ethernet.begin(mac) == 0) {
3537
Serial.println("Failed to configure Ethernet using DHCP");

libraries/Ethernet/examples/PachubeClient/PachubeClient.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Ethernet shield attached to pins 10, 11, 12, 13
1717
1818
created 15 March 2010
19-
updated 16 Mar 2012
19+
modified 2 Apr 2012
2020
by Tom Igoe with input from Usman Haque and Joe Saavedra
2121
2222
http://arduino.cc/en/Tutorial/PachubeClient
@@ -53,8 +53,10 @@ boolean lastConnected = false; // state of the connection last t
5353
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
5454

5555
void setup() {
56-
// start serial port:
56+
// Open serial communications and wait for port to open:
5757
Serial.begin(9600);
58+
while(!Serial) ;
59+
5860
// start the Ethernet connection:
5961
if (Ethernet.begin(mac) == 0) {
6062
Serial.println("Failed to configure Ethernet using DHCP");

0 commit comments

Comments
 (0)