Hi. This is just a reference guide that i made motivated by the lack of clear information around Internet in the matter of programming an stand-alone Atmel ATMEGA chip different from the "standard" ATMEGA 328P-PU found in the Arduino UNO board.
While it is true that you can find all this information in other websites ( i will try to mention all of them here, too ), none of them clearly explain, step by step, how to do it without other external hardware programmers or special software. So, here we go.
The wiring is pretty simple and is already explained in the ArduinoISP sketch. Apart from the oscillator ( connected to XTAL1 and XTAL2 ) , capacitors (connected to each XTAL and to the GND ) and resistor ( connected to the RESET and VCC ), connect the following depending on the board ( UNO or Mega )
|Name||ATMEGA 2560 PIN||To||Arduino UNO PIN||Or||Arduino Mega PIN|
The first step is clear. Assuming that our ATMEGA2560 is empty, we will program the Arduino bootloader. This step is, in fact, optional, since the chip could be programmed with our sketch directly, but the Arduino bootloader eases the process of reprogramming by using only the serial RX/TX ports.
Start the Arduino IDE program. Connect just the Arduino UNO / Arduino Mega, and load the File -> Examples -> ArduinoISP sketch.
Select the appropiate board under Tools and the default AVR ISP mkII as programmer. Select the serial port and finally compile and upload the sketch as you would normally do.
Now that we programmed our Arduino with the ArduinoISP, it's time to program our litlle chip.
Disconnect the Arduino and proceed to connect the previous wiring PINs. Then reconnect the Arduino board.
Find the file called "boards.txt" located in your Arduino installation directory. In my case, the path is "arduino-1.6.5/hardware/arduino/avr/boards.txt". Open it with your favourite text editor and locate the ATMEGA2560 section.
The key line is the following:
We have to replace the value of "0xD8" with "0xD9". This is so, because in stand-alone ATMEGA2560 chips, if the BOOTRST fuse is not set, the chip will be correctly programmed, but the programs will never run. So the line could look like this ( we can keep the original line commented ):
Save the changes and now, in our Arduino IDE program, select the Arduino Mega 2560 board and processor, the Arduino as ISP programmer and finally, from Tools, choose Burn the bootloader. If everything is done correctly, the process will take some seconds and will finish with no errors. If you see some errors, i always like having the compilation and upload errors shown ( you can enable the output in the program's preferences ).
Here we have two options: we can keep the previous wiring and configuration, and upload the sketch using the "Upload the sketch using a programmer" option under the "File" or "Tools" menu, depending on the version.
Or we can just use the RX, TX and RST wiring and upload the sketch as if it was a normal Arduino Mega board, selecting the AVRISP mkII programmer, Arduino Mega 2560 board and programming it.
I haven't tried the second method, but it might work if you first remove the ATMEGA328P-PU from the Arduino UNO board ( otherwise, it will be programmed ). Ideally you should use an external programmer compatible with the SKT500v2 protocol connected to the RX, TX and RST pins.
Some people, and myself, reported having problems when using the same 5V power source from the Arduino. If you get problems about the programmer or board not responding, recheck the wirings and try using another power source for the chip ( battery, another Arduino, etc. ).
I keep receiving comments describing the situation where the sketch still doesn't run after following the instructions. Please enable the verbose mode (enable the checkboxes in the Preferences dialog for compiling and uploading) in Arduino, and check again the fuse settings applied correctly. You'll see them in avrdude command output. If it doesn't show the correct fuse value, you either incorrectly edited the boards.txt file or you edited the wrong file.