Please select To the mobile version | Continue to access the desktop computer version
| |

Robot Forum

 Forgot password?
 Register
Search
View: 90101|Reply: 0

Using an Arduino as an ISP programmer

[Copy link]

16

Posts

0

Blogs

0

Albums

Administrator

Rank: 9Rank: 9Rank: 9

Credits
145
Post time: 2016-02-29 15:24:15
| Show all posts |Read mode
Bootloader1.jpg

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 originally written using Arduino 1.02 which was the latest at the time. I have since used these techniques with 1.06 without any problems but I have not tested it with the newer Arduino IDEs.

I normally use an Arduino Nano and some jumper wires 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.

Nano_programmer_600.jpg

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).

Step 1
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

Step 2

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.

Bootloader001.jpg

Step 3
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.

Step 4

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.
file:///C:/Users/OddBot/Desktop/MyStuff/Make%20an%20Arduino%20into%20ISP%20programmer%20_%20Let%27s%20Make%20Robots%21_files/Bootloader002.jpg

Bootloader002.jpg

ISP_pin_configurations.jpg
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 3 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.

MiniDriver_Programmer_ISP_header_600.jpg MicroMagicianV2_programmer_600.jpg Spider_programmer_600.jpg
Step 5
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.

Bootloader_cable_wiring_diagram.jpg

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.

Step 6
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 some cases the solder pad will be square instead of round.

Pin1_Mega.jpg        Pin1_LilyPad.jpg

Once you have connected your target, recheck all your pins, especially your power pins, Vcc and Gnd.


MiniDriver_Target.jpg

Step 7
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.

Bootloader006.jpg

Step 8
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.

Bootloader008.jpg

I have found that sometimes you will get an error message for no apparent reason.

Bootloader014.jpg

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.

Step 9

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.

programmer_hot_glue_header.jpg

Step 10
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.

Bootloader010.jpg

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:

Bootloader012.jpg

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.

burn_bootloder_on_Micro_magician.jpg

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.

Bootloader2_600.jpg

Good luck and enjoy!




















Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

dagurobot

2017-11-23 00:23 GMT+8 , Processed in 0.311904 sec., 16 queries .

Powered by Discuz! X3.2

Release 20140618, © 2004-2017 Dagurobot

Quick Reply To Top Return to the list