Skip to content

Commit ed3f3b0

Browse files
tigoeTom Igoe
authored andcommitted
Added Serial port check to all examples using Serial statements in the setup
1 parent fde6508 commit ed3f3b0

File tree

11 files changed

+43
-15
lines changed

11 files changed

+43
-15
lines changed

examples/ChatServer/ChatServer.ino

Lines changed: 4 additions & 2 deletions
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
}

examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 4 additions & 1 deletion
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");

examples/DhcpChatServer/DhcpChatServer.ino

Lines changed: 4 additions & 1 deletion
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) {

examples/DnsWebClient/DnsWebClient.ino

Lines changed: 4 additions & 2 deletions
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");

examples/PachubeClient/PachubeClient.ino

Lines changed: 4 additions & 2 deletions
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");

examples/PachubeClientString/PachubeClientString.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Ethernet shield attached to pins 10, 11, 12, 13
1919
2020
created 15 March 2010
21-
updated 16 Mar 2012
21+
modified 2 Apr 2012
2222
by Tom Igoe with input from Usman Haque and Joe Saavedra
2323
2424
http://arduino.cc/en/Tutorial/PachubeClientString
@@ -55,8 +55,10 @@ boolean lastConnected = false; // state of the connection last t
5555
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
5656

5757
void setup() {
58-
// start serial port:
58+
// Open serial communications and wait for port to open:
5959
Serial.begin(9600);
60+
while(!Serial) ;
61+
6062
// give the ethernet module time to boot up:
6163
delay(1000);
6264
// start the Ethernet connection:

examples/TelnetClient/TelnetClient.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Ethernet shield attached to pins 10, 11, 12, 13
1414
1515
created 14 Sep 2010
16+
modified 2 Apr 2012
1617
by Tom Igoe
1718
1819
*/
@@ -38,8 +39,10 @@ EthernetClient client;
3839
void setup() {
3940
// start the Ethernet connection:
4041
Ethernet.begin(mac, ip);
41-
// start the serial library:
42+
// Open serial communications and wait for port to open:
4243
Serial.begin(9600);
44+
while(!Serial) ;
45+
4346
// give the Ethernet shield a second to initialize:
4447
delay(1000);
4548
Serial.println("connecting...");

examples/TwitterClient/TwitterClient.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Ethernet shield attached to pins 10, 11, 12, 13
1818
1919
created 21 May 2011
20+
modified 2 Apr 2012
2021
by Tom Igoe
2122
2223
This code is in the public domain.
@@ -51,8 +52,10 @@ void setup() {
5152
currentLine.reserve(256);
5253
tweet.reserve(150);
5354

54-
// initialize serial:
55+
// Open serial communications and wait for port to open:
5556
Serial.begin(9600);
57+
while(!Serial) ;
58+
5659
// attempt a DHCP connection:
5760
Serial.println("Attempting to get an IP address using DHCP:");
5861
if (!Ethernet.begin(mac)) {

examples/UdpNtpClient/UdpNtpClient.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
created 4 Sep 2010
1111
by Michael Margolis
12-
modified 17 Sep 2010
12+
modified 2 Apr 2012
1313
by Tom Igoe
1414
1515
This code is in the public domain.
@@ -38,7 +38,9 @@ EthernetUDP Udp;
3838

3939
void setup()
4040
{
41+
// Open serial communications and wait for port to open:
4142
Serial.begin(9600);
43+
while(!Serial) ;
4244

4345
// start Ethernet and UDP
4446
if (Ethernet.begin(mac) == 0) {

examples/WebClient/WebClient.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Ethernet shield attached to pins 10, 11, 12, 13
99
1010
created 18 Dec 2009
11+
modified 2 Apr 2012
1112
by David A. Mellis
1213
1314
*/
@@ -26,8 +27,10 @@ IPAddress server(173,194,33,104); // Google
2627
EthernetClient client;
2728

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

0 commit comments

Comments
 (0)