Using an off-board programming tool, it’s possible to program the Arduino Mega 2560 directly through the ICSP pins.
I have a Sparkfun Pocket AVR Programmer at my desk, but according to their documentation as of 04.12.2015, the ATmega2560 is unsupported. Pololu has an inexpensive USB AVR Programmer that is up to task.
- Windows 7 Professional, x64
- Arduino IDE 1.62
- USB AVR Programmer Windows Drivers and Software release 121114
- AVR Downloader/UploaDEr (AVRDUDE) version 5.10
- Windows 7 Professional compatible computer or VM.
- Arduino Mega 2560 R3
- Pololu USB AVR Programmer
- USB-B cable
- A way to power the board e.g. HERE
- Install all software for the Arduino IDE and Mega. Make sure you can program ‘Blink’.
- Follow all the installation instructions for the AVR Programmer.
- Install AVRDUDE. Sparkfun and Adafruit have tutorials if you’ve never used.
- Open the Arduino IDE for software development, and a command window for programming.
- Make yourself an Arduino sketch, perhaps fork ‘Blink’ and change the blink times to 5 seconds. Verify…but don’t upload.
- The compiled .hex is found in your AppData directory, on my computer it’s here: “C:\Users\samueltoepke\AppData\Local\Temp\buildXXXXXXXX.tmp”. AppData is hidden by default, so make sure to change that setting in “Folder and Search Options -> View -> Advanced Settings -> Show Hidden Files, Folders, and Drives”.
- Make sure the Arduino is being powered by a DC source, the AVR Programmer is properly connected to the ICSP connector, and the USB cable is unplugged.
- In the command window, run your version of (make sure to change file and COM port): ($ avrdude -p m2560 -c stk500v2 -P COM14 -b 115200 -F -U flash:w:”C:\Users\samueltoepke\AppData\Local\Temp\build7577322246968947662.tmp\BlinkDiff.cpp.hex”:i).
- The end result should look like:
- Continue developing in the Arduino IDE, and uploading the .hex files using the command window.
When you’re done with your project, it will be necessary to re-burn the Arduino Bootloader if you want to use the board with just a USB cable again.
You’ll have to find the bootloader .hex. It can be downloaded online, or you can get it from your Arduino IDE install folder. Searching for “stk500boot_v2_mega2560.hex” using Windows Explorer in your install directory “C:\Program Files (x86)\Arduino” should find it. For my version/install the file was in “C:\Program Files (x86)\Arduino\dist\default_package.zip\packages\arduino\hardware\avr\1.6.2\bootloaders\stk500v2\stk500boot_v2_mega2560.hex”.
- In the command window, set fuses: ($ avrdude -P COM14 -b 19200 -c stk500v2 -p m2560 -v -e -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m).
- In the command window, burn bootloader: (avrdude -P COM14 -b 19200 -c stk500v2 -p m2560 -B 1 -v -e -U flash:w:”C:\Users\samueltoepke\Documents\stk500boot_v2_mega2560.hex”:i -U lock:w:0x0F:m).
- Unplug the DC power, unplug the AVR Programmer, hook the USB cable up, restart the Arduino IDE, and you should be able to Verify and Upload code without a problem.