Arduino Mega 2560 programming help

I'm having trouble uploading large sketches to my Arduino Mega 2560. I've reinstalled the drivers and upgraded to the latest hourly build without success. I can upload small things, like Blink, without apparent trouble. Here's the results from the sketch I'm trying to load:

Sketch uses 47,164 bytes (18%) of program storage space. Maximum is 253,952 bytes.
Global variables use 4,977 bytes (60%) of dynamic memory, leaving 3,215 bytes for local variables. Maximum is 8,192 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM3 -b115200 -D -Uflash:w:C:\Users\Pierce\AppData\Local\Temp\build5968149608f0c3aa25eb58c9ad9cf5b0.tmp/HackerBoatLibPilot.ino.hex:i 

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Wiring
         Description     : Wiring
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 43.5 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801
avrdude: reading input file "C:\Users\Pierce\AppData\Local\Temp\build5968149608f0c3aa25eb58c9ad9cf5b0.tmp/HackerBoatLibPilot.ino.hex"
avrdude: writing flash (47164 bytes):

Writing | avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout

Any ideas about how to fix this?

Do you have a new official Arduino Mega 2560 board ? The bootloader was changed a while ago. If you have a programmer (or Arduino Uno as programmer) you can burn a new bootloader.
Can you measure the 5V pin of the Arduino board ? Perhaps you have a bad USB cable and the voltage is too low.

The board is a couple of years old now, but it is a 2560 and it has an ATmega rather than an FTDI for serial interface. Any idea how to check what bootloader it's really got on board, or how to select an older bootloader for testing?

I was hoping to avoid having to reflash, but I guess that's the next step. It's part of a larger project, and it gets its 5V from the board it's plugged into, which I can confirm is good.

Does it have string with. !!! In it? The old bootloader would hang when it got to the three ! marks in a row, and a lot of boards still ship with the old one

A couple of years is probably too old. The trouble with !!! was fixed as well as a few other problems in the bootloader. I think it was fixed in 2013.

As I said, it's a couple of years old, so it may well have the old bootloader. I loaded this board with substantially the same code a month or two ago, my add-on libraries haven't changed, and my code contains no examples of !!!.

I think I might be stuck reflashing it. :frowning:

If you have a UNO or a ISP Just reprogram the bootloader and try again....

If you have a ISP,Use it to program the mega,select " Sketch>Upload Using Bootloader " .

-Malhar

Reflashing it fixed the issue. That's only the third or fourth time I've ever had to reflash an Arduino, so I guess I should feel lucky.

For some reason the burn bootloader option didn't work for me -- I had to use Atmel Studio.

Clone Mega2560 boards with the !!! bug are still shipping, as far as I know - some people on here have reported that problem with boards they got this year.