upload works from arduino but not from avrdude

I have an Arduino Duemilanve 328 and an Arduino Diecimila 168. I can upload sketches to both just fine with the java arduino program. I also want to be able to program these boards with avrdude directly. Unfortunately, if I manually run avrdude in the exact same way that aruduino does, it only will program correctly the very first time that I plug it in. What am I missing?

I ran ./arduino with the upload.verbose=true option so that it would give me the avrdude command that it uses to upload the sketch. If I cut and pasted that exact same command to the command line, it times out. If I run it from arduino, it uploads just fine every time.

Is there some additional trick that the java aruduino runtime is playing when it executes avrdude that makes it run correctly?

/home/user/arduino-0017/hardware/tools/avrdude \
-C/home/user/arduino-0017/hardware/tools/avrdude.conf -v -v -v -v \
-pm328p -cstk500v1 -P/dev/ttyUSB0 -b57600 -D \
-Uflash:w:/home/user/arduino-0017/examples/Digital/Blink/applet/Blink.cpp.hex:i

Thank you in advance for the help,
Head Tinker
tinkerish.com

Could it be the activation and timing of the board reset command? The Arduino IDE resets the Arduino board via toggling the DTR control signal before handing off to the AVRDUDE process. Perhaps if you manually reset the board with the reset switch (at the correct time, whenever that is) it will work.

I've read that the newest version of AVRDUDE has the Arduino auto-reset option built into in and might be included in the next Arduino IDE release, relieving the IDE from having to do that task.

Lefty

Lefty,

That sounds like a very plausible explanation. I tried hitting the reset button at various different times with no good results.

I've been looking through the arduino java souce. I see in Uploader.java in flushSerialBuffer() where this is done. Also, I see that routine called in AvrdudeUploader.java right before calling the actual avrdude(). Again, I tried simulating this with my finger but never got it to work.

Anyone know more specifics of why this is necessary and how to work around it? The vanilla non arduino ISPs that I am used to hold down reset the entire time they are programming (AFAIK). I can see in the schematic that the reset pin on the ISP and the reset button and the DTR from the FTDI chip all go to the same place. Perhaps it is time to get out the scope tomorrow.

Stop the presses. I got it to work! I just pressed and released the reset button fairly quickly right before issuing the avrdude command. I got it to work many times in a row now.

Thanks for the help!

I got it to work many times in a row now.

Great. Like I said there is a good chance that the next release of the IDE will fix that hassle.

Lefty

A lot of people write a small wrapper script that pulses the DTR line before running the avrdude command. You can apparently do it with Perl like this (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1255121021/2#2 ):

perl -MDevice::SerialPort -e 'Device::SerialPort->new("/dev/ttyUSB0")->pulse_dtr_on(1000)'

or Python like this (http://johanneshoff.com/arduino-command-line.html ):

import serial
import time
import sys

if len(sys.argv) != 2:
    print "Please specify a port, e.g. %s /dev/ttyUSB0" % sys.argv[0]
    sys.exit(-1)

ser = serial.Serial(sys.argv[1])
ser.setDTR(1)
time.sleep(0.5)
ser.setDTR(0)
ser.close()

Andrew

I have the same issue using Ubuntu 9.10 32-bit.
A workaround is to keep reset depressed until the RX LED starts flashing during download. Works 100% of the time for me.
Strangely it worked fine under 9.04

::slight_smile: