Generating PDF…

Preparing…
← Back
Reference

Arduino as ISP

Programming the Standalone ATmega328P

DE6417 Microcontrollers 2  ·  Week 14

Arduino Uno + ATmega328P Required
1. Why2. How ISP works3. Wire4. Upload5. Bootloader + clock

Why Program a Bare Chip?

The Arduino board is a development tool

Everything on the board around the ATmega328P exists to make programming convenient. Real products ship the chip, not the board.

  • Cost: ATmega328P ~$2. Arduino Uno ~$25.
  • Size: the chip is 3 cm long. The Uno is 7× bigger.
  • Power: the Uno's USB chip and regulator draw current even when idle.

Ways to get code onto a bare chip

ApproachHardware needed
Arduino as ISP (today)A second Arduino Uno running a sketch
Dedicated ISP programmerUSBasp, AVRISP mkII, Atmel-ICE
Bootloader + USB-serial adapterFTDI adapter — but a bootloader must be burned first
Every approach writes bytes to flash. They differ only in what acts as the bridge between your PC and the chip.

Today's Approach: Arduino as ISP

Why Arduino as ISP?

  • No extra hardware to buy — you already have an Arduino Uno
  • Built into the Arduino IDE, no special drivers
  • Can both upload sketches and burn bootloaders
The one sentence to remember today:
The Uno is the programmer. The bare chip on the breadboard is the target — your sketch goes there.

🛒 Components for Today

ComponentValue / TypeQty
Arduino Uno (the programmer)Any revision1
ATmega328P-PU (the target)DIP-281
Crystal16 MHz1
Ceramic capacitor22 pF2
Electrolytic capacitor10 µF1
LED + resistor220 Ω1 each
Breadboard + jumper wiresMale-to-male10+

Learning Outcomes

🔌

Understand ISP

Explain how ISP differs from the normal bootloader upload.

💾

Configure programmer

Flash ArduinoISP to a Uno and set up the IDE correctly.

🔧

Wire correctly

Connect the 6 ISP lines and the crystal to the target chip.

✅

Flash and prove

Upload a sketch to the standalone chip and see it run.

💎

Clock + bootloader

Explain what Burn Bootloader sets and why the chip needs a clock.

Quick Check — Before We Start

Q1: What does ISP stand for?

Q2: Which physical interface does ISP use?

1. Why2. How ISP works3. Wire4. Upload5. Bootloader + clock

Two Ways to Program the ATmega328P

1. Normal Upload (Uses a Helper Inside the Chip)
Step 1: You press Upload on your computer
↓
Step 2: The code travels through the USB cable to the Arduino board
↓
Step 3: The board sends it to the chip using 2 wires: RX and TX
↓
Step 4: A small helper program (the bootloader) is already inside the chip. It receives your code and saves it
↓
Step 5: Your code is saved in Flash memory and starts running
💡 Think of it like this:
A receptionist sits inside the chip. When a delivery arrives, the receptionist takes it and puts it on the shelf.
Problem: A brand-new chip has no receptionist, so nobody takes the delivery. This method does not work on a new chip.
2. ISP Upload (Today: No Helper Needed)
Step 1: You press Upload Using Programmer on your computer
↓
Step 2: The code goes to a second Arduino (the "Programmer"). It acts as a messenger
↓
Step 3: The Programmer pulls the chip's RESET pin LOW (to 0 V). This tells the chip: "Stop and listen!" Then it sends the code on 3 wires: MOSI, MISO, SCK
↓
Step 4: The chip's built-in hardware accepts the code. No helper program is needed
↓
Step 5: Your code is saved in Flash memory. Release RESET and it runs
🔑 Think of it like this:
You use a master key to open the chip's back door and put the code on the shelf yourself. No receptionist needed.
Why we use it: It works on a brand-new blank chip.
ISP = In-System Programming. 4 wires (MOSI, MISO, SCK + RESET), built into every ATmega328P — even a blank one. Bonus: because ISP doesn't need the chip to run any code, it can also rescue a chip whose settings were changed by mistake.

Who Talks to Whom: The 4 ISP Wires

Same SPI you already know

  • Master = programmer Uno (running ArduinoISP)
  • Slave = target ATmega328P on the breadboard
SignalUno pinTarget DIP pinJob
MOSID1117 (PB3)Program data → chip
MISOD1218 (PB4)Verify data ← chip
SCKD1319 (PB5)Clock for every bit
RESETD101 (PC6)Held LOW = "stop and listen"

D10 is just a spare pin the programmer uses to hold the target's RESET low. Newer docs call MOSI/MISO COPI/CIPO — same wires.

Programmer Uno
(ArduinoISP sketch)
MOSI →
← MISO
SCK →
RESET →
Target ATmega328P
(standalone chip)

Only MISO points back to the programmer — it's how the programmer checks what was written.

Signal Direction Check

Match each signal to its correct direction during ISP programming

MOSI →
MISO →
SCK →
RESET →

