From ec09ead6ac7528239d25853c41b94a6dbfb0bd9b Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 21 Oct 2011 11:54:11 -0400 Subject: [PATCH 01/11] Lowering timer 1 prescale factor (to 8 from 64) for F_CPU less than 8 MHz. Otherwise, you can see flicker on an LED. --- hardware/arduino/cores/arduino/wiring.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hardware/arduino/cores/arduino/wiring.c b/hardware/arduino/cores/arduino/wiring.c index 1b3fd44fa..bc01949e2 100755 --- a/hardware/arduino/cores/arduino/wiring.c +++ b/hardware/arduino/cores/arduino/wiring.c @@ -221,10 +221,14 @@ void init() // set timer 1 prescale factor to 64 sbi(TCCR1B, CS11); +#if F_CPU >= 8000000L sbi(TCCR1B, CS10); +#endif #elif defined(TCCR1) && defined(CS11) && defined(CS10) sbi(TCCR1, CS11); +#if F_CPU >= 8000000L sbi(TCCR1, CS10); +#endif #endif // put timer 1 in 8-bit phase correct pwm mode #if defined(TCCR1A) && defined(WGM10) From b14a3c501ebd62afff251fb69169df6a6bcf9758 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 21 Oct 2011 18:25:14 -0400 Subject: [PATCH 02/11] Lock / unlock fuses and hex file now optional for burn bootloader command. This allows the "burn bootloader" command to be used, for example, to set the fuses on a microcontroller without actually loading a bootloader onto it. http://code.google.com/p/arduino/issues/detail?id=683 http://code.google.com/p/arduino/issues/detail?id=684 --- .../processing/app/debug/AvrdudeUploader.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/app/src/processing/app/debug/AvrdudeUploader.java b/app/src/processing/app/debug/AvrdudeUploader.java index 2fec8f6f6..d5db258ad 100755 --- a/app/src/processing/app/debug/AvrdudeUploader.java +++ b/app/src/processing/app/debug/AvrdudeUploader.java @@ -132,7 +132,8 @@ public class AvrdudeUploader extends Uploader { Map boardPreferences = Base.getBoardPreferences(); List fuses = new ArrayList(); fuses.add("-e"); // erase the chip - fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m"); + if (boardPreferences.get("bootloader.unlock_bits") != null) + fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m"); if (boardPreferences.get("bootloader.extended_fuses") != null) fuses.add("-Uefuse:w:" + boardPreferences.get("bootloader.extended_fuses") + ":m"); fuses.add("-Uhfuse:w:" + boardPreferences.get("bootloader.high_fuses") + ":m"); @@ -146,26 +147,32 @@ public class AvrdudeUploader extends Uploader { } catch (InterruptedException e) {} Target t; + List bootloader = new ArrayList(); String bootloaderPath = boardPreferences.get("bootloader.path"); - if (bootloaderPath.indexOf(':') == -1) { - t = Base.getTarget(); // the current target (associated with the board) - } else { - String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':')); - t = Base.targetsTable.get(targetName); - bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1); + if (bootloaderPath != null) { + if (bootloaderPath.indexOf(':') == -1) { + t = Base.getTarget(); // the current target (associated with the board) + } else { + String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':')); + t = Base.targetsTable.get(targetName); + bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1); + } + + File bootloadersFile = new File(t.getFolder(), "bootloaders"); + File bootloaderFile = new File(bootloadersFile, bootloaderPath); + bootloaderPath = bootloaderFile.getAbsolutePath(); + + bootloader.add("-Uflash:w:" + bootloaderPath + File.separator + + boardPreferences.get("bootloader.file") + ":i"); } - - File bootloadersFile = new File(t.getFolder(), "bootloaders"); - File bootloaderFile = new File(bootloadersFile, bootloaderPath); - bootloaderPath = bootloaderFile.getAbsolutePath(); - - List bootloader = new ArrayList(); - bootloader.add("-Uflash:w:" + bootloaderPath + File.separator + - boardPreferences.get("bootloader.file") + ":i"); - bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m"); + if (boardPreferences.get("bootloader.lock_bits") != null) + bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m"); - return avrdude(params, bootloader); + if (bootloader.size() > 0) + return avrdude(params, bootloader); + + return true; } public boolean avrdude(Collection p1, Collection p2) throws RunnerException { From dc21e1da8a20d666e0736b22b6bc881505e796e5 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 24 Oct 2011 10:55:39 -0400 Subject: [PATCH 03/11] Added examples for the Keyboard library of the Leonardo --- .../KeyboardMessage/KeyboardMessage.ino | 43 +++++++++++++++++++ .../KeyboardSerial/KeyboardSerial.ino | 33 ++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 libraries/Keyboard/KeyboardMessage/KeyboardMessage.ino create mode 100644 libraries/Keyboard/KeyboardSerial/KeyboardSerial.ino diff --git a/libraries/Keyboard/KeyboardMessage/KeyboardMessage.ino b/libraries/Keyboard/KeyboardMessage/KeyboardMessage.ino new file mode 100644 index 000000000..51b1ce2c6 --- /dev/null +++ b/libraries/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -0,0 +1,43 @@ +/* + Keyboard Button test + + Sends a text string when a button is pressed. + + The circuit: + * pushbutton attached from pin 4 to +5V + * 10-kilohm resistor attached from pin 4 to ground + + created 24 Oct 2011 + by Tom Igoe + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/KeyboardButton + */ + +const int buttonPin = 4; // input pin for pushbutton +int previousButtonState = HIGH; // for checking the state of a pushButton +int counter = 0; // button push counter + +void setup() { + // make the pushButton pin an input: + pinMode(buttonPin, INPUT); +} + +void loop() { + // read the pushbutton: + int buttonState = digitalRead(buttonPin); + // if the button state has changed, + if ((buttonState != previousButtonState) + // and it's currently pressed: + && (buttonState == HIGH)) { + // increment the button counter + counter++; + // type out a message + Keyboard.print("You pressed the button: "); + Keyboard.print(counter); + Keyboard.println(" times."); + } + // save the current button state for comparison next time: + previousButtonState = buttonState; +} diff --git a/libraries/Keyboard/KeyboardSerial/KeyboardSerial.ino b/libraries/Keyboard/KeyboardSerial/KeyboardSerial.ino new file mode 100644 index 000000000..b64b6272b --- /dev/null +++ b/libraries/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -0,0 +1,33 @@ +/* + Keyboard test + + Reads a byte from the serial port, sends a keystroke back. + The sent keystroke is one higher than what's received, e.g. + if you send a, you get b, send A you get B, and so forth. + + The circuit: + * none + + created 21 Oct 2011 + by Tom Igoe + +This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/KeyboardSerial + */ + +void setup() { + // open the serial port: +Serial.begin(9600); +} + +void loop() { + // check for incoming serial data: + if (Serial.available() > 0) { + // read incoming serial data: + char inChar = Serial.read(); + // Type the next ASCII value from what you received: + Keyboard.write(inChar+1); + } +} + From 8336c8821147d42336d94478fe891e67231cec72 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 24 Oct 2011 15:44:01 -0400 Subject: [PATCH 04/11] Correcting analogReference() constants for ATtiny24/44/84 and 25/45/85. DEFAULT, EXTERNAL, and INTERNAL have different values on those processors. --- hardware/arduino/cores/arduino/Arduino.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hardware/arduino/cores/arduino/Arduino.h b/hardware/arduino/cores/arduino/Arduino.h index 7f2fc0582..07216f907 100755 --- a/hardware/arduino/cores/arduino/Arduino.h +++ b/hardware/arduino/cores/arduino/Arduino.h @@ -40,6 +40,11 @@ extern "C"{ #define FALLING 2 #define RISING 3 +#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) +#define DEFAULT 0 +#define EXTERNAL 1 +#define INTERNAL 2 +#else #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define INTERNAL1V1 2 #define INTERNAL2V56 3 @@ -48,6 +53,7 @@ extern "C"{ #endif #define DEFAULT 1 #define EXTERNAL 0 +#endif // undefine stdlib's abs if encountered #ifdef abs From 18838fb44a64e6d2550f79d447360ec46dd832ce Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 24 Oct 2011 16:45:44 -0400 Subject: [PATCH 05/11] Renaming LED to LED_BUILTIN. http://code.google.com/p/arduino/issues/detail?id=651 --- hardware/arduino/variants/mega/pins_arduino.h | 2 +- hardware/arduino/variants/standard/pins_arduino.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/variants/mega/pins_arduino.h b/hardware/arduino/variants/mega/pins_arduino.h index 237173adc..57ec97f9c 100644 --- a/hardware/arduino/variants/mega/pins_arduino.h +++ b/hardware/arduino/variants/mega/pins_arduino.h @@ -39,7 +39,7 @@ const static uint8_t SCK = 52; const static uint8_t SDA = 20; const static uint8_t SCL = 21; -const static uint8_t LED = 13; +const static uint8_t LED_BUILTIN = 13; const static uint8_t A0 = 54; const static uint8_t A1 = 55; diff --git a/hardware/arduino/variants/standard/pins_arduino.h b/hardware/arduino/variants/standard/pins_arduino.h index 3999d1fcd..6e774d462 100644 --- a/hardware/arduino/variants/standard/pins_arduino.h +++ b/hardware/arduino/variants/standard/pins_arduino.h @@ -44,7 +44,7 @@ const static uint8_t SCK = 13; const static uint8_t SDA = 18; const static uint8_t SCL = 19; -const static uint8_t LED = 13; +const static uint8_t LED_BUILTIN = 13; const static uint8_t A0 = 14; const static uint8_t A1 = 15; From f729e0321b864bac6cc52a4adde5f7b059d85c68 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 24 Oct 2011 16:50:15 -0400 Subject: [PATCH 06/11] Moving ARDUINO_MAIN from main.cpp to wiring_digital.c and hiding PA, PB, etc. http://code.google.com/p/arduino/issues/detail?id=677 http://code.google.com/p/arduino/issues/detail?id=691 --- hardware/arduino/cores/arduino/Arduino.h | 2 ++ hardware/arduino/cores/arduino/main.cpp | 1 - hardware/arduino/cores/arduino/wiring_digital.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/cores/arduino/Arduino.h b/hardware/arduino/cores/arduino/Arduino.h index 07216f907..ebd374a74 100755 --- a/hardware/arduino/cores/arduino/Arduino.h +++ b/hardware/arduino/cores/arduino/Arduino.h @@ -148,6 +148,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; #define NOT_A_PIN 0 #define NOT_A_PORT 0 +#ifdef ARDUINO_MAIN #define PA 1 #define PB 2 #define PC 3 @@ -159,6 +160,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; #define PJ 10 #define PK 11 #define PL 12 +#endif #define NOT_ON_TIMER 0 #define TIMER0A 1 diff --git a/hardware/arduino/cores/arduino/main.cpp b/hardware/arduino/cores/arduino/main.cpp index 0ef525651..34450f46d 100755 --- a/hardware/arduino/cores/arduino/main.cpp +++ b/hardware/arduino/cores/arduino/main.cpp @@ -1,4 +1,3 @@ -#define ARDUINO_MAIN #include int main(void) diff --git a/hardware/arduino/cores/arduino/wiring_digital.c b/hardware/arduino/cores/arduino/wiring_digital.c index dd1b94979..97ef1343d 100755 --- a/hardware/arduino/cores/arduino/wiring_digital.c +++ b/hardware/arduino/cores/arduino/wiring_digital.c @@ -24,6 +24,7 @@ $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ */ +#define ARDUINO_MAIN #include "wiring_private.h" #include "pins_arduino.h" From e1dbe688e9a5cfca52685e13547d0cf1f83d8574 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 24 Oct 2011 16:53:41 -0400 Subject: [PATCH 07/11] NewSoftSerial -> SoftwareSerial in keywords.txt. http://code.google.com/p/arduino/issues/detail?id=640 --- libraries/SoftwareSerial/keywords.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SoftwareSerial/keywords.txt b/libraries/SoftwareSerial/keywords.txt index 90d4c152d..6b3e3ce70 100755 --- a/libraries/SoftwareSerial/keywords.txt +++ b/libraries/SoftwareSerial/keywords.txt @@ -6,7 +6,7 @@ # Datatypes (KEYWORD1) ####################################### -NewSoftSerial KEYWORD1 +SoftwareSerial KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) From d9f9676d23c7430f0cc31e10641861013b9a1704 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 25 Oct 2011 11:15:14 -0400 Subject: [PATCH 08/11] Bug fix in replace(). http://code.google.com/p/arduino/issues/detail?id=694 --- hardware/arduino/cores/arduino/WString.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/cores/arduino/WString.cpp b/hardware/arduino/cores/arduino/WString.cpp index ad8d8289f..3e813316e 100644 --- a/hardware/arduino/cores/arduino/WString.cpp +++ b/hardware/arduino/cores/arduino/WString.cpp @@ -593,7 +593,7 @@ void String::replace(const String& find, const String& replace) if (size == len) return; if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! int index = len - 1; - while ((index = lastIndexOf(find, index)) >= 0) { + while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { readFrom = buffer + index + find.len; memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); len += diff; From 6a68361a141b4d04de73c86719388790d37c447b Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 25 Oct 2011 22:50:57 -0400 Subject: [PATCH 09/11] Updating Mac Info.plist version to 1.0-rc2. --- build/macosx/template.app/Contents/Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/macosx/template.app/Contents/Info.plist b/build/macosx/template.app/Contents/Info.plist index e284081dd..6fe5351f4 100755 --- a/build/macosx/template.app/Contents/Info.plist +++ b/build/macosx/template.app/Contents/Info.plist @@ -7,11 +7,11 @@ CFBundleGetInfoString - 1.0-rc1 + 1.0-rc2 CFBundleVersion 0100 CFBundleShortVersionString - 1.0-rc1 + 1.0-rc2 CFBundleAllowMixedLocalizations From d16eeb0af3eb3e23202de663a09ca44434c738e9 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Wed, 26 Oct 2011 13:22:30 -0400 Subject: [PATCH 10/11] Modified Pachube examples to use manual Ethernet config if DCHP fails. --- .../examples/PachubeClient/PachubeClient.ino | 14 ++++++++------ .../PachubeClientString.ino | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino index e626113b0..8f405e7af 100644 --- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino +++ b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino @@ -11,7 +11,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 15 March 2010 - updated 4 Sep 2010 + updated 26 Oct 2011 by Tom Igoe http://www.tigoe.net/pcomp/code/category/arduinowiring/873 @@ -28,6 +28,9 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +// fill in an available IP address on your network here, +// for manual configuration: +IPAddress ip(10,0,1,20); // initialize the library instance: EthernetClient client; @@ -38,15 +41,14 @@ const int postingInterval = 10000; //delay between updates to Pachube.com void setup() { // start serial port: Serial.begin(9600); + // give the ethernet module time to boot up: + delay(1000); // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); - // no point in carrying on, so do nothing forevermore: - for(;;) - ; + // Configure manually: + Ethernet.begin(mac, ip); } - // give the ethernet module time to boot up: - delay(1000); } void loop() { diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino index 4b97c4175..4a03100f2 100644 --- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino +++ b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino @@ -14,7 +14,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 15 March 2010 - updated 4 Sep 2010 + updated 26 Oct 2011 by Tom Igoe This code is in the public domain. @@ -28,6 +28,9 @@ // fill in your address here: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +// fill in an available IP address on your network here, +// for manual configuration: +IPAddress ip(10,0,1,20); // initialize the library instance: EthernetClient client; @@ -37,16 +40,16 @@ boolean lastConnected = false; // state of the connection last time through const int postingInterval = 10000; //delay between updates to Pachube.com void setup() { - // start the ethernet connection and serial port: + // start serial port: Serial.begin(9600); - if (Ethernet.begin(mac) == 0) { - Serial.println("Failed to configure Ethernet using DHCP"); - // no point in carrying on, so do nothing forevermore: - for(;;) - ; - } // give the ethernet module time to boot up: delay(1000); + // start the Ethernet connection: + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Configure manually: + Ethernet.begin(mac, ip); + } } void loop() { From 432fab12dbba468c8db47d75e67eeee10160140d Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Wed, 26 Oct 2011 13:23:04 -0400 Subject: [PATCH 11/11] Fixed SerialCallResponseASCII example so sensor output matches what Processing sketch expects. --- .../SerialCallResponseASCII.ino | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/build/shared/examples/4.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/build/shared/examples/4.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index acf400051..ea624ba1a 100644 --- a/build/shared/examples/4.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/build/shared/examples/4.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -19,7 +19,7 @@ Created 26 Sept. 2005 by Tom Igoe - modified 30 Aug 2011 + modified 26 Oct 2011 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. @@ -47,12 +47,10 @@ void loop() if (Serial.available() > 0) { // get incoming byte: inByte = Serial.read(); - // read first analog input, divide by 4 to make the range 0-255: - firstSensor = analogRead(A0)/4; - // delay 10ms to let the ADC recover: - delay(10); - // read second analog input, divide by 4 to make the range 0-255: - secondSensor = analogRead(A1)/4; + // read first analog input: + firstSensor = analogRead(A0); + // read second analog input: + secondSensor = analogRead(A1); // read switch, map it to 0 or 255L thirdSensor = map(digitalRead(2), 0, 1, 0, 255); // send sensor values: