Introduction: How to Program a AVR (arduino) With Another Arduino

Picture of How to Program a AVR (arduino) With Another Arduino

This instructables is usefull if:

* you've got your arduino with atmega168 and you bought an atmega328 at you local electronics store. It doesn't have an arduino bootloader

* you want to make a project that doesn't use arduino - just a regular AVR chip (like the USBTinyISP) - you have a clean attiny2313/attiny48 etc that you want to burn firmware on.

Normally  you would have to have an ISP (In System Programmer) like USBTinyISP to program your new chip.  Having the arduino you can teach it to be a programmer thank to a great work done by Randall Bohn. He created Mega-ISP - an arduino sketch that works like a programmer.

Step 1: What Do You Need ?

Picture of What Do You Need ?

* a working Arduino (or a clone - i'm using the BBB - BareBonesBoard and a RBBB - RealBareBonesBoard by ModernDevices)
* a chip that you want to program (tested with atmega8,atmega168,atmega368, attiny2313, attiny13)
* a breadboard or a board with ISP header
* 3 leds + 3 resistors
* breadboard wires

Step 2: Making the Mega-isp Programmer on a Breadboard

Picture of Making the Mega-isp Programmer on a Breadboard

There are two ways to connect your Arduino to program a chip.

You can plug your avr chip to a breadboard and connect 5v and GND to the respective pins (check the datasheet!) + a pullup resistor to reset and wire pins from you arduino to the chip.
These are the lines on Arduino and their function
13 - SCK
12 - MISO
11 - MOSI
10 - RST (Reset)

Or you can make a 2x3pin ISP header that you can plug into a board that provides one (another arduino board).
The pinout for the ISP header is on the third image

There are 3 leds to indicate the status of the programmer.
pin 9 - blue led - its the hearbeat of the programmer.
pin 8 - red led - indicates an error
pin 7 - green led - indicates that the programming is taking place
(i was lazy so i didn't match the colors in my setup)

Here are the drawings made in Fritzing

You can alsa make a MEGA-isp shield. Yaroslav Osadchyy designed the shield in eagle. You can get the eagle files on his site:

Step 3: Uploading the Sketch

Picture of Uploading the Sketch

Download the sketch from mega-isp google code.( at the time of writing).
Unpack it and run arduino ide and open avrisp.pde.
Upload it to your arduino board.
Heartbeat led should start beating.

Step 4: Using With Avrdude

Picture of Using With Avrdude

To use with avrdude (and all GUIs that use it) you have to select the 'avrisp' programmer. the safest bitrate is 19200.

To test your your new atmega168 from commandline try:
$ avrdude -p m168 -P /dev/ttyUSB0 -c avrisp -b 19200

/dev/USB0 is the port that arduino is connected to my linux box (your's may be com5). This can be checked in arduino IDE in Tools -> Serial Port.

You should get:
[kabturek@hal-9000 ~]# avrdude -p m168 -P /dev/ttyUSB0 -c avrisp -b 19200

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9406

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

That means everything is ok.

If you get errors - check the last step.

Step 5: Burning USBtinyISP Firmware to an Attiny2313

Picture of Burning USBtinyISP Firmware to an Attiny2313

The USBTinyISP is a great programmer from LadyAda thats really cheap - 22$.
I had a spare attiny2313 and some parts so i decided to make one myself. If you don't have any experience in making PCB i advice you buy the kit cause it's higher quality than you can make yourself :). At least buy the PCB if you want to build one. You can get it from Adafruit.

Connect the ATtiny2313
In the last picture you can see the attiny2313 with the pins used for ISP in red. The picture is from LadyAda avr tutorial.

Burning the firmware:

Unpack the USBTinyISP firmware.

Go to the spi dir and run
$ avrdude -p pt2313 -P /dev/ttyUSB0 -c avrisp -b 19200
to check if everything is ok with the chip.

Now set the fuses:
$ avrdude -P /dev/ttyUSB0 -c avrisp -b 19200 -pt2313 -U hfuse:w:0xdf:m -U lfuse:w:0xef:m

Now you should attach the 12mhz external oscillator to the chip.

And burn the firmware:
$ avrdude -B 1 -pt2313 -U flash:w:main.hex -P /dev/ttyUSB0 -c avrisp -b 19200

Voila. Your attiny2313 has the USBTinyISP firmware.

Step 6: Burning the Arduino Bootloader

Picture of Burning the Arduino Bootloader

I cheated a bit cause i used a RBBB to simplify the connections. The schema is on picture #2.
If you use 2 arduinos use the picture #3 and connect the ISP pin to the ICSP 2x3header on the second(slave) arduino.Only connect the usb power to the first board.

The GUI way
This is a little tricky cause you can't just use Tools-> Burn Bootloader -> w/ AVR ISP cause the default speed is too big for mega-isp.
Find avrdude.conf that comes with arduino IDE  (in arduino/hardware/tools/avrdude.conf) and change the boundrate for avrisp programmer from 115200 to 19200 (around line 312 )
Find and change in avrdude.conf 
  id    = "avrisp";
  desc  = "Atmel AVR ISP";
  baudrate = 115200;    # default is 115200
  type  = stk500;

  id    = "avrisp";
  desc  = "Atmel AVR ISP";
  baudrate = 19200;    # default is 115200
  type  = stk500;

Now you can use Tools-> Burn Bootloader -> w/ AVR ISP (after you select the proper board from the Tools menu)

You can also use the commandline:
Edit arduino/hardware/bootloaders/atmega/Makefile
and change ISPTOOL/PORT/SPEED to:
# enter the parameters for the avrdude isp tool
ISPTOOL    = avrisp
ISPPORT    = /dev/ttyUSB0
ISPSPEED   = -b 19200

no you can write
$ make diecimila_isp
to burn fuses and the bootloader.

Now connect you new arduino to usb and burn the blinky!

Step 7: Troubleshooting

Picture of Troubleshooting

Avrdude errors:
avrdude: ser_open(): can't open device "/dev/ttyUSB0": No such file or directory
You have the wrong port (-P) specified or your arduino isn't connected. check the connection

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

This is kind of general error. Your chip isn't recognized.
Check the connection on the board (GND/5V connected to pins ?)
You will get this error when your chip is configured to use an external oscillator and it isnt working (there isn't one or it isn't oscillating properl - 22pf caps missing ?)


fran52 (author)2016-02-29

Unpack the USBTinyISP firmware.

from where???

victor.valadez.547 (author)2015-04-23

There is an alternative set of instructions that works if you have an Arduino Uno and want to transform it into an universal programmer for any stand alone AVR. Read this tutorial:

"Arduino Uno R3 as a true ISP programmer for any Attiny and Atmega AVR"


No boot-loader has to be first loaded into your target AVR. You can simply program the Attiny or Atmega micro-controllers, existent on the breadboard, directly with the hex file generated from the source code you wrote (Blink a led, for example).

KarolisL (author)2012-05-09


can you help me?
PC doesnt see my programmer. Everything is ok with wiring. I think i did something bad with firmware burning.

As i understood i should insert hex from spi folder only or I should compile makefiles in 1 hex from all folder?

Can u upload hex which you used?

phenoptix (author)2012-03-19

Thanks for the ibble! Found it very useful for information programming an ATTiny85 (with slightly different board layout). Steps were largely the same. Cheers!

carnotricecooker (author)2012-02-26

Hi kabturek, I'm a little confused on this part. I'm not quite sure through what you're sending the commands to upload firmware onto the ATTINY2313. Are you using the Arduino as an AVR programmer to upload the firmware or are you using a USBTinyISP that you bought to upload it? And after this, don't you still need the hardware support files to upload an Arduino sketch onto the ATTINY2313? Help on this section would be much appreciated.

jcbed (author)2011-06-04

for the bit about burning the tiny usb isp chip ummmmm... what pullup didu use if anney and do you have a fritzing image of it or any more info .
btw great indestrustiabel

meyer_lanski (author)2011-05-26

Great Instructables, thank you very much for this. very informative. In your poist you mention you could use this method to program attiny13 chips. How do you go about wiring it up? the image you show is an atmega chip i believe which has more pins.

Sorry for the noob question. This is my first attempt at programming a standalone chip!

Any help would be appreciated.
Thank you.

kabturek (author)meyer_lanski2011-05-26

Look at the attiny13 datasheet:
On page 2 you've got te pinout for an atmega. You need these signals :
13 - SCK
12 - MISO
11 - MOSI
10 - RST (Reset)

on attiny13 they are on pins::
SCK is pin 7
MISO - pin 6
MOSI - pin 5
RESET - pin 1
GND is pin 4 and VCC pin 8
Connect them like this and you should be ready to go. Look at step 2.

Hope that helps.

shanakaplus (author)2011-04-07

um looking for elevator avr program. Do you have example program ?

andrew101 (author)2010-12-10




I spent quite a while at this wondering where i went wrong (followed diagrams to the pin)

I didn't realize the reset resistor was supposed to be pull up, not pull down. Please fix the diagram.

Havne't gotten it working (yet) but made progress :)

kabturek (author)andrew1012010-12-13

Really sorry about that, i uploaded the new version some time ago but didnt include it in the instructable.

Whats your actual problem ?

andrew101 (author)kabturek2010-12-13

Well its been fixed now, but the chip was in an eternal state of resetting with a pulldown resistor instead of a pullup one

I used the method in this video:

plus I used your tutorial for the actual programmer and stuff.

dustinandrews (author)2010-09-18

I wanted to use this to upload to an ATMEGA168p from Windows 7.

Using a Pro Mini as the programmer and the Ardunio menu option to burn the bootloader I got an error.

avrdude: Expected signature for ATMEGA168 is 1E 94 06
Double check chip, or use -F to override this check.

I had to drop to a dos prompt and run the command by hand. I copied the hex file and conf file into the dir with avrdude to make things easy.

C:\>avrdude -p m168 -c avrisp -b 19200 -P com4 -F -U flash:w:ATmegaBOOT_168_diecimila.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e940b
avrdude: Expected signature for ATMEGA168 is 1E 94 06
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "ATmegaBOOT_168_diecimila.hex"
avrdude: input file ATmegaBOOT_168_diecimila.hex auto detected as Intel Hex
avrdude: writing flash (16294 bytes):

Writing | ################################################## | 100% 2.50s

avrdude: 16294 bytes of flash written
avrdude: verifying flash memory against ATmegaBOOT_168_diecimila.hex:
avrdude: load data flash data from input file ATmegaBOOT_168_diecimila.hex:
avrdude: input file ATmegaBOOT_168_diecimila.hex auto detected as Intel Hex
avrdude: input file ATmegaBOOT_168_diecimila.hex contains 16294 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 22.43s

avrdude: verifying ...
avrdude: 16294 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

I still need to test if it worked properly since I only have the pro-mini and some loose 168p chips.

By the way, I omited the external oscilator. So it's not mandatory for these chips.

P.S. if you need to burn the fuses on an atmega128 and you are using and external resonator:

avrdude -p m168 -c avrisp -b 19200 -P com4 -F -U lfuse:w:0xff:m -U hfuse:w:0xdd:m

If you don't burn any fuses your chip will run at 1mhz. You can tell because 1. The blink program will take 16 seconds to blink the light AND you can't program from the arduino IDE.

If you burn the wrong fuses, you can ruin your chip until you can get it into a high power (12v) programmer, so be sure before you burn fuses.

heh, still having problems. You can to burn the lock bits to keep from overwriting the bootload with the sketch. I haven't got that working yet... Moral of the story: atmega169p is $3.30, but problematic with Ardunio, just buy the pre-burned ones for $5.

Fast Eddy (author)2010-07-09

I think I may be just being thick but ... I have two ATMEGA8-16PC chips that I want to put a bootloader on. I successfully execute this step (using "m8" instead of "m168") but how do I upload the bootloader correctly. I am confuse (as they say).

Derin (author)2010-05-14

In Arduino 0017 the avrdude.conf flie does not have anything like this:
id    = "avrisp";
  desc  = "Atmel AVR ISP";
  baudrate = 115200;    # default is 115200
  type  = stk500;

kabturek (author)Derin2010-07-04

When i wrote the guide 0017 was the actual version and im sure it was there. search the file for "avrisp"

esbit (author)2010-04-12


First of all: Great project :-)

You said, all we need is the chip, 3 leds and 3 resistors (and the arduino of course).
I understand the additional 10kΩ resistor to prevent the chip of resetting, but what are the two capacitors at pin 9 and 10 for? Can I omit them? If I need them, what value should I use for the capacitors?

Bye from Bavaria :-)

