Arduino Mega brain transplant
While building a MIDI controlled LED suit we accidentally damaged 2 of the Arduino Mega pins. There was no output from Digital 4 and 5 , just floating.
luckily we had some Atmega640 100 pin ICs around. They are from the same family as the Atmega2560 and are pin compatible but has a quarter of the memory.
The only problem is that the Arduino mega 2560 bootloader can't be "just uploaded" to the 640.
I found some source files from http://www.avr-developers.com/bootloaderdocs/index.html (link to file) and then spent a few hours down rabbitholes to compile the bootloader.
There is a pre compiled bootloader for the AtMega640, but it uses UART1 whereas Arduino boards are laid out to use UART0. to save you the effort of recompiling for the 640 the compiled file is on GIThub. I uploaded it to the 640 using an AVRISP MKII, but you can use any flashing tool that works for you. the fuse settings are the same as for the 2560 ( i think we might get away with a smaller bootloader section, but i kept it the same anyway)
mega640.bootloader.low_fuses=0xFF
mega640.bootloader.high_fuses=0xD8
mega640.bootloader.extended_fuses=0xFD
mega640.bootloader.lock_bits=0x0F
add this to your \arduino install folder\hardware\avr\boards.txt
############################################################## mega640.name=Arduino Mega 640 mega640.cpu=640 mega640.upload.tool=avrdude mega640.upload.protocol=wiring mega640.upload.maximum_size=61440 mega640.upload.speed=115200 mega640.bootloader.tool=avrdude mega640.bootloader.low_fuses=0xFF mega640.bootloader.high_fuses=0xD8 mega640.bootloader.extended_fuses=0xFD mega640.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex mega640.bootloader.unlock_bits=0x3F mega640.bootloader.lock_bits=0x0F mega640.build.mcu=atmega640 mega640.build.f_cpu=16000000L mega640.build.core=arduino mega640.build.variant=mega
##############################################################
When you restart your Arduino IDE ( or whichever IDE you use to program arduino ) you will see a "mega 640" in the list of boards.












