# Standalone AVR Chip Programmer

## Overview

We previously showed how to [use an Arduino + protoshield + ZIF socket to make a programmer that can burn a lot of Arduino bootloaders](http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduinoisp "Link: http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduinoisp"). In our blog comments [a user commented that he had written a stand-alone program for the Arduino called Optiloader](http://www.adafruit.com/blog/2011/08/25/tutorial-arduino-hacks-burning-bootloader-chips-using-an-arduino/ "Link: http://www.adafruit.com/blog/2011/08/25/tutorial-arduino-hacks-burning-bootloader-chips-using-an-arduino/") that is similar and might be worth checking out.

[What Optiloader does is kinda of neat.](http://www.youtube.com/watch?v=YBFUGre0hY4 "Link: http://www.youtube.com/watch?v=YBFUGre0hY4") Instead of having a computer that talks **thru** the Arduino to a chip for programming, instead the **Arduino itself** programs the chip. This means you can program chips without having a computer involved. The good news about this technique is that it is incredibly fast, you can program chips 10x faster than with a computer and without having to type anything in. The only downside is that its very specialized, once you set it up the programmer can only do one chip (in general) with one HEX file. If you want to update it, it can be a little effort to reconfigure.

However, if you are burning a lot of chips, this can be a real blessing. We can program and burn an Arduino bootloader chip in about 5 seconds. Normally with a computer you're talking 40 seconds or so. Another nice thing is that you can make it very clear when a failure has occured. Instead of reading text on a computer screen - a piezo will beep once on success. We've found that audio feedback is way more likely to be noticed than visual feedback.

[We adapted Optiloader to be more flexible - so it can program any AVR with any HEX file.](https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer "Link: https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer") While you don't _need_ to use an Arduino for this, we have a lot of Arduino's kicking around here so they make a handy base.

http://www.flickr.com/photos/adafruit/6140821773/

This code can be adapted for programming any AVR that can be ISP programmed (this is like 99% of AVRs) but in this example the wiring will be for the Atmega8/48/88/168/328 series and the code will be the Adaboot bootloader. If you have other chips you are programming, check the datasheet for how to wire VCC, Gnd, MISO, MOSI, SCK, RST and XTAL1 (if you need external clocking).

Info: 

# Standalone AVR Chip Programmer

## Assembly

To complete this tutorial you will need…

- [An Arduino](http://www.adafruit.com/products/50)
- [A proto shield kit](https://www.adafruit.com/products/51)
- [28-pin ZIF (zero-insertion force) socket](https://www.adafruit.com/products/382 "Link: https://www.adafruit.com/products/382")
- [A piezo](https://www.adafruit.com/products/160)
- [Some wire](https://www.adafruit.com/products/289)
- [Blank ATmega328P](http://www.adafruit.com/partfinder/microcontroller?s%5B%5D=atmega328p) (that you will program)

First up, place the ZIF socket on the proto shield like so:

![](https://cdn-learn.adafruit.com/assets/assets/000/009/731/medium800/manufacturing_zifplace.jpg?1396896156)

Solder all 28 pins for a solid connection!![](https://cdn-learn.adafruit.com/assets/assets/000/009/732/medium800/manufacturing_zifsolder.jpg?1396896171)

Solder the following wires to the ZIF socket

- Pin 1 to digital 10 - Blue (this wire connects underneath to the ZIF socket so make sure to 'jumper it so it solders directly to the ZIF pin, see the photos below)
- Pin 7 to 5V - Red
- Pin 8 to Ground - Black
- Pin 9 to digital 9 - Gray
- Pin 17 to digital 11 - Brown
- Pin 18 to digital 12 - Orange
- Pin 19 to digital 13 - Yellow
- Pin 20 to +5V - Red
- Pin 22 to Ground - Black

![](https://cdn-learn.adafruit.com/assets/assets/000/009/733/medium800/manufacturing_ispwiring.jpg?1396896181)

Follow the protoshield tutorial to solder in the Red LED into **LED1** position, Green LED into **LED2** position. Also solder in the two 1.0K resistors next to the LEDs. We'll use the LEDs as indicators. Then solder a wire from the LED2 breakout (white) to analog 0 and a wire from LED1 breakout (white) to digital 8.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/734/medium800/manufacturing_extras.jpg?1396896194)

Next add **S1** switch which you will press to start the programming process. You can just solder a wire (yellow) from the breakout near **S1** to **Analog 1.**

We also soldered in a Piezo beeper, to give us feedback. One side is soldered into **Analog 3** the other side is soldered to the ground rail right next to the analog breakouts.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/735/medium800/manufacturing_standaloneshield.jpg?1396896209)

Finally, you'll need to solder on the header to allow the shield to be placed on, break the 0.1" male header and place it into the Arduino sockets. Then place the shield above on top to solder it in place.![](https://cdn-learn.adafruit.com/assets/assets/000/009/736/medium800/manufacturing_diecheader.jpg?1396896223)

If you need to see what the bottom looks like, it will be something like this. Except ours has a ton of rosin on it because we ended up moving the socket for this prototype, so that brown rosin stuff probably wont be on yours!![](https://cdn-learn.adafruit.com/assets/assets/000/009/737/medium800/manufacturing_standaloneshieldbot.jpg?1396896237)

Thats it!

## Program the Arduino

Next, install the [AVRProg Library](https://github.com/adafruit/Adafruit_AVRProg) which will be used to build the programmer firmware. It can be installed via the Arduino IDE's Library Manager.

In the Arduino IDE, open the Library Manager:

**Tools -\> Manage Libraries...**

Then search for Adafruit AVRProg. The library should be found in the listing. Then click the Install button.

![](https://cdn-learn.adafruit.com/assets/assets/000/120/096/medium800/manufacturing_libman1.png?1680626783)

Once the library is installed, open the **atmega328\_optiboot** example in the Arduino IDE:

**File -\> Examples -\> Adafruit AVRProg -\> atmega328\_optiboot**

Upload this example to your Arduino board.

Info: 

Info: 

## Using the Programmer

Once the programmer sketch has been uploaded to the Arduino board, programming chips is easy:

1. Insert the chip into ZIF socket.
2. Lock it down via lever on ZIF socket.  
3. Press the button on the shield.  
4. While programming, the green LED is lit. When done, the piezo will beep once. **If the red LED is lit, a problem occurred.**

http://www.flickr.com/photos/adafruit/6140821773/

Once you have programmed the chip with our default code you can use it in an existing Arduino board, compatible, or breadboard style. You will need a 16 MHz crystal on the clock pins, so don't forget it!

Info: 

# Standalone AVR Chip Programmer

## Changing the Code

Unlike the specialized Optiloader, this program can be adapted to any AVR and any size HEX file as long as you can fit the HEX into the flash of the microcontroller. Since HEX files are ascii, they basically 2x the size of the code itself. So if you have a 500 byte program, the HEX will be 1K. The sketch itself takes about 10KB so you have approximately 20KB left for the HEX which is good for about 10KB of flash to burn. This isn't tons but I suppose if you wanted to port the program to the Mega then you could fit up to 128KB of flash for massive chips.

You can paste your new HEX into [images.cpp](https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer/blob/master/images.cpp) . You'll need also to set the bottom two bytes of the signature (third entry), and the fuses you want to set before you start programming, and the fuses you want to set after programming (in case the lock bits have changed). The fuse mask is used because not all fuse bits are used so if you write a zero to an unused bit (as avrdude prefers to do) it may be read back as a 1 which can cause verification errors. Next is the size of the chip flash in bytes and the size of a flash page for the chip (you may need to research the datasheet for this number). The first two arguments (name of flash and name of chip) are for your records, they arent really used by the program itself.

Please note that while this tutorial works and we're very confident that this project can be adapted to other chips **making sure that you have all the above set correctly is not trivial and will take some trial and error as well as expertise in reading datasheets and the avrdude.conf file** so **we can't provide one-on-one technical support in helping you adapt the tutorial to your particular chip and code.** Please endeavor to work it out on your own!

Of course, after you load a new firmware in, be sure to check that it did in fact burn it correctly using a known good programmer.


## Related Guides

- [Adafruit MOSFET Driver](https://learn.adafruit.com/adafruit-mosfet-driver.md)
- [HID Reporter](https://learn.adafruit.com/hid-reporter.md)
- [Adafruit PN532 RFID/NFC Breakout and Shield](https://learn.adafruit.com/adafruit-pn532-rfid-nfc.md)
- [Adafruit ADG729 Dual 1-to-4 Analog Matrix Switch](https://learn.adafruit.com/adafruit-adg729-dual-1-to-4-analog-matrix-switch.md)
- [How to Make a Pogo Pin Test Jig](https://learn.adafruit.com/how-to-make-a-pogo-pin-test-jig.md)
- [Adafruit PCF8574 I2C GPIO Expander](https://learn.adafruit.com/adafruit-pcf8574.md)
- [Adafruit RP2040 CAN Bus Feather](https://learn.adafruit.com/adafruit-rp2040-can-bus-feather.md)
- [Adafruit ENS161 MOX Gas Sensor](https://learn.adafruit.com/adafruit-ens161-mox-gas-sensor.md)
- [Adafruit MAX17048 LiPoly / LiIon Fuel Gauge and Battery Monitor](https://learn.adafruit.com/adafruit-max17048-lipoly-liion-fuel-gauge-and-battery-monitor.md)
- [NeoAnim: Using Bitmaps to Animate NeoPixels on Circuit Playground](https://learn.adafruit.com/circuit-playground-neoanim-using-bitmaps-to-animate-neopixels.md)
- [LIGHTSHIP: LED Animation over WiFi](https://learn.adafruit.com/lightship-led-animation-over-wifi.md)
- [Adafruit S-35710 Low-Power Wake Up Timer Breakout](https://learn.adafruit.com/adafruit-s-35710-low-power-wake-up-timer-breakout.md)
- [ePaper FeatherWing Quote Display](https://learn.adafruit.com/epaper-display-featherwing-quote-display.md)
- [Adafruit TMC2209 Stepper Motor Driver Breakout Board](https://learn.adafruit.com/adafruit-tmc2209-stepper-motor-driver-breakout-board.md)
- [Using Bluefruit BLE to Give Disabled Users Switch Control Access to IOS Devices](https://learn.adafruit.com/ios-switch-control-using-ble.md)
