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?
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.
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.
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()
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