The ATmega8/168/328 are a range of microprocessors at the heart of the Arduino. Rather than having to include an external Arduino board with my projects, I’d like to be able to create self-contained devices which have the ATmega chip embedded.
Programming the ATmega
It’s possible to program Atmel microprocessors using an Arduino board and the megaISP project. This post documents my attempt.
Before starting of got hold of a copy of the datasheet for the ATmega8 (http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf)
Step 1: Upload mega-isp to Arduino
I downloaded the mega-isp source, and uploaded it to my Arduino board. The source can be found at google code (http://code.google.com/p/mega-isp/).
Step 2: Set up breadboard

mega-isp: programming an atmega8 with arduino
First of all, I set up the breadboard according the advice given at http://www.uchobby.com/index.php/2007/11/04/arduino-avr-in-system-programmer-isp/
The article mentions something called a bypass capacitor .. which is something I hadn’t come across before. Basically, it’s a small capacitor that’s used to smooth out small changes in voltage – and should be used whenever you set up a microprocessor in a circuit. I learnt about them here (http://www.seattlerobotics.org/Encoder/jun97/basics.html)
Because I’m trying to program an ATmega8 (and not the Tiny18 mentioned in the article) I needed to adjust the pins. I also added another LED to signal when megaisp is actually programming (which was mentioned in the Arduino source code).

ATmega8/168/328p pinout diagram
The only pins that I needed to consider were:
| The SPI interface | ||
|---|---|---|
| ATMEGA-PIN19 | ⇔ | ARDUINO-PIN13(SCK) |
| ATMEGA-PIN18 | ⇔ | ARDUINO-PIN12(MISO) |
| ATMEGA-PIN17 | ⇔ | ARDUINO-PIN11(MOSI) |
| Power / Gnd (I added a bypass capacitor between 7/22 on the atmega) |
||
| ATMEGA-PIN8 | ⇔ | ARDUINO-GND |
| ATMEGA-PIN22 | ⇔ | ARDUINO-GND |
| ATMEGA-PIN7 | ⇔ | ARDUINO-5V |
| ATMEGA-PIN20 | ⇔ | ARDUINO-5V |
| Reset | ||
| ATMEGA-PIN1 | ⇔ | ARDUINO-PIN10 |
| Status LEDs (each connected to ground via a resistor) |
||
| heartbeat LED | ⇔ | ARDUINO-PIN9 |
| error LED | ⇔ | ARDUINO-PIN8 |
| programming LED | ⇔ | ARDUINO-PIN7 |
Step 3: Connecting via AVRdude
AVRdude is an open-source utility for programming Atmel AVR Microcontrollers.
Running the following from a terminal
avrdude -p atmega8 -c avrisp -P /dev/ttyUSB0 -b 19200
produced
avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.13s avrdude: Device signature = 0x1e9307 avrdude: safemode: Fuses OK avrdude done. Thank you.
Which indicated that AVRdude had communicated with the mega-isp successfully.
3 Comments
hello, i try this example – but nothing fails – all connections are OK – but when connect Arduino mega, ATMEGA 8 on usb avrdude say:
avrdude -p atmega8 -c avrisp -P com3 -b 19200
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.14s
avrdude: Device signature = 0xffffff
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
how can I solve this problem? I am using WinAVR-and tries to join the CMD on Win7 – I’ve also tried the win xp
if i try again it say :
avrdude -p atmega8 -c avrisp -P com3 -b 19200
avrdude: stk500_program_enable(): protocol error, expect=0×14, resp=0×50
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude: stk500_disable(): protocol error, expect=0×14, resp=0×51
avrdude done. Thank you.
p.s im using arduino mega
2 Trackbacks
[...] Many places sell ATmega chips with the Arduino booloader pre-burnt. To actually burn the bootloader yourself, you do need an external programmer. Fear not though – in a previous post, I discovered how to use an Arduino board (together with the mega-isp project) as a make-shift external programmer -> see this post for details. [...]
[...] program our new Arduino using an existing Arduino. This novel idea of bootstrapping was presented here. The software used for the programmer is MegaISP (Recently integrated into the Arduino [...]