Make an Arduino into ISP programmer
The Arduino and Arduino compatible boards all use a small program called a bootloader to take serial data from your computer and store it in the Arduino's memory. You will need to "burn" the bootloader into the chip if:
- You are building your own board and have bought a blank chip.
- Your 5V rail dropped too low for too long and your bootloader was corrupted (perhaps due to flat batteries).
- You overwrote your bootloader at some time to save memory.
Fortunately The Arduino IDE includes a program called "ArduinoISP" that allows you to use one Arduino board as a programmer to burn the bootloader into another board (the target).
Using the latest versions of the Arduino IDE (V1.0 or later) you can write your code directly to the MCU without using the bootloader. This can overwrite the bootloader to give you more memory. The disadvantage of this is that you cannot update your code later using the USB interface.
PLEASE NOTE: This tutorial was written using Arduino 1.02 which was the latest at the time. I have used these techniques with 1.04 without any problems but some people have had trouble with 1.05 and later. If you cannot get this tutorial to work with 1.05 or later then please use 1.04.
I normally use an Arduino Nano as a programmer because of it's small size. This allows me to burn a bootloader or write code directly to the MCU by simply plugging it into the ISP header. I have used some hotglue to hold my jumper wires in a 3x2 configuration so that all I need to do is line up my white wire with pin one on the board.
In this tutorial I will show you how to convert almost any Arduino, Arduino clone or Arduino compatible board that uses an ATmega 8,168, 328, 1280 or 2560 into a programmer. I will then show you how to use it to program any other board that uses one of these processors. This tutorial does not cover some of the newer boards such as the Leonardo or the Due. You will need:
- An Arduino, Arduino clone or Arduino compatible board with 5V logic to use as your programmer.
- 6x female to female and 6x male to male jumper wires.
Optional parts if you want to program both 3.3V boards such as the LillyPad as well as 5V boards.
- 3x 4K7 resistors.
- 1x diode (1N4001 or 1N4148).
Open your Arduino IDE version 1.2 or later. If you have an earlier version then these instructions may not work. You can download the latest version here: http://arduino.cc/en/Main/Software
Go to File menu and select ArduinoISP from the Examples menu. There are instructions at the start of the program that explain the ISP interface pins. There are also instructions for adding LEDs but these are optional and are not shown in this tutorial.
Go to the Tools menu and select the com port and board type that matches the board you are going to use for a programmer. Upload the ArduinoISP sketch into your programmer.
Disconnect the USB cable and any other power source before you begin. At the begining of the ArduinoISP sketch there is information about what pins to use for the programmer as shown below. There is also some instructions for wiring up LEDs but these are optional and not included in the tutorial.
Note: in the above diagram that pin 5 of the target ISP header is always connected to reset. When you connect your wires to the programmer this wire will connect to D10 or D53 instead.
Start by connecting wires to your programmer. In my photos I use a different colour for each wire but I always use red for +Vcc and black for ground. Be very careful with Vcc and Gnd. If you accidentally swap them then you could fry something.
Below I show 4 different boards wired as a programmer. In each case, I am using the yellow wire for reset and it is plugged into D10 or D53. Note that all my boards have male header pins so I am using female to female jumper wires.
If you are using an Arduino that only has female headers for your programmer then you can join a male to male jumper wire with a female to female jumper wire to make a male to female jumper wire.
You can skip this step if you only want to program 5V target devices or if your target is a Micro Magician controller from DAGU. The Micro Magician already has the resistors and diode installed and can be programmed by both 5V and 3.3V programmers.
If you want to program both 5V and 3.3V target boards you will need to cut some of your wires and solder the resistors and diode in the middle of the wire as shown in the diagram below. make sure to use heatshrink or electrical tape to insulate your components and solder joints.
All ATmega processors have clamping diodes on the I/O pins to protect them from static. By placing 4K7 resistors in series for MISO, MOSI and SCK we limit the current through these clamping diodes to a safe level to prevent damage. The clamping diodes can then limit the 5V programmer's signals to a safe level for the 3.3V target. The diode allows the programmer to pull the target's reset pin low otherwise the target's reset pin is held high by a pullup resistor within the taget PCB.
The diagram below shows the standard programming cable and then the 5V to 3.3V version.
Note that the Vcc is not connected. When programming a 3.3V target, the target should be powered seperately. The grounds are linked by pin 6 of the target ISP header.
Connect the jumper wires to your target board ISP header. It is very important that you connect them correctly to prevent possible damage. There will always be some indication which pin is pin 1 of the ISP header. It is often a triangle or spot printed next to the pin.
In the case of the Lily Pad PCB shown below, pin 1 of the header has a square pad while the other pads are round. In the case of the Lily Pad shown below, you may want to use alligator clips to connect to the apropriate petal. As you can see here, ISP pin 1 connects to petal D12.
Once you have connected your target, recheck all your pins, especially your power pins, Vcc and Gnd.
Plug in your USB cable to the programmer. If the power LEDs on your boards light up dimly or not at all then quickly unplug your cable and recheck your wiring. Go back to the Tools menu and this time select yhe board type to match your target board. Your com port will still be that of your programmer. In my example here, the target is a MiniDriver from DAGU which uses an ATmega8A.
Go to the Tools menu again and make sure you have your programmer set to Arduino as ISP. You can now click on Burn Bootloader.
I have found that sometimes you will get an error message for no apparent reason.
Select Burn Bootloader a second time and it should work. If not, re-check your wiring. Be patient, Burning the bootloader is slower than uploading a sketch. You will see the RX, TX and D13 LEDs on your programmer flash slower than with a normal upload.
Once you know your wiring is correct and the bootloader has burned successfully you might want to glue the ISP header wires together so that you have a single 3x2 header rather than 6 individual wires. I cable tied my wires first and then applied some hot glue. This makes it easier for future use.
Using your programmer to load a sketch directly into the MCU via the ISP header is a relatively new feature of the Arduino IDE. This method of programming has 2 advantages.
- You can use the memory normally reserved for the bootloader which is useful for big sketches.
- You can program boards that do not have a built in USB interface.
The only disadvantage is you must always use a programmer to update your sketch. If your board does not has a built in USB interface then you will still need an external interface to use the serial monitor for debugging.
To upload your sketch via the programmer you must first go to the Tools menu and make sure that the com port is set to that of your programmer but the board type is set to that of the taget board (same as when you burn the bootloader).
Open your sketch, I'm using the blink example, and then go to the Files menu again to select Upload Using Programmer.
As with burning the bootloader, you may get an error on the first attempt but it should work fine by the second attempt. Once you have uploaded a sketch by this method you will need to re-burn the bootloader before you can upload sketches the normal way.If you do not then you will get this error:
Burning the bootloader is no different to uploading any other sketch except for it's location in memory. Re-burning the bootloader will not reduce the life expectancy of your Arduino.
One advantage of writing your sketch to a board that uses an ATmega8 is that you eliminate that annoying wait at the start. In the photo below I have written the Arduino ISP sketch directly to the Mini Driver and am now using the Mini Driver as a programmer without any start up delay.
The Arduino Mega and compatible controllers can also be used as programmers just as easy. Normally I do not use them as a programmer simply because of their larger size.