The Bridge: What Happens When You Upload

ArduinoISP = a translator sketch

You flash it to the Uno once. From then on the Uno translates the PC's serial commands into SPI for the target chip.

File → Examples → 11.ArduinoISP → ArduinoISP
  1. Compile: the IDE turns your sketch into a .hex file
  2. Send: avrdude sends it over USB serial to the Uno
  3. Translate: ArduinoISP turns it into SPI and writes the target's flash
  4. Verify: avrdude reads every byte back to check it
avrdude: verifying flash memory...
avrdude done. Thank you.

"done" means the flash holds exactly what you sent.
PC / avrdude
↓USB serial
Programmer Uno
runs ArduinoISP — not your sketch
↓SPI (MOSI / MISO / SCK / RESET)
Target ATmega328P
runs your sketch
↓
Flash memory

Arduino IDE Configuration

Four things to set before uploading

#Menu pathWhat to select
1Tools → BoardArduino Uno — describes the target (ATmega328P at 16 MHz)
2Tools → PortThe COM/tty port of the programmer Uno
3Tools → ProgrammerArduino as ISP
4Upload methodSketch → Upload Using Programmer

The critical mistake to avoid

Do NOT click the normal Upload arrow (▶).

That sends your sketch to the programmer Uno, not the target. If it gets through, it replaces ArduinoISP and you have to re-flash it.
Use Sketch → Upload Using Programmer every single time.

Upload Sketch vs Burn Bootloader

OperationWhat it doesWhen to use
Upload Using Programmer
Sketch menu
Erases the whole chip (bootloader included), then writes your sketch Every normal upload today
Burn Bootloader
Tools menu
Erases the chip, sets the fuses (incl. the clock source), writes the Optiboot bootloader Fresh chip, mis-set chip, or to make USB uploads work again
Fuses = the chip's settings switches. One of them chooses the clock:
Factory-new chip: internal 8 MHz ÷ 8 = 1 MHz
After Burn Bootloader (Uno settings): external 16 MHz crystal
Clock matters: once the fuses say "external crystal", the chip needs the crystal to run — or even to be programmed. That's why we wire the crystal in from the start.

Pin Mapping Check

Q3: On the ATmega328P DIP-28 package, which physical pin is MOSI?

Q4: You connect programmer pin 10 to target pin 1. What is this wire for?

Lab Block

Flash a Sketch to the Standalone Chip

Goal: a bare ATmega328P blinks an LED from code you put there — no Uno board underneath it

Lab Brief

Goal

Use the Uno as a programmer to put Blink on the bare ATmega328P, then burn a bootloader and see what the clock setting does.

The steps

  1. Flash ArduinoISP to the Uno
  2. Wire the chip: ISP lines, crystal, LED, then the 10 µF cap
  3. Upload Blink to the chip
  4. Burn Bootloader
  5. Upload Blink again and compare the speed

Time box

TimeTask
0:00 – 0:20Steps 1–2: flash ArduinoISP + wire
0:20 – 0:50Step 3: upload Blink, troubleshoot
0:50 – 1:10Steps 4–5: Burn Bootloader + clock comparison
1:10 – 1:15Exit question
Your chip may be blank or already bootloaded. The steps work for both — you'll find out which one you have in Step 3.

Step 1: Flash ArduinoISP to the Uno

Instructions

  1. Connect only the Uno to your PC via USB (no capacitor yet)
  2. In Arduino IDE: File → Examples → 11.ArduinoISP → ArduinoISP
  3. Board = Arduino Uno, Port = the Uno's port
  4. Click the normal Upload button ▶ — the only time you use it today
  5. Wait for "Done uploading"
  6. Do not unplug the Uno — it stays connected all session

How to know it worked

"Done uploading" with no red errors = ArduinoISP is on the Uno.
Optional status LED: ArduinoISP has a heartbeat on D9 (not D13). Add an LED + 220 Ω from D9 to GND and it slowly fades in and out while the sketch runs.

Also available: D8 = error, D7 = programming.

The Uno's onboard L LED (D13 = SCK) does not show a heartbeat. It only flickers during an upload.
1. Why2. How ISP works3. Wire4. Upload5. Bootloader + clock

Step 2a: Wire Power and the 4 ISP Lines

Wire in this order

#UnoTarget DIP pinSignal
1GND8 + 22GND first — always
25V7 + 20VCC + AVCC
3D101RESET
4D1319SCK
5D1117MOSI
6D1218MISO
Find the notch — it marks pin 1. Count down one side and back up the other. The chip must straddle the centre gap, or opposite pins short together.
Arduino Uno to ATmega328P wiring diagram

The diagram also shows optional 100 nF decoupling caps. The crystal is added on the next slide.

Step 2b: Add the Crystal, LED and 10 µF Cap

7 · Crystal (on the chip)

  • 16 MHz crystal across pin 9 (XTAL1) and pin 10 (XTAL2) — either way round
  • 22 pF from pin 9 → GND
  • 22 pF from pin 10 → GND
