Then uploaded the ISP code to the the board. Finally, started burning the bootloader to the target chip.
Burning seems done with no problem. During the process RX and TX LEDs blinked and IDE output was done uploading.
Next I replaced 328 chip with the new 168 and changed the board definition in Tools menu accordingly (i.e. to a 168 chip), then opened the Blink exampled to burn. Burning failed.
Tried several time again and failed.
I guess the problem is something simple I just don't know, please tell me what it is if possible.
I chose the correct board with 328 chip as I have, then I loaded Arduino ISP program that makes the board a programmer, from this point there is a question:
where should I get the bootloader from? In Arduino folder I have hardware, then bootloader folder with hex files and a .c file. Arduino IDE will neither load hex nor .c but .pde.
0) make sure 'auto-reset' is disabled on your arduino board used as programmer
1) select the correct board/chip you want to program (168 in your case).
2) press burn bootloader "w/ Arduino as ISP".
If you want to know what happens behind the scenes, press and hold the 'shift' key before you click on the burn button.
Please let me know make sure all points I got right and on what I still have questions..
1) select the correct board/chip you want to program (168 in your case).
this is the start of my confusion point:
a) from the IDE menu, you do not have 2 choices, one for board, the other for target MCU, but only one choice for board
b) my board has a 328 chip, so I used to program it with the board selected as a Duemilanove w/ ATmega328, and on my breadboard I have my target chip which is Atmega168PA-PU
c) I am not sure if at all Atmega168PA-PU could be programmed with the bootloader hex file of a general 168 found under hardware folder. I checked the datasheet and Atmega168PA-PU can have up to 20Mhz crystal so that should be ok (theoretically), I am using a 16Mhz crystal as usual, but I'm not sure if any change in source of bootloader is needed for Atmega168PA-PU or not.
a) Yes... If you run your new 168 with 16MHz, choose the 'Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168' board type for the target to be programmed
b) That was correct. ArduinoISP runs on the 328 chip.
c) You don't have to change the source, as long as you stick to either 8MHz or 16MHz.
As you have the 168PA chip variant, you may experience error messages about a wrong device signature.
Please give a final confirmation if I got the right process:
1. I choose board as a "w/ Atmega328" and burn the ArduinoISP sketch into my 328 chip on the board
2. Having my Atmega168PA-PU on the breadboard, I wire as stated on the official tutorial (link above)
3. From the Tools menu, I "change" the board declaration to 'Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168'
4. From Tools menu, I'll finally click on 'burn bootloader w/ Arduino as ISP'
I burnt bootloader to 3 Atmega168 chips. Two of them being 10PU but I run the 16Mhz and burning was successful: I removed the ISP chip of board, leaving the 10PU on breadboard and loaded the Blink sketch to it and put LED all ok.
So there is proof of concept (i.e. I wired ok and I got the process as explained above right), but what to do with those new ATmega168PA-PU ones? I still tried some more and same error:
ERROR while burning bootloader:
avrdude: Expected signature for ATMEGA168 is 1E 94 06
Double check chip, or use -F to override this check.
You need to create a new board-type for this chip in 'boards.txt'.
Duplicate one that works with your 168-PU chip, give it a new name + description and replace 'XXX.build.mcu=atmega168' with 'XXX.build.mcu=atmega168p'.
What I used with my 168-10PU was just what you instructed, i.e. 'Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168', so I added this to the end of file (not yet tested, making sure here), please see if I changed right:
pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168PA-PU