From b2fe779ec013eda7e6549beae2ab747140f9bf7c Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Wed, 14 Mar 2012 21:03:15 -0400 Subject: [PATCH 1/9] Added DigitalInputPullup example by Scott Fitzgerald --- .../DigitalIputPullup/DigitalIputPullup.ino | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino diff --git a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino new file mode 100644 index 000000000..99b5a5476 --- /dev/null +++ b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino @@ -0,0 +1,39 @@ +/* + Input Pullup Serial + + This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a + digital input on pin 2 and prints the results to the serial monitor. + + The circuit: + * Momentary switch attached from pin 2 to ground + + Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal + 20K-ohm resistor is pulled to 5V. This configuration causes the input to + read HIGH when the switch is open, and LOW when it is closed. + + created 14 March 2012 + by Scott Fitzgerald + + This example code is in the public domain + + */ + +void setup(){ + //start serial connection + Serial.begin(9600); + //configure pin2 as an input and enable the internal pull-up resistor + pinMode(2, INPUT_PULLUP); + +} + +void loop(){ + //read the pushbutton value into a variable + int sensorVal = digitalRead(2); + //print out the value of the pushbutton + Serial.println(sensorVal); + //brief delay + delay(10); + +} + + From 81b6ca2d61afd897fb04fa9ad66f94a8c90adaf5 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Wed, 14 Mar 2012 21:11:00 -0400 Subject: [PATCH 2/9] Added URL for new example --- .../examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino index 99b5a5476..093304595 100644 --- a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino +++ b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino @@ -14,6 +14,8 @@ created 14 March 2012 by Scott Fitzgerald + http://www.arduino.cc/en/Tutorial/InputPullupSerial + This example code is in the public domain */ From 1b58e45f743bc285a18ddfa28c207f80d59924ce Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Wed, 14 Mar 2012 23:11:35 -0400 Subject: [PATCH 3/9] Added LED to InputPullup example --- .../DigitalIputPullup/DigitalIputPullup.ino | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino index 093304595..955d27465 100644 --- a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino +++ b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino @@ -6,6 +6,7 @@ The circuit: * Momentary switch attached from pin 2 to ground + * Built-in LED on pin 13 Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal 20K-ohm resistor is pulled to 5V. This configuration causes the input to @@ -24,7 +25,8 @@ void setup(){ //start serial connection Serial.begin(9600); //configure pin2 as an input and enable the internal pull-up resistor - pinMode(2, INPUT_PULLUP); + pinMode(2, INPUT_PULLUP); + pinMode(13, OUTPUT); } @@ -33,9 +35,18 @@ void loop(){ int sensorVal = digitalRead(2); //print out the value of the pushbutton Serial.println(sensorVal); - //brief delay - delay(10); - + + // Keep in mind the pullup means the pushbutton's + // logic is inverted. It goes HIGH when it's pressed, + // and LOW when it's not. Turn on pin 13 when the + // button's pressed, and off when it's not: + if (sensorVal == HIGH) { + digitalWrite(13, LOW); + } + else { + digitalWrite(13, HIGH); + } } + From 13e0b9335c296c8921d2c60d3dc867bf04cf186f Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 15 Mar 2012 19:00:24 -0400 Subject: [PATCH 4/9] Putting ArduinoISP back to 19200 baud. From 9600. And lowering the delay in the heartbeat from 40 to 20, which seems to fix things again. --- build/shared/examples/ArduinoISP/ArduinoISP.ino | 4 ++-- hardware/arduino/programmers.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/shared/examples/ArduinoISP/ArduinoISP.ino b/build/shared/examples/ArduinoISP/ArduinoISP.ino index b4e6eae28..9ed0bc7df 100644 --- a/build/shared/examples/ArduinoISP/ArduinoISP.ino +++ b/build/shared/examples/ArduinoISP/ArduinoISP.ino @@ -66,7 +66,7 @@ void pulse(int pin, int times); void setup() { - Serial.begin(9600); + Serial.begin(19200); pinMode(LED_PMODE, OUTPUT); pulse(LED_PMODE, 2); pinMode(LED_ERR, OUTPUT); @@ -109,7 +109,7 @@ void heartbeat() { if (hbval < 32) hbdelta = -hbdelta; hbval += hbdelta; analogWrite(LED_HB, hbval); - delay(40); + delay(20); } diff --git a/hardware/arduino/programmers.txt b/hardware/arduino/programmers.txt index 43e8d95d5..c34b88cd2 100644 --- a/hardware/arduino/programmers.txt +++ b/hardware/arduino/programmers.txt @@ -23,4 +23,4 @@ parallel.force=true arduinoisp.name=Arduino as ISP arduinoisp.communication=serial arduinoisp.protocol=stk500v1 -arduinoisp.speed=9600 +arduinoisp.speed=19200 From c9ded421970894de5d6d2d7cb0bcc1525466990f Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Fri, 16 Mar 2012 10:48:07 -0400 Subject: [PATCH 5/9] Updated PachubeClientString and PachubeClient examples for Ethernet --- .../examples/PachubeClient/PachubeClient.ino | 37 ++++++++++-------- .../PachubeClientString.ino | 39 ++++++++++--------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino index f169feb5e..4d4290d46 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 27 Feb 2012 + updated 16 Mar 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra http://arduino.cc/en/Tutorial/PachubeClient @@ -27,8 +27,6 @@ http://arduino.cc/en/Tutorial/PachubeClient #include #include - - #define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here #define FEEDID 00000 // replace your feed ID #define USERAGENT "My Project" // user agent is the project name @@ -45,9 +43,14 @@ IPAddress ip(10,0,1,20); // initialize the library instance: EthernetClient client; -long lastConnectionTime = 0; // last time you connected to the server, in milliseconds -boolean lastConnected = false; // state of the connection last time through the main loop -const int postingInterval = 10000; //delay between updates to Pachube.com +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +IPAddress server(216,52,233,122); // numeric IP for api.pachube.com +//char server[] = "api.pachube.com"; // name address for pachube API + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +boolean lastConnected = false; // state of the connection last time through the main loop +const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com void setup() { // start serial port: @@ -93,13 +96,13 @@ void loop() { // this method makes a HTTP connection to the server: void sendData(int thisData) { // if there's a successful connection: - if (client.connect("www.pachube.com", 80)) { + if (client.connect(server, 80)) { Serial.println("connecting..."); - // send the HTTP PUT request: + // send the HTTP PUT request: client.print("PUT /v2/feeds/"); client.print(FEEDID); client.println(".csv HTTP/1.1"); - client.print("Host: api.pachube.com\n"); + client.println("Host: api.pachube.com"); client.print("X-PachubeApiKey: "); client.println(APIKEY); client.print("User-Agent: "); @@ -112,24 +115,24 @@ void sendData(int thisData) { client.println(thisLength); // last pieces of the HTTP PUT request: - client.print("Content-Type: text/csv\n"); - client.println("Connection: close\n"); + client.println("Content-Type: text/csv"); + client.println("Connection: close"); + client.println(); // here's the actual content of the PUT request: - client.print("sensor1,"); + client.print("sensor1,"); client.println(thisData); - - // note the time that the connection was made: - lastConnectionTime = millis(); + } else { - // if you couldn't make a connection: + // if you couldn't make a connection: Serial.println("connection failed"); Serial.println(); Serial.println("disconnecting."); client.stop(); - lastConnected = client.connected(); } + // note the time that the connection was made or attempted: + lastConnectionTime = millis(); } diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino index 3e1b08c73..3535287ac 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 27 Feb 2012 + updated 16 Mar 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra http://arduino.cc/en/Tutorial/PachubeClientString @@ -40,14 +40,19 @@ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // fill in an available IP address on your network here, // for manual configuration: -IPAddress ip(10,0,0,20); +IPAddress ip(10,0,1,20); // initialize the library instance: EthernetClient client; -unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds -boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10000; //delay between updates to Pachube.com +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(216,52,233,122); // numeric IP for api.pachube.com +char server[] = "api.pachube.com"; // name address for pachube API + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +boolean lastConnected = false; // state of the connection last time through the main loop +const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com void setup() { // start serial port: @@ -66,9 +71,9 @@ void loop() { // read the analog sensor: int sensorReading = analogRead(A0); // convert the data to a String to send it: - + String dataString = "sensor1,"; - dataString += sensorReading; + dataString += sensorReading; // you can append multiple readings to this String if your // pachube feed is set up to handle multiple values: @@ -93,7 +98,7 @@ void loop() { } // if you're not connected, and ten seconds have passed since - // your last connection, then connect again and send data: + // your last connection, then connect again and send data: if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(dataString); } @@ -105,29 +110,27 @@ void loop() { // this method makes a HTTP connection to the server: void sendData(String thisData) { // if there's a successful connection: - if (client.connect("api.pachube.com", 80)) { + if (client.connect(server, 80)) { Serial.println("connecting..."); // send the HTTP PUT request: client.print("PUT /v2/feeds/"); client.print(FEEDID); client.println(".csv HTTP/1.1"); - client.print("Host: api.pachube.com\n"); + client.println("Host: api.pachube.com"); client.print("X-PachubeApiKey: "); client.println(APIKEY); client.print("User-Agent: "); client.println(USERAGENT); client.print("Content-Length: "); - client.println(thisData.length(), DEC); + client.println(thisData.length()); // last pieces of the HTTP PUT request: - client.print("Content-Type: text/csv\n"); - client.println("Connection: close\n"); + client.println("Content-Type: text/csv"); + client.println("Connection: close"); + client.println(); // here's the actual content of the PUT request: client.println(thisData); - - // note the time that the connection was made: - lastConnectionTime = millis(); } else { // if you couldn't make a connection: @@ -135,8 +138,8 @@ void sendData(String thisData) { Serial.println(); Serial.println("disconnecting."); client.stop(); - lastConnected = client.connected(); } + // note the time that the connection was made or attempted: + lastConnectionTime = millis(); } - From a46facad7010a682a39d8034083a6d178465e826 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Fri, 16 Mar 2012 08:45:29 -0400 Subject: [PATCH 6/9] Updated notes in digitalInputPullup --- .../2.Digital/DigitalIputPullup/DigitalIputPullup.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino index 955d27465..6f540e9ff 100644 --- a/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino +++ b/build/shared/examples/2.Digital/DigitalIputPullup/DigitalIputPullup.ino @@ -37,8 +37,8 @@ void loop(){ Serial.println(sensorVal); // Keep in mind the pullup means the pushbutton's - // logic is inverted. It goes HIGH when it's pressed, - // and LOW when it's not. Turn on pin 13 when the + // logic is inverted. It goes HIGH when it's open, + // and LOW when it's pressed. Turn on pin 13 when the // button's pressed, and off when it's not: if (sensorVal == HIGH) { digitalWrite(13, LOW); From da09e0c867071f9d360947fc078ce60cebc228ce Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Tue, 20 Mar 2012 10:37:15 -0400 Subject: [PATCH 7/9] Updated Ethernet WebServer example to give more diagnostic info --- .../Ethernet/examples/WebServer/WebServer.ino | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index 6837f8320..7cf2c53cf 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 4 Sep 2010 + modified 20 Mar 2012 by Tom Igoe */ @@ -20,7 +20,8 @@ // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1, 177); // Initialize the Ethernet server library @@ -28,23 +29,27 @@ IPAddress ip(192,168,1, 177); // (port 80 is default for HTTP): EthernetServer server(80); -void setup() -{ +void setup() { + Serial.begin(9600); // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); + Serial.print("server is at "); + Serial.println(Ethernet.localIP()); } -void loop() -{ + +void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { + Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); + Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply @@ -52,16 +57,22 @@ void loop() // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); + client.println("Connnection: close"); client.println(); - + client.println(""); + client.println(""); + // add a meta refresh tag, so the browser pulls again every 5 seconds: + client.println(""); // output the value of each analog input pin for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); client.print("analog input "); client.print(analogChannel); client.print(" is "); - client.print(analogRead(analogChannel)); - client.println("
"); + client.print(sensorReading); + client.println("
"); } + client.println(""); break; } if (c == '\n') { @@ -78,5 +89,7 @@ void loop() delay(1); // close the connection: client.stop(); + Serial.println("client disonnected"); } } + From 87eaf2d0c50840862244f27678a265ae21a37e71 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Tue, 20 Mar 2012 14:48:24 -0400 Subject: [PATCH 8/9] Updated comments in softwareSerial example --- .../SoftwareSerialExample.ino | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index 1f535bdef..088c7d2ae 100644 --- a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -1,5 +1,22 @@ +/* + Software serial multple serial test + + Receives from the hardware serial, sends to software serial. + Receives from software serial, sends to hardware serial. + + The circuit: + * Software serial TX attached to digital pin 2, RX to pin 3 + + created back in the mists of time + by Tom Igoe + based on Mikal Hart's example + + This example code is in the public domain. + + */ #include +// software serial port: TX = digital pin 2, RX = digital pin 3 SoftwareSerial mySerial(2, 3); void setup() From 19f513b943309ec66541d86684636d8819c64d19 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 20 Mar 2012 16:24:48 -0400 Subject: [PATCH 9/9] Updating comments in SoftwareSerial example. --- .../SoftwareSerialExample/SoftwareSerialExample.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino index 088c7d2ae..615d2b363 100644 --- a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -5,7 +5,8 @@ Receives from software serial, sends to hardware serial. The circuit: - * Software serial TX attached to digital pin 2, RX to pin 3 + * RX is digital pin 2 (connect to TX of other device) + * TX is digital pin 3 (connect to RX of other device) created back in the mists of time by Tom Igoe @@ -16,8 +17,7 @@ */ #include -// software serial port: TX = digital pin 2, RX = digital pin 3 -SoftwareSerial mySerial(2, 3); +SoftwareSerial mySerial(2, 3); // RX, TX void setup() {