kabturek (author)esbit2010-04-12

the two capacitors are 22p for the crystal oscilator. it will probably work without them but its a good design to include them. You do need the 16mhz oscilator if you're going to program the chip on a breadboard.

If you have a Ceramic oscillator (this one has 3 legs) you don't need them cause ceramic oscilator has them built in.

the 16mhz oscilator (with the 22p caps) and reset resistor is used on the second soon-to-be arduino (Its the minimal number of needed components on an arduino)

esbit (author)kabturek2010-04-13

Ahh, okay, this explains something :-) I didn't see the oscillator on the Fritzing-Graphic...
Because I get my oscillators not until friday, I tried without the caps and clock crystal, but when I try to test my attiny2313 with avrdude the heartbeat-led freezes and I get an "The programmer is not responding"-error. Same with attiny45 and atmega168...

Do all of the atmel chips (esp: attiny2313 and attiny25/45/85) work with an 16MHz oscillator?

kabturek (author)esbit2010-04-14

Most of them work with 16mhz. but you don't have to use exactly 16mhz - its only used on the arduino after the fuses are burnt. when you only upload programs to attiny it runs with the internal oscilator (8mhz divided by 8). The important thing is to match the oscillator to the fuses that you burned


esbit (author)esbit2010-04-13

Hey, I might have found (can I say this in English :-p "might have found" sounds strange in german-school-english-ears ?!) the mistake, though I didn't test it, yet:

