You can use Arduino-compatible AVR boards like the Freetronics Eleven, EtherTen, EtherMega or LeoStick as external programmers for other Arduino boards. You can use this to upload sketches, or to reflash bootloaders.
This is an alternative to using a dedicated AVR ICSP programmer like the Freetronics USBasp ICSP Programmer.
The Arduino tutorial "Using an Arduino as an AVR ISP (In-System Programmer" also describes this, but the examples there are only for Arduino Uno, Duemilanove, or Diecimila or compatible. For Mega-compatible or Leonardo-compatible boards the wiring is different.
Leonardo/LeoStick on Windows: If you're using a Leonardo-compatible board like a LeoStick as the Programmer on Windows, you will need the Arduino IDE version 1.6 or newer.
What you'll need
- The board you want to program (the Target.)
- An Arduino-compatible board you can use as the Programmer.
- Arduino IDE installed (recommend 1.6 or newer.)
- Breadboard leads to connect the programmer to the target.
Programmer Sketch
The Programmer needs to run an Arduino example sketch called "ArduinoISP", which is based on the mega-isp project by Randall Bohn.
Select File -> Examples -> ArduinoISP in the Arduino IDE to open the sketch, then upload it to the Programmer board.
Leonardo/LeoStick only:
Before uploading, look for this line near the top of the sketch:
#define RESET SSAnd change it to:
#define RESET 10
Programmer Wiring
You need to wire the SPI interface from the Programmer to the Target, except for the Reset pin on the Target which is toggled independently by the Programmer.
This diagram shows one possible setup, of an Eleven (Uno-compatible) programming a LeoStick (Leonardo-compatible) using the 6-pin ICSP headers on each board:
There are other alternative pins you can use. Here's a table of all six connections, and the possible pins you can choose for each:Signal Name | Programmer Pin | Target Pin |
---|---|---|
MISO | ICSP pin 1 (or D12 on Eleven/Uno, D50 on Mega.) | |
+5V | ICSP pin 2 or any 5V pin | |
SCK | ICSP pin 3 (or D13 on Eleven/Uno, D52 on Mega.) | |
MOSI | ICSP pin 4 (or D11 on Eleven/Uno, D51 on Mega.) | |
Reset | D10 (D53 on Mega) | ICSP pin 5 or RST pin |
Ground | ICSP pin 6 or any GND pin |
Note that on Uno-compatible boards like the Eleven there are two ICSP headers, one for the main microcontroller (as shown above) and a USB ICSP header for the Atmega8u2/16u2 which acts as the Serial to USB interface. You want to connect to the main ICSP on the Programmer. The ICSP header on the Target depends on which chip you want to reprogram.
Disabling auto reset
You may need to disable auto-reset on the Programmer board. You don't need to do this if you're using a Leonardo-compatible Programmer like a LeoStick.
On Freetronics boards, you can disable auto-reset permanently by cutting the solder jumper marked "RST-EN" on the board. However then you'll need to press the reset button every time you want to upload a new sketch.
A temporary way to disable auto-reset is to place a 10 uF capacitor between the RST and GND pins (on Uno-compatible or recent Mega-compatible boards) or a 120 ohm resistor between the RST and 5V pins (Duemilanove or Diecimila.) More details are available on the Arduino Playground.
Uploading Arduino Bootloader
To use your new programmer to upload a bootloader:- Under Tools -> Board, choose the Target board type.
- Under Tools -> Serial Port, leave the serial port belonging to the Programmer (that you used to upload the ArduinoISP sketch.
- Leonardo/LeoStick Programmers only: open the Arduino serial monitor monitor, use the serial port speed dropdown in the bottom-right to change the serial port to any different value that is not 1200bps, then close the serial monitor window. Workaround for this issue.
- Under Tools -> Programmer, choose either "Arduino as ISP" or (if using a LeoStick/Leonardo programmer and IDE 1.6 or newer) "Arduino as ISP (Leonardo)"
- Choose Tools -> Burn Bootloader
LeoStick only: The LeoStick onboard LED will "breathe" green when the ArduinoISP sketch is running.
Uploading Sketches
If you're using the Programmer to upload sketches to the Target, follow the instructions on the Burning sketches to the Arduino board with an external programmer page.
Uploading Using avrdude
To use avrdude with the Programmer, use the arguments "-cstk500v1 -b19200" (non-LeoStick Programmer) or "-carduino -b19200" (LeoStick Programmer) to choose the programmer name and the baud rate. Otherwise use avrdude as normal for any external programmer.