pin 9 ─┬─[XTAL]─┬─ pin 10 22pF 22pF │ │ GND GND

Keep leads short, right next to the chip.

8 · LED (on the chip)

  • Pin 19 (PB5 = Arduino D13) → 220 Ω → LED long leg
  • LED short leg → GND

Pin 19 is also SCK, so this LED flickers during uploads. That's normal.

9 · 10 µF cap (on the Uno)

  • Uno RESET → + leg
  • Uno GND → − leg (stripe)
Why? Opening the serial port normally resets the Uno. The cap stops that, so ArduinoISP keeps running during the upload.
Add it after Step 1. Remove it if you ever need to re-flash ArduinoISP. Never on the target chip.
Why the crystal now? A bootloaded chip is set to use a crystal. Without one it has no clock and can't even be programmed. A blank chip ignores the crystal for now, so wiring it works for every chip.

Pre-Upload Checklist

Hardware checklist

Software checklist

1. Why2. How ISP works3. Wire4. Upload5. Bootloader + clock

Step 3: Upload Blink and Observe

Upload

  1. Open File → Examples → 01.Basics → Blink
  2. Click Sketch → Upload Using Programmer
  3. Wait for "Done uploading"

What do you see? Write it down for Step 5

LED on pin 19It means
1 s on / 1 s offChip was bootloaded — already running on the 16 MHz crystal ✓
~16 s on / ~16 s offChip was blank — running at 1 MHz. Not an error! Step 4 fixes it.

Observation questions

  • What is powering the target chip right now?
  • Does the target have its own USB connection?
  • What would happen if you unplugged the D10–D13 wires now?
  • Which parts of the Uno board are NOT needed for the sketch to run?
The sketch is in flash. Give the chip power and a clock and it runs — no PC, no Uno underneath it.

Troubleshooting Guide

What symptom do you see?

Debug order

  1. Power: 5V and GND reach pins 7, 8, 20, 22?
  2. Clock: crystal + 22 pF caps on pins 9 and 10?
  3. Capacitor: 10 µF on the Uno, stripe to GND?
  4. Wiring: D10→1, D11→17, D12→18, D13→19?
  5. IDE: Programmer = Arduino as ISP, correct port?
Read the exact avrdude error message. Each one points to a different cause.
1. Why2. How ISP works3. Wire4. Upload5. Bootloader + clock

Step 4: Burn the Bootloader

Steps

  1. Keep all the wiring exactly as it is (crystal included)
  2. Same IDE settings: Board = Arduino Uno, Programmer = Arduino as ISP
  3. Tools → Burn Bootloader
  4. Wait for "Done burning bootloader."
This is how the "bootloaded" chips you can buy are made — with exactly the setup on your bench.

What happens inside

  • The whole chip is erased — your Blink is gone (the LED stops)
  • Fuses are set: external 16 MHz crystal, bootloader size, reset behaviour
  • Optiboot is written to the last 512 bytes of flash
  • From now on, after every reset the chip waits briefly for a serial upload before starting the sketch

Step 5: Upload Blink Again — Spot the Difference

Do it

Sketch → Upload Using Programmer — same Blink, no code changes. Compare with what you wrote down in Step 3.

Blank chip (Step 3)After Burn Bootloader
ClockInternal 8 MHz ÷ 8 = 1 MHz16 MHz crystal
Blink~16 s on / 16 s off1 s on / 1 s off ✓
Why?The code expects 16 MHz but runs 16× slower, so every delay() is 16× too longThe clock matches the Board setting

Bootloaded chip? Your Step 3 and Step 5 look the same — compare with a group that had a blank chip.

Two takeaways

The IDE does not detect your clock. It trusts the Board setting. If the chip's clock doesn't match it, all timing is wrong.
This upload erased the bootloader again, because Upload Using Programmer erases the whole chip. The fuses (crystal) stay. To keep the bootloader, put the chip in an Uno socket and use the normal Upload ▶.

Week 14 Summary

What you proved today

  • ISP programs the chip over 4 SPI wires — no bootloader, no USB chip needed on the target
  • ArduinoISP turns a Uno into the programmer — your sketch goes to the target
  • 10 µF cap on the Uno's RESET stops it resetting during an upload
  • Upload Using Programmer erases the chip (bootloader too) and writes your sketch
  • Burn Bootloader sets the fuses (clock!) and installs Optiboot
Key insight: the ATmega328P doesn't need the Arduino board. It needs power, a clock, and code in flash.

Exit question

Name one thing the Arduino board was doing for you that the standalone chip cannot do by itself.

Good answers: USB communication, the auto-reset circuit, the 5V regulator, the 16 MHz clock, the bootloader.

Preview: Week 15

Now that we can program the chip with 4 wires — what if we wrote the code without the Arduino framework? No setup(), no loop(), no digitalWrite(). Just C and registers.