On the Fritzing-Graphic the Reset-Pin of the ic is connected (over the 10kΩ) to the ground -> the chip is nonstop resetting... Instead it should be pulled high to to the 5V, shouldn't it?

Well I will test it tomorrow and give feedback...


kabturek (author)esbit2010-04-14

Hey, thanks! You're right, on my breadboard the gnd and 5v rails are switched and i wired it the other way in Fritzing.
I'll update the drawings when ill be back home

esbit (author)esbit2010-04-13

And I'm keeping replying to myself ;-)

Well I couldn't wait until tomorrow and gues what: I was right :-)! just connect the 10kΩ resistor to 5V instead of ground and everything is working fine!
But thanks to this mistake I learned myself a lot by reading all arduino sites in the web to solve the error ;-)

34nanana (author)2010-02-14

Great stuff you did there with fritzing sketch.

Nevertheless it looks like the Atmega168 on the bread board is shifted on dot too far to the left. 
According to Atmega168 pinout, power should connect to pin 20(AVCC)
SCK to 19  (in your fritzing sketch  20)
MISO to 18 (in your fritzing sketch  20)
MOSI to 17 (in your fritzing sketch  20)

Apart from RESET connecting to pin 1 all the other are shifted as well.

ivancho (author)34nanana2010-03-07

