Random failure to upload code.

I have an arduino demilove (atmega328) running a ported version of liblo that was our own work, and uIP based on the wishield codebase. I am programming it from an Ubuntu 10.04 computer.

I have it able to receive data and such from the wifi network and change the color of my LED light using OSC packets, but when I make updates to the code and try to upload them, about 90% of the time it fails with various errors ranging from "out of sync" to "lost communication" to "not connected". But if I keep hitting "upload" without necessarily even resetting the device, it will suddenly work.

Here are some examples of sequential error messages, after taking off the wishield just in case that is causing an issue:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_loadaddr(): (a) protocol error, expect=0x14, resp=0x10
avrdude: stk500_loadaddr(): (a) protocol error, expect=0x14, resp=0x10
avrdude: stk500_recv(): programmer is not responding
Successfully Uploaded
Successfully Uploaded
Successfully Uploaded
avrdude: stk500_recv(): programmer is not responding

and so on. This is all sequential, without any shields, with code that functions when it successfully uploads (i.e. is presumably not somehow hard-locking the arduino if that would prevent programming), and without power cycling or trying to reset the device.

I can only think of two possibilities for this.

  1. The arduino bootloader or avrdude have too short of a timeout and don't wait long enough to upload the 17596 byte program before assuming the programmer isn't responding.

  2. My code is somehow blocking the bootloader from functioning.

(2) seems unlikely because I have it turn on an LED light on startup. When I start programming, the LED light turns off. Whenever it fails to program, it turns the LED light back on before the arduino software reports successfully uploading the code. This seems to me to indicate that the device is successfully being put into "reset" mode for programming, but is leaving programming mode before it is finished.

Does anyone know how I can check to see if it is a timeout issue in the bootloader or on the avrdude side of things? Or does anyone have alternative ideas as to what the problem could be? I need this to program 100% of the time reliably (or at least 95% of the time).

I tried uploading a smaller, simpler program (1334 bytes) 20 times, and it worked 19 times out of 20. Unfortunately, this doesn't help me distinguish between problems (1) and (2), but it does verify that my programmer in general does work (assuming the one failure was a fluke).

Thanks,

To make things weirder, get this.

I upload my small code that works fine. It cycles the LED colors forever in a loop.

Then, I upload my gigantic code that does wifi control of the LED lights through python. It reports "avrdude: stk500_recv(): programmer is not responding".

HOWEVER:

The code is still running! It turns on the red channel on dim until it successfully connects to the wireless network, flashes blue and then off, and then I can control it perfectly from my python script!

What is with the scary error? Is my code uploaded correctly or not? Can I verify the code manually? I know how to do that on a normal atmega, but not inside of arduino...

It sounds like the auto reset on the arduino is not working correctly or your PC is too slow (or too fast) that it is missing the download window the boot loader opens after reset.
You can try increasing the value of the capacitor from the DTR line to the reset line by soldering another one in parallel. Use as big a non polarised value as you can get. I sometimes use a 1uF here.

Wow; I didn't realize there was a power reset startup circuit in there. Capacitor + Transistor + Resistor for delayed powerup?

Ick. As much as I'm not terrified about changing something like this, is there any way to address this in software? If it actually is a capacitor on the reset line that gradually pulls it back up, it sounds like a resounding "no"...

