The overview, with examples running, is on the board page.
The ATmega328P on a breadboard
The Uno's chip on its own, in a 28-pin DIP that pushes into a breadboard, in the two builds the tutorials wire: a 16 MHz crystal, and the 8 MHz internal clock.
What it is
The ATmega328P out of the Uno, with no board around it. It is the same chip
model as the Arduino Uno, so everything that page
says about the core, the timers, the USART, the ADC and EEPROM is true here
too. What the board did for the chip, you now do on the breadboard: give it a
supply, tie its grounds, hold RESET high and add your own LED.
It sits across the breadboard's center channel like the 555 and the 74HC chips, pins 1 to 14 on one side and 15 to 28 on the other.
The two builds
There are two parts in the bin. They are the same chip, clocked two ways.
| ATmega328P | ATmega328P, 8 MHz internal clock | |
|---|---|---|
| Clock | 16 MHz, from a crystal on pins 9 and 10 | 8 MHz, from the chip's own oscillator |
| Pins 9 and 10 | XTAL1 and XTAL2, the crystal's |
PB6 and PB7, port pins |
| Programs it runs | the Uno's | the 3.3 V Pro Mini's, built for 8 MHz |
The 16 MHz build is the chip from the "Arduino on a breadboard" tutorial, with the Uno's bootloader burned in. The 8 MHz build needs no crystal at all, which frees pins 9 and 10.
Every timer, the USART and the ADC count clock cycles, so a sketch built for
16 MHz and loaded onto the 8 MHz chip runs at half speed: delay(1000) takes
two seconds. Sketches you write for the 8 MHz chip are compiled for 8 MHz, so
they keep time. At 8 MHz, 115200 baud is 3.5 percent fast; use 57600, as the
Pro Mini page says.
The pins
Pin 1 is at the notch end, and the numbers run down one side and back up the
other. A sketch uses the Uno's numbers, so digitalWrite(13, HIGH) drives
PB5, pin 19.
| Pin | Name | In code | What it is |
|---|---|---|---|
| 1 | RESET |
Low resets the chip | |
| 2 | PD0 |
0 |
RX, Serial in |
| 3 | PD1 |
1 |
TX, Serial out |
| 4 | PD2 |
2 |
INT0 |
| 5 | PD3 |
3 |
PWM, INT1 |
| 6 | PD4 |
4 |
|
| 7 | VCC |
The supply, in | |
| 8 | GND |
Ground | |
| 9 | XTAL1 |
The crystal's; PB6 on the 8 MHz build |
|
| 10 | XTAL2 |
The crystal's; PB7 on the 8 MHz build |
|
| 11 | PD5 |
5 |
PWM |
| 12 | PD6 |
6 |
PWM |
| 13 | PD7 |
7 |
|
| 14 | PB0 |
8 |
|
| 15 | PB1 |
9 |
PWM |
| 16 | PB2 |
10 |
PWM, SPI SS |
| 17 | PB3 |
11 |
PWM, SPI MOSI |
| 18 | PB4 |
12 |
SPI MISO |
| 19 | PB5 |
13 |
SPI SCK, and LED_BUILTIN |
| 20 | AVCC |
The ADC's supply, in | |
| 21 | AREF |
The ADC's reference | |
| 22 | GND |
Ground | |
| 23 | PC0 |
A0 |
Analog |
| 24 | PC1 |
A1 |
Analog |
| 25 | PC2 |
A2 |
Analog |
| 26 | PC3 |
A3 |
Analog |
| 27 | PC4 |
A4 |
Analog, I2C SDA |
| 28 | PC5 |
A5 |
Analog, I2C SCL |
The catalog names the pins by the data sheet's port names. PB6 and PB7 on
the 8 MHz build have no number in the core, so reach them through PORTB and
DDRB.
Wiring it up
The chip does nothing until it has a supply. This is the wiring the starter projects use:
VCC(pin 7) andAVCC(pin 20) to 5 V.- Both
GNDpins (8 and 22) to ground. - A 10 k resistor from
RESET(pin 1) to 5 V, so the chip is not held in reset by noise. - An LED and a 220 ohm resistor on
PB5(pin 19), which is pin 13 in code.
A real 16 MHz chip also needs its crystal between pins 9 and 10, with a 22 pF capacitor from each of those pins to ground. In Mokxi the crystal is not a part, so you can leave it out and the chip still runs at 16 MHz.
There is no LED, and no supply
A bare chip has no board, so it has no LED of its own. LED_BUILTIN is still
13, which is PB5, pin 19, so a sketch written for the Uno blinks whatever you
wire there.
VCC is an input, not a supply. The chip runs only while VCC is wired to a
supply of 1.8 V or more. Without one, every pin lets go and nothing runs, which
is the commonest slip on a real breadboard too. Check the supply first when
nothing happens.
Programming a real one
A bare chip has no USB, so a real one needs one of two things:
- A programmer. A USBasp, or an Uno running the Arduino as ISP sketch from
the IDE's examples. The programmer's
MOSI,MISOandSCKgo toPB3,PB4andPB5(pins 17, 18 and 19), its reset line goes toRESET(pin 1), and the chip needs its supply and grounds as above. In the IDE, pick Arduino Uno as the board, then use Sketch, Upload Using Programmer. - The Uno's bootloader, through a USB serial adapter. A chip with the
Uno's bootloader burned in takes the ordinary Uno upload. The adapter's
TXgoes toPD0and itsRXtoPD1, and the chip has to reset as the upload starts.
The 8 MHz chip needs its fuses set for the internal clock first. Install MiniCore by MCUdude, pick ATmega328 as the board and Internal 8 MHz as the clock, and use Tools, Burn Bootloader once with a programmer. That is what sets the fuses. After that, upload with the programmer as above.
Mokxi's upload card gives you the program as a .hex file and the avrdude
line that writes it.
What is modeled
- The whole ATmega328P, as on the Uno: every instruction with its data sheet cycle count, three timers in every mode, USART0, the ADC, interrupts, sleep and EEPROM.
- The clock of each build: exactly 16 MHz, or exactly 8 MHz.
- The supply on
VCC: below 1.8 V, or with nothing on it, the chip stops and every pin lets go. RESET: low holds the chip in reset, and it starts again when it goes high.- The 28 pins in package order, with pins 9 and 10 as the crystal's on one
build and as
PB6andPB7on the other.
Serial reaches the serial monitor directly, as on the Nano, and pins 0 and 1
stay plain GPIO.
What is not modeled
- The crystal and its two capacitors. They are not parts, and the clock is the build's whether or not a crystal is wired.
- The internal oscillator's error. A real one is off by a few percent; here the 8 MHz is exact.
- The supply's voltage on the pins. They swing to 5 V whatever
VCCis, so a chip on 3.3 V is not modeled as one. The speed grade is not checked either: a real chip wants 4.5 V for 16 MHz, and here it runs at 16 MHz on any supply of 1.8 V or more. AVCCandAREF. Wire them as you would on the bench, but nothing checks them:analogReadreads against 5 V either way.- Fuses and burning a bootloader. Each build starts with its clock set, and no bootloader runs first.
- SPI and I2C as peripherals, as on the Uno.
Starter projects
ATmega328P on a breadboard is the 16 MHz chip wired as the tutorial wires
it, with 5 V on VCC and AVCC, both grounds, a 10 k pull-up on RESET, and
an LED on PB5 running the Uno's Blink. Pull the wire to VCC and it stops.
ATmega328P at 8 MHz is the same circuit on the internal clock, running a
Blink built for 8 MHz.