My own Atmega168 …

… or how I can use the Arduino as ISP!

There are a lot of tutorials with removing the original chip from the board. I will show you an solution without removing!

20151127_141224

You know this situation: You build a project that based on on the Arduino Uno. You finish it, and now? You use the Arduino in this project and for future projects you must buy you an new arduino Uno.
No, this is not necessary! What you need is only the chip, not the whole Arduino Uno (or Nano, …). After search in the internet I found the answer: Yes, with the Arduino Uno it’s possible to program your own Atmega chip.

Now I will show you, how you can do this.
First, some basics:
Currently I’m using the Arduino Uno and an Arduino Nano. The heart of this are the Atmega microcontroller. One of this is the Atmega328, the other one is the Atmega168. Let us compare both:

Atmega168

  • MHz: 20
  • Flash: 16 kByte
  • EEProm: 512 Byte
  • RAM: 1 kByte
  • I/ O: 23

Atmega328

  • MHz: 20
  • Flash: 32 kByte
  • EEProm: 1 kByte
  • RAM: 2 kByte
  • I/ O: 23

You see, both are equivalent. They differ only on in the amount of memory. Therefore you can run your programs also on an Atmega168 microcontroller (if the memory is enough).
Currently, the price is the same … more or less 3 Euro

How works it?
Using the Arduino Uno we will program a new Atmega microcontroller on a breadboard.
To realise it, we need the following steps:

  1. Change the Arduino to an “ISP”
  2. Burn the bootloader on the new chip
  3. Transfer the source code into the new chip

Preparations:
Be sure, you use an actually version of the Arduino IDE (version 1.5 or 1.6). I tested it with version 1.01 and got a lot of errors. After changing the version to 1.6 it runs without an error. *** smile ***

 

Step 1: Change the Arduino to an “ISP”

Don’t connect any wire at your board. Please, leave it blank! Connect the Arduino Uno with your computer and start the Arduino IDE.
Load the following source code (saved under examples): ArduinoISP.
Now, upload (run) this sketch. …. without an error.
That’s all in this step.

Note:
What is an ISP? ISP = In System Programmer.
With this sopurce code is our Arduino Uno a system programmer for other chips.

Step 2: Burn the bootloader on the new chip

Before we can do this, we must connect our breadboard.
And now, we have two possibilities. The microcontroller needs an tact. Normally used it an external tact source (oscillator) (16 MHz Quartz). You can omit this tact source, but I don’t show you this here. I will describe only the possibility with an external tact source.

What we need:

  • 1 breadboard
  • 1 Atmega168 or Atmega328
  • 1 oscillator(crystal) (16 MHz)
  • 2 capacitors 22 pF

fritzing

For your control:
This is the pin mapping from the Atmega datasheet.

atmega168_arduino_pinbelegung

So, we can start to burn the bootloader. A lot of people say, this is not necessary, but I show you this step.
After connecting the breadboard, we must do two things:
First: open in the Arduino IDE the tools menu, select “Programmer:” and change the entry to “Arduino as ISP“. At this point our Arduino Uno will work as “In System Programmer”.
Secondly: Please forget now your Arduino Uno, these question is the question about your microcontroller on the breadboard! If you use an Atmega168 you should select in the tools menu as board: “Arduino mini” and as prozessor: “Atmega168”. If you have an Atmega 328 on your Breadboard, change the prozessor to Atmega328.

Arduino IDE

And now select from the tools menu: bootloader burn …

 

Step 3: Transfer the source code into the new chip

To do this without removing the original microcontroller from the Arduino Uno board, we need an additional software (freeware): WinAVR.

Download this software and install it. After installing, we can start the fist test:
Open a command prompt (cmd), change to the WinAVR\bin directory and insert the following command:

avrdude -P COM5 -b 19200 -c avrisp -p m168 -n

-P COM5 means your USB Port where the Arduino is connected
-b 19200 baudrate to transmit
-c avrisp the Arduino Uno is an ISP
p m168 on the breadboard is an Atmega168

C:\WinAVR-20100110\bin>avrdude -P COM5 -b 19200 -c avrisp -p m168 -n

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.06s
avrdude: Device signature = 0x1e9406
avrdude: safemode: Fuses OK
avrdude done. Thank you.

 

If you select a wrong Board, you get an error like this:

C:\WinAVR-20100110\bin>avrdude -P COM5 -b 19200 -c avrisp -p m328p -n
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.08s
avrdude: Device signature = 0x1e9406
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
Double check chip, or use -F to override this check.

 

Let us transfer the already compiled source code.
Load you own source code (who wants to transfer) into the Arduino IDE. The settings are still:

  • Board: “Arduino Mini”
  • Prozessor: Atmega168 (or Atmega328 … what you use on your breadboard)
  • Programmer: “Arduino as ISP”
  • Pin 10,11,12 and 13 are connected to the breadboard, the oscillator is on the board.

20151130_182702

Now, select from the menu: Verify/Compile. Don’t start an upload!
When the compilation completes (without an error), you find the hex code here:

C:\users\…\AppData\Local\Temp\build…\

Use the windows explorer to change in this directory, order by date and the last build directory is the first entry.

In the next example is this the complete path:
C:\Users\rrehbein\AppData\Local\Temp\builded9e9aa8e4a52b6f3cfc553282361cc6.tmp.
Here you will find your compiled source code (.hex): In my example:
iv_18_0002_ziffern_interrupt_time_mit_RTC.ino.hex

 

With both entries we can start the transfer:

C:\WinAVR-20100110\bin>avrdude -P COM5 -b 19200 -c avrisp -p m168 -u -U flash:w:”C:\Users\rrehbein\AppData\Local\Temp\builded9e9aa8e4a52b6f3cfc553282361cc6.tmp\iv_18_0002_ziffern_interrupt_time_mit_RTC.ino.hex”:i

 

This is the complete communication (cmd):

C:\WinAVR-20100110\bin>avrdude -P COM5 -b 19200 -c avrisp -p m168 -u -U flash:w:”C:\Users\rrehbein\AppData\Local\Temp\bu
ilded9e9aa8e4a52b6f3cfc553282361cc6.tmp\iv_18_0002_ziffern_interrupt_time_mit_RTC.ino.hex”:i
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.08s
avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file “C:\Users\rrehbein\AppData\Local\Temp\builded9e9aa8e4a52b6f3cfc553282361cc6.tmp\iv_18_0002_z
iffern_interrupt_time_mit_RTC.ino.hex”
avrdude: writing flash (4746 bytes):
Writing | ################################################## | 100% 6.07s
avrdude: 4746 bytes of flash written
avrdude: verifying flash memory against C:\Users\rrehbein\AppData\Local\Temp\builded9e9aa8e4a52b6f3cfc553282361cc6.tmp\i
v_18_0002_ziffern_interrupt_time_mit_RTC.ino.hex:
avrdude: load data flash data from input file C:\Users\rrehbein\AppData\Local\Temp\builded9e9aa8e4a52b6f3cfc553282361cc6
.tmp\iv_18_0002_ziffern_interrupt_time_mit_RTC.ino.hex:
avrdude: input file C:\Users\rrehbein\AppData\Local\Temp\builded9e9aa8e4a52b6f3cfc553282361cc6.tmp\iv_18_0002_ziffern_in
terrupt_time_mit_RTC.ino.hex contains 4746 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 3.76s
avrdude: verifying …
avrdude: 4746 bytes of flash verified
avrdude done. Thank you.

 

That’s all! The microcontroller is programmed!

Note:
Please, be careful! I tested all steps repeatedly.

But I must write this here: You’re doing out at your own risk!

Advertisements