Surely other people have this issue with large programs... and if it's resetting before finishing upload, god knows what the code is that's actually there... =(

Is there anything I can do short of soldering a new resistor onto 100+ arduino boards...?

Does anyone know how I can check to see if it is a timeout issue in the bootloader or on the avrdude side of things?

You will get details if you hold down the SHIFT key while performing the upload.

Well before you do 100 boards I would check that it works with one first. It's just a capacitor no transistors involved.
If it is that then you could modify the boot loader to wait longer on power up, but you need a programmer to put that in to your board.

I do have a mkII for in circuit programming, although I had hoped that using arduino would mean I could leave it collecting dust :wink: And thanks for the advice about not doing 100 before I do a working prototype, I will definitely do that. It's good to know that I can at least change the time the bootloader waits for powerup. I am not entirely clear on how the bootloader can change the timing for reset, but I assume it's just outputting 5V through a resistor into a capacitor connected to reset?

Actually (sorry, I'm new to the arduino platform), there appears to be an option for using the arduino "as an ISP". Does that mean I can burn a bootloader by using the existing bootloader? Huh? If that was the case, I'd be pretty excited, because then at least it's just a two-step programming operation that I could script to happen from a single command without having to do multiple wiring jobs.

Thanks for that debug info Coding Badly. It outputs a lot of stuff, but it scrolls by quickly and the buffer isn't long enough to see the beginning by the end... do you know if I can make it send the debug output to a file? In any case, I captured it in the terminal and this is what it said:

avrdude: Version 5.10, compiled on Mar 23 2010 at 15:05:31
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/neltnerb/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         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

...

         Programmer Type : Arduino
         Description     : Arduino
avrdude: Send: A [41] . [80]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [02] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [81]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [01] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [82]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [98]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [03] 
avrdude: Recv: . [10] 
         Hardware Version: 2
         Firmware Version: 1.16
avrdude: Send: A [41] . [84]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [85]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [86]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [87]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [89]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [01] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [82]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Recv: . [10] 
avrdude: Send: B [42] . [86] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] . [80] . [04] . [00] . [00] . [00] . [80] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: E [45] . [05] . [04] . [d7] . [c2] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: P [50]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: AVR device initialized and ready to accept instructions

Reading | avrdude: Send: u [75]   [20] 
avrdude: Recv: . [14] . [1e] . [95] . [0f] . [10] 
################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: Send: V [56] . [a0] . [03] . [fc] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [a0] . [03] . [fd] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [a0] . [03] . [fe] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [a0] . [03] . [ff] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: reading input file "/tmp/build1252157735055366361.tmp/LightBrick.cpp.hex"
avrdude: writing flash (17602 bytes):

followed by many lines of output of bytes being sent to the arduino's flash memory, with intermittent receives, and ending with something like this:

avrdude: Send: t [74] . [00] . [80] F [46]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [80] . [93] ? [3f] . [05] . [0e] . [94] . [be] . [18] q [71] . [c6] / [2f] p [70] # [23] 0 [30] . [09] . [f0] . [a2] . [c7] . [88] . [e0] . [80] . [93] ? [3f] . [05] . [0e] . [94] . [be] . [18] & [26] . [c6] . [85] 0 [30] . [19] . [f5] . [e0] . [91] @ [40] . [05] . [f0] . [91] A [41] . [05] . [84] . [81] . [95] . [81] . [89] + [2b] . [09] . [f4] . [91] . [c7] . [10] . [92] E [45] . [05] . [10] . [92] D [44] . [05] . [c9] . [01] . [0c] . [97] . [90] . [93] C [43] . [05] . [80] . [93] B [42] . [05] . [90] . [93] : [3a] . [05] . [80] . [93] 9 [39] . [05] . [10] . [92] 8 [38] . [07] . [10] . [92] 7 [37] . [07] . [10] . [92] 8 [38] . [05] . [10] . [92] 7 [37] . [05] . [88] . [e0] . [80] . [93] ? [3f] . [05] . [aa] . [c1] . [80] . [91] k [6b] . [05] . [90] . [91] l [6c] . [05] . [01] . [96] . [90] . [93] l [6c] . [05] . [80] . [93] k [6b] . [05] . [e9] . [01] . [a8] . [97] . [80] . [91] 
avrdude: Recv: . [10] 
avrdude: Send: U [55] @ [40] . [09]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: t [74] . [00] . [80] F [46]   [20] 
avrdude: Recv: . [14] 
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

the timing of which correlates with my "on" LED turning back on.

Does this sound like the "resetting too soon" issue Grumpy_Mike suggested to everyone else as well?

Your version...

avrdude: Version 5.10, compiled on Mar 23 2010 at 15:05:31
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

My version...

avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

Do you have more than one AVRDUDE on your computer?

Whoa, that's very odd. I have avrdude version 5.10 installed from programming atmegas on my own. Version 5.04-arduino must be included with arduino's frontend. I can't even locate the 5.04 binary on my computer. I definitely didn't intentionally install another one... I hope they didn't copy+paste the entire codebase into the arduino software!

I will try uninstalling 5.10 temporarily to see if that helps (after I get home from work), but that's not a particularly good long term solution as I still have my own boards without arduino software running on them.

I will try uninstalling 5.10 temporarily to see if that helps

You shouldn't need to do that. Modify the PATH so the AVRDUDE you want to run is earlier in the list.

Or, try running the AVRDUDE of choice from the command-line. The HEX file for your Arduino Sketch is in the TEMP directory after you perform a Verify.

I can't figure out where avrdude 5.04 is installed; the binary is nowhere on my system. So, the only way I can think of to make it run the 5.04-arduino version that I assume is packaged with the arduino software would be to get rid of the previously installed version, right?

Sorry if this is a stupid question, I'm an ubuntu user after all :wink: It's been a few years since I really had to use the command line and shell scripting hard.

I'm an ubuntu user

I'll try to help as much as I can but someone with Linux experience may have to step in.

I can't figure out where avrdude 5.04 is installed

I have Windows Vista. My current Arduino "root" is "C:\Arduino\arduino-0019". AVRDUDE is under that directory in "C:\Arduino\arduino-0019\hardware\tools\avr\bin"

So, the only way I can think of to make it run the 5.04-arduino version that I assume is packaged with the arduino software would be to get rid of the previously installed version, right?

I wouldn't think so. AVRDUDE seems to run fine from wherever it's located. I assume it can be copied where you like and run from there.

Sorry if this is a stupid question

I think they're good questions. Unfortunately, I don't have good answers!

I'm getting a bit concerned that we may be drifting from the original problem. When I mentioned the difference in versions, I assumed you were using Windows and switching versions would be trivial. Before making any potentially dramatic changes to your computer, you way want to spend a bit of time with Google to try and determine if there are any relevant issues with version 5.10.

Have you tried a different USB port on your computer? Have you had any other USB devices misbehave? Can you test with a USB hub in the middle?

Don't forget about Grumpy Mike's suggestion. He occasionally gets it right. :wink:

HAve u a linux OS?

A lot of questions here.

do you know if I can make it send the debug output to a file?

If you run avrdude on the command line, this is simple, just pipe the output from avrdude into a file:

avrdude [your usual flags, files, etc] > output_file.txt

I can't figure out where avrdude 5.04 is installed

I have Windows Vista. My current Arduino "root" is "C:\Arduino\arduino-0019". AVRDUDE is under that directory in "C:\Arduino\arduino-0019\hardware\tools\avr\bin"

Arduino's root directory on linux usually installs into:
PATH/share/arduino-0019

On ubuntu, you'd probably find it in:
/usr/share/arduino-0019/hardware/tools/

I'm an ubuntu user after all Wink It's been a few years since I really had to use the command line

This seems backwards to me.

HAve u a linux OS?

Yes

ok, maybe you need to take a look here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282403628 at my last post.
Please tell me if have solved. :slight_smile: