Draft:Using Arduino as ISP to program an ATMega microcontroller

An Arduino can be used as a programmer for AVR microcontrollers. This guide will explain how to program microcontrollers in the ATMega family.

Requirements

 * ATMega microcontroller (MCU)
 * Arduino Uno or Mega (Other Arduinos will work, but the pins may be slightly different.)
 * USB cable to connect Arduino to computer
 * Arduino IDE installed on computer

Electrical Components

 * Breadboard
 * Jumper wires
 * Two 0.1uF capacitors
 * 10 uF capacitor

The microcontroller should be set to use the internal clock if it is factory new. If it has been set to external clock, you will also need:
 * 16Mhz crystal
 * Two 18-22 pF capacitors (Anything between 18 and 22 will work)

Upload Arduino ISP sketch

 * 1) Connect the Arduino to the computer.
 * 2) Open the ArduinoISP sketch, which can be found in File > Examples.
 * 3) Upload the sketch.
 * 4) Disconnect the Arduino from the computer for the following steps so that everything is unpowered while you make connections.

Connect components
  Place the MCU on the breadboard, straddling the center line, so that half the pins are on one side and half on the other.  Pin 1 will be the left pin on the side nearest the U-shaped groove of the MCU. They increase down the left side 1-14, then increase back up the right side, 15-28. Pin 28 will be directly opposite pin 1.  Place a 0.1uF capacitor between pins 7 and 8. Place a second 0.1uF capacitor between pins 20 and 22. Try to keep the capacitor as close as possible to the MCU pins. Connect the Arduino to the MCU using the below table as a guide for which pin connect to which. The Arduino pins differ depending on if you are using an Uno or a Mega.

 Place a 10uF capacitor between the Reset and GND pins of the Arduino. If it's an electrolytic capacitor, make sure the long lead, or positive side, is connected to Reset and the short lead is connected to GND. 

External Crystal
If you are using a brand new MCU, it should be set to use its internal clock. If your MCU has been changed to use an external clock, you will need to follow these steps:


 * 1) Place a 16Mhz crystal on the breadboard and connect one lead to pin 9 of the MCU and the other to pin 10.
 * 2) Place two 18-22pF capacitors onto the breadboard, each one going between one of the crystal leads and ground.

LED circuit
This part is not necessary for normal programming, but for this guide, it will demonstrate the code working properly on the MCU.


 * 1) Connect one leg of a resistor to pin 19 of the MCU. Any value resistor between 150 and 600 ohms will work. (Actually any value above that will work too, but if it's too high, the light may get too dim to see.
 * 2) Connect the other leg of the resistor to the positive leg of an LED. The positive leg is the longer leg. You can also tell which side is positive by looking at the head of the LED. The negative side will have a flat face, while the positive side will be curved.
 * 3) Connect the other leg of the LED, the negative side, to ground.

Install configuration file
1. Follow the How to Install instructions on the MiniCore Github page.

Burn bootloader

 * 1) Connect the Arduino to the computer with the USB cable.
 * 2) Board: Open the Arduino IDE, and select the appropriate MCU under Tools > Board > Minicore.
 * 3) Clock: Select the clock you would like to use, under Tools > Clock.
 * 4) * If you would like to use an external clock component, choose one of the External settings.
 * 5) * Otherwise, choose an Internal setting to use the MCU's internal clock.
 * 6) BOD: Select the appropriate BOD level under Tools > BOD.
 * 7) * BOD, or brown-out detection, forces the MCU to stop working if its supply voltage dips below the set level, in order to protect the circuit. For example, if your MCU is powered by a 5V supply, and its BOD is set to 4.3V, it will "sleep" if the supply dips below 4.3V, and start up again when it rises above 4.3V. Your circuit may or may not need BOD, but any value you choose will let you program your MCU.
 * 8) Variant: If the menu option is available, choose the appropriate variant of your MCU under Tools > Variant.
 * 9) Programmer: Select "Arduino as ISP (Minicore)" under Tools > Programmer.
 * 10) Click Burn Bootloader in the Tools Menu. If the Arduino IDE did not produce any errors, you can now upload sketches to the MCU.

Upload sketch
Now that all the correct settings have been selected, you can upload a sketch to the microcontroller. As an example, we'll upload the Blink sketch from the Arduino IDE.
 * 1) Make sure all the correct options for Board, Clock, BOD, Variant, and Programmer are still set correctly.
 * 2) EEPROM: Select whether you want EEPROM retained or not, under Tools > EEPROM.
 * 3) * EEPROM is a section of memory on the MCU, which is not erased when the the MCU is off. This menu setting lets you decide if you want all the existing EEPROM memory to be kept when you program the MCU ("EEPROM retained"), or if you want it to be erased to a fresh slate.
 * 4) Compiler LTO: Select whether you want link-time optimization enabled under Tools > Compiler LTO.
 * 5) *Link-time optimization attempts to optimize the code, which may help to reduce program size or increase program speed.


 * 1) In the Arduino IDE, under File > Examples > Basics, click on Blink.
 * 2) Under the Sketch menu, click Upload Using Programmer. You can also hold the Shift key while pressing the Upload button on the toolbar.
 * 3) After the sketch finishes uploading, the LED on the breadboard should start blinking.

If the Blink sketch worked, congratulations, you did it!

Concluding thoughts

 * If you want to go back to uploading sketches to the Arduino, you'll need to change the Board setting in the Tools > Board menu back to the correct Arduino model, and the Programmer setting in the Tools > Programmer menu to "AVRISP mkll".
 * Whenever you want to upload to the MCU, make sure the ArduinoISP sketch has been uploaded to the Arduino first, and all the settings from previous steps are correctly set. You don't need to click Burn Bootloader after the first time you program the microcontroller.

Other resources

 * From Arduino to a Microcontroller on a Breadboard
 * Program ATmega 328 Using Arduino (Arduino As ISP)