Sunday, February 1, 2015

Program standalone breadboard Arduino of ATmega328, using Arduino Uno as ArduinoISP

This post show how to program the ATmega328 on a standalone breadboard Arduino. Using Arduino Uno as Arduino ISP.


Connect your breadboard Arduino to Arduino Uno as shown here:

Extra components needed:
- a 16 MHz crystal
- two 22 picofarad capacitors, between the crystal and GND.
- a 10k resistor, between pin 1 of ATMEGA328P and +5V.
- LED and 1K resistor, used in our Blink example. LED cathode connect to GND, anode connect to the 1K resistor, connect to pin 19 of ATMEGA328P.

The basic steps:
- Connect the breadboard to Arduino Uno as shown above.
- Connect Uno to PC using USB.
- Start Arduino IDE, and program the Arduino Uno as ArduinoISP.
- Switch Tools -> Board to our target board.
- Select Tools -> Programmer -> Arduino as ISP.
- Burn Bootloader.
- Compile and upload your sketch.

I suppose the target board is very similar to Nano board, so I select Board of Arduino Nano, and Processor of ATmega328. It success to burn bootloader, but FAIL to upload sketch, with error of:
avrdude: stk500_getsync() attempt x of 10: not in sync: resp=0x1c

As show in this video:

I have to modify boards.txt to add a new board, copy from nano. The file should be locate in the folder arduino-1.5.8/hardware/arduino/avr/. For safety, make a copy before edit.

Find the entry of nano, copy and rename another board, bba.name=BreadBoard Arduino in my case. Modify the content as:
##############################################################
# Create custom board of BreadBoard Arduino
bba.name=BreadBoard Arduino

bba.upload.tool=avrdude
#bba.upload.protocol=arduino

bba.bootloader.tool=avrdude
bba.bootloader.unlock_bits=0x3F
bba.bootloader.lock_bits=0x0F

bba.build.f_cpu=16000000L
bba.build.board=AVR_NANO
bba.build.core=arduino
bba.build.variant=eightanaloginputs

## BreadBoard Arduino w/ ATmega328
## -------------------------
bba.menu.cpu.atmega328=ATmega328

bba.menu.cpu.atmega328.upload.maximum_size=30720
bba.menu.cpu.atmega328.upload.maximum_data_size=2048
bba.menu.cpu.atmega328.upload.speed=57600

bba.menu.cpu.atmega328.upload.using=arduino:arduinoisp

bba.menu.cpu.atmega328.bootloader.low_fuses=0xFF
bba.menu.cpu.atmega328.bootloader.high_fuses=0xDA
bba.menu.cpu.atmega328.bootloader.extended_fuses=0x05
bba.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex

bba.menu.cpu.atmega328.build.mcu=atmega328p

##############################################################

Re-start Arduino IDE after boards.txt modified and saved.

This video show how to edit the file boards.txt:

Finally, we can program the ATmega328 on breadboard using Arduino Uno as ISP, and select our custom BreadBoard Arduino, of processor ATmega328 as target.

Check this video:


3 comments:

  1. Hello, thanks for tutorial, It works in ATmega328P-au???

    Great Job!!

    ReplyDelete
    Replies
    1. Suppose YES. But I haven't tried, sorry.

      Delete
  2. hello, i am having problems with burning the bootloader even though i followed the steps you provided.

    ReplyDelete