en – eo fr

Standalone Atmega328P guide

2022-09-12
electronics, Arduino

This guide describes how to burn a program into an Atmega328P microcontroller, using an Arduino board as programmer and an external 16MHz oscillator. It's the result of the frustration that every single time I wanted to to this, it was a struggle because I couldn't find any complete tutorial. At least, the following works for me.

§Materials needed

§Notes

If you don't have any 22pF capacitor, you can salvage some capacitors from an old device (e.g. there are plenty in videotape readers). Unfortunately through-hole capacitors with this value look pretty rare, so you may need to salvage a bunch of unmarked surface-mounted ones and build a simple Arduino-based capacitance meter to find the wanted ones.

§Circuit

Circuit for programming the Atmega using an Arduino.

Check Atmega328P's pinout in the datasheet.

Triple-check the wiring. MOSI goes on MOSI and MISO goes on MISO, they are not swapped.

§For normal operation

The following connections are only needed when the microcontroller is disconnected from the Arduino.

§Program

I'm using the Arduino IDE.

First, we program the Arduino board to make it operating as a relay between the computer and the microcontroller:

  1. Open the example sketch ArduinoISP.
  2. If using an Arduino Uno, uncomment the line #define USE_OLD_STYLE_WIRING.
  3. Choose your programmer board as board type (Arduino Micro in my case).
  4. Choose a regular programmer (typically AVR ISP).
  5. Upload the sketch normally.

Now we can program the microcontroller:

  1. Open the wanted sketch. (or start with the Blink example)
  2. Choose Arduino Uno as board type. (even if you're using another board as a programmer; it's because a standalone Atmega328P with a 16MHz oscillator behaves like an Arduino Uno)
  3. Choose Arduino as ISP as programmer.
  4. If your microcontroller doesn't contain a bootloader yet, upload the bootloader using Tools -> Burn bootloader.
  5. Upload the sketch using Sketch -> Upload using programmer.