From 970dd043ce1838b527f12e83b1f5beb180e3f54f Mon Sep 17 00:00:00 2001 From: Federico Vanzati Date: Wed, 6 Jun 2012 17:31:14 +0200 Subject: [PATCH] added serial opening mod for Leonardo in examples --- WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino | 7 +++++-- WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino | 7 +++++-- WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino | 7 +++++-- WiFi/examples/ScanNetworks/ScanNetworks.ino | 7 +++++-- WiFi/examples/WifiChatServer/WifiChatServer.ino | 7 +++++-- WiFi/examples/WifiCosmClient/WifiCosmClient.ino | 7 +++++-- .../examples/WifiCosmClientString/WifiCosmClientString.ino | 7 +++++-- WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino | 7 +++++-- WiFi/examples/WifiWebClient/WifiWebClient.ino | 6 +++++- .../WifiWebClientRepeating/WifiWebClientRepeating.ino | 7 +++++-- WiFi/examples/WifiWebServer/WifiWebServer.ino | 7 +++++-- 11 files changed, 55 insertions(+), 21 deletions(-) diff --git a/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino index 2609320c1..f42a7f377 100644 --- a/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino +++ b/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -18,8 +18,11 @@ char ssid[] = "yourNetwork"; // the name of your network int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { - // initialize serial: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino b/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino index e6f531ca8..19736b5b2 100644 --- a/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino +++ b/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -30,8 +30,11 @@ int keyIndex = 0; // your network key Index numbe int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { - // initialize serial: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino b/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino index 953841500..fcc33ecaa 100644 --- a/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino +++ b/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -19,8 +19,11 @@ char pass[] = "secretPassword"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { - // initialize serial: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/ScanNetworks/ScanNetworks.ino b/WiFi/examples/ScanNetworks/ScanNetworks.ino index efe171adb..829e25409 100644 --- a/WiFi/examples/ScanNetworks/ScanNetworks.ino +++ b/WiFi/examples/ScanNetworks/ScanNetworks.ino @@ -19,8 +19,11 @@ #include void setup() { - // initialize serial and wait for the port to open: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiChatServer/WifiChatServer.ino b/WiFi/examples/WifiChatServer/WifiChatServer.ino index f231073ba..e4b1d1a3b 100644 --- a/WiFi/examples/WifiChatServer/WifiChatServer.ino +++ b/WiFi/examples/WifiChatServer/WifiChatServer.ino @@ -34,8 +34,11 @@ WiFiServer server(23); boolean alreadyConnected = false; // whether or not the client was connected previously void setup() { - // start serial port: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiCosmClient/WifiCosmClient.ino b/WiFi/examples/WifiCosmClient/WifiCosmClient.ino index 668c9e0ac..cc456a14e 100644 --- a/WiFi/examples/WifiCosmClient/WifiCosmClient.ino +++ b/WiFi/examples/WifiCosmClient/WifiCosmClient.ino @@ -46,8 +46,11 @@ boolean lastConnected = false; // state of the connection last t const unsigned long postingInterval = 10*1000; //delay between updates to Cosm.com void setup() { - // start serial port: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiCosmClientString/WifiCosmClientString.ino b/WiFi/examples/WifiCosmClientString/WifiCosmClientString.ino index 3634ed762..a7b0b223f 100644 --- a/WiFi/examples/WifiCosmClientString/WifiCosmClientString.ino +++ b/WiFi/examples/WifiCosmClientString/WifiCosmClientString.ino @@ -51,8 +51,11 @@ boolean lastConnected = false; // state of the connection last t const unsigned long postingInterval = 10*1000; //delay between updates to cosm.com void setup() { - // start serial port: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino b/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino index 3bbe63e8e..3dc2c8d33 100644 --- a/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino +++ b/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino @@ -50,8 +50,11 @@ void setup() { // reserve space for the strings: currentLine.reserve(256); tweet.reserve(150); - // start serial port: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiWebClient/WifiWebClient.ino b/WiFi/examples/WifiWebClient/WifiWebClient.ino index 54ec68b71..17f44a3aa 100644 --- a/WiFi/examples/WifiWebClient/WifiWebClient.ino +++ b/WiFi/examples/WifiWebClient/WifiWebClient.ino @@ -40,7 +40,11 @@ IPAddress server(173,194,73,105); // numeric IP for Google (no DNS) WiFiClient client; void setup() { - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino b/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino index 1c623d12e..96eb6283d 100644 --- a/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino +++ b/WiFi/examples/WifiWebClientRepeating/WifiWebClientRepeating.ino @@ -36,8 +36,11 @@ boolean lastConnected = false; // state of the connection last const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds void setup() { - // start serial port: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { diff --git a/WiFi/examples/WifiWebServer/WifiWebServer.ino b/WiFi/examples/WifiWebServer/WifiWebServer.ino index 72bd8e0b9..ac5f056f1 100644 --- a/WiFi/examples/WifiWebServer/WifiWebServer.ino +++ b/WiFi/examples/WifiWebServer/WifiWebServer.ino @@ -29,8 +29,11 @@ int status = WL_IDLE_STATUS; WiFiServer server(80); void setup() { - // start serial port: - Serial.begin(9600); + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) {