*!&^# .. I wish I'd seen your comment 2 hours earlier...

kabturek (author)ivancho2010-03-07

sorry for the confusion ivancho, hope your chips are ok :)

ivancho (author)kabturek2010-03-08

they heated up quite a bit, but I don't think there's permanent damage... eventually I made it to the 328 datasheet and started counting..

In any case, thanks for the instructable

kabturek (author)34nanana2010-03-07

ups, sorry for the mixup, these things are hard to catch up with all the work. the images are updates with the correction. thanks 34nanana

TOCO (author)2010-02-20

You can simply buy several atmega chips and pop them into your arduino and program them. Then you simply follow a breadboard arduino instructable. Granted this only works with a few types of chips that work in the specific arduino. This is a very good instructable though!

Sorry if that sounded mean I only wanted to say that to someone.

kabturek (author)TOCO2010-03-07

hmm Are you sure thats possible ? to burn the arduino bootloader on the chip you need a programmer (look in tools->burn bootloader menu for a list of supported programmers from the ide). the other way around is bit-banging with the serial/ftdi-usb interdace)

np. every comment is welcome:)

TOCO (author)kabturek2010-03-08

You can buy them online for like $5.50 with the boot loader already installed.

ivancho (author)TOCO2010-03-08

I think paying people $2.42 extra to flash your chips is, well, wrong

andy.parksie (author)2010-02-25

is is possible to program a Arduino Duemilanove with an Arduino Mega?  Would it work in the same way?

kabturek (author)andy.parksie2010-03-07

yeah it should work ok, nothing specific in the sketch. Just change the pins if necessery (dont have a mega so can't help much) do write if you succeed.

devicemodder (author)2010-01-12

or just use digital 1/0 and 5v. you will have to press reset before upload

kabturek (author)devicemodder2010-01-12

i'm not sure what are you refering to :)
i don't think you can flash a bootloader  or program another avr chip that way:)

devicemodder (author)kabturek2010-02-26

the boot loader is already programmed just use the blink sketch

i did it and it worked with a atmega 328/168 with bootloader

willrandship (author)2010-02-25

This looks really handy for integrated projects!

brunoxyz (author)2010-02-14

I wish I had found this earlier! thanks

nadav (author)2010-01-31

 does the it have to be an ATMEGA  with arduino bootloader?

kabturek (author)nadav2010-02-01

it probably should work with any arduino hardware with SPI. what board are you referring to ?

nadav (author)2010-01-25

 if i do this can i still use my arduino as an arduino or will it mod it permanently?
ex:  can i still run the blink sketch after?

kabturek (author)nadav2010-01-25

yes sure, just disconnect the wires and upload a new sketch. its just a sketch so the arduino acts as a programmer.

nadav (author)kabturek2010-01-25

 Great! Thanks Great instructable! 

buteomont (author)2010-01-11

This is a keeper!

About This Instructable




Bio: if you can't open - you don't own it
More by kabturek:How to program a AVR (arduino) with another arduinoDIY Jewlery stand / hanger
Add instructable to: