Ubuntu Terminal avrdude timeout [SOLVED]

Im using Linux Mint with avrdude and avr-gcc installed. Im trying to upload this program to Arduino Leonardo. I got it to compile just fine, but make avrdude command (in linux terminal) returns timeout(). Uploading works fine through Arduino IDE.

I tried numerous ways to get avrdude to upload by resetting the Arduino:

1.) Connect GND-RESET OR 1click reset btn before uploading = using this method Arduino resets, but upon initializing "sees" that the ttyACM0 port is being used (by avrdude trying to upload the program), and it just switches to ttyACM1!

2.) Double click reset button puts the Leonardo in -LED 13 fading for some seconds- mode, that (at least on Linux) while it lasts seems to just not have any port opened, so that avrdude just fails because there is no port opened.

I also tried changing the programmers (avrisp, avrispmkII, avr109) in the makefile. Still the same error, just said differently - the avrdude run from terminal just cant upload to arduino

If uploading with the IDE works, then the command line being used to run avrdude in the makefile is different than what the IDE is using.

If you haven’t already, turn on verbose mode in the IDE and look at the command line used for avrdude.
Edit the makefile to create and use the same commandline that the IDE uses.

There are either path issues, or a difference of arguments / options.

— bill

thanks, i already tried it but if this helps, here are the commands:

terminal:
avrdude -p atmega32u4 -P /dev/ttyACM0 -c avrispmkII* -U flash:w:MIDI.hex
*note that I tried different programmers like avr109 etc..

arduino ide:
avrdude -C avrdude.conf -v -p atmega32u4 -c avr109 -P /dev/ttyACM0 -b 57600 -D -U flash:w:/tmp/arduino_build_511820/Blink.ino.hex:i

arduino command I simplified because it included paths to files like avrdude

Also, the Arduino IDE resets the com port before uploading. But avrdude doesnt seem to do that, and Im wondering if that isnt the problem, and I cant reset manually since as i said, it resets but to a different COM port.

The reset is triggered when the Leonardo's virtual (CDC) serial / COM port is opened at 1200 baud and then closed. When this happens, the processor will reset, breaking the USB connection to the computer (meaning that the virtual serial / COM port will disappear). After the processor resets, the bootloader starts, remaining active for about 8 seconds.

arduino ide log: translated
Forced reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, } / {} => {}
PORTS {} / {} => {}
PORTS {} / {/dev/ttyACM0, } => {/dev/ttyACM0, }
Found upload port: /dev/ttyACM0

So why are you using different command line options than the IDE?
including a different programmer?
This is not showing that it works for the IDE but not with make.

Details really matter so show everything and I mean everything, including if there is more than one avrdude command being used.

Also, there is a bug in avrdude in that if you try to do back to back avrdude commands with an Atmel based products that use USB like the Dragon, or the avrispmkII, avrisp2, it will fail.
And despite what you may read in any of the Arduino threads or in Arduino issues, it is not an IDE issue. It is an avrdude issue.

If you are doing back to back avrdude commands here is more about it:

I reported this 8 years ago. I even provided a 6 line fix to avrdude to fix it but Joerg refuses to put it in the code.
He claims it is libusb issue, however, Avrdude created this issue by resetting the USB so it should be fixed in avrdude by having avrdude wait for devices to re-enumerate - and it doesn’t.
It is infuriating since this bug has been known for so long, and there is a small & simple solution, but yet the issue still remains.

Here are some links about this issue,

https://savannah.nongnu.org/bugs/?34339

The real solution is to fix avrdude, it is a very small 6 line fix.
Other than that, there are a few ways to kludge a work around by either avoiding using multiple commands by doing more in a single command, or put a delay of several seconds between commands.
I see many cases where multiple avrdude commands are being done to set fuses, burn a bootloader, code, etc… when it could all be done in a single avrdude command. Doing it all in a single command will avoid the avrdude issue.

— bill

Just tried this stackoverflow. Its the same thing as if I reset the Leonardo by clicking the reset button. It resets but opens up another available COM port while avrdude waits, and can wait for a century for Leonardo to come back to COM0 but it never does as long as avrdude is running.
I have yet to look at the links you sent me

If you are not using an atmel ISP programmer over USB then the stuff I pointed out does not apply.

I am no fan of leonardo. I have had many serial port issues with that board due to the way the virtual com is implemented.
I avoid it. For an AVR processor with native USB support, I much prefer the Teensy products. They "just work".

--- bill

  1. Link - avrdude doesnt do anything to leonardo as far as Im avare, the previous program still stays here, and the arduino is perfectly usable with Arduino IDE
    other links - this is what I write to the terminal:

make avrdude

at first the program is compiled or idk what happens, but on the second run with the same commands, the avrdude goes straight to uploading, so I dont think there are two commands

[AVRDUDE] : Programming device "atmega32u4" FLASH using "avrispmkII" on port "/dev/ttyACM0"
avrdude -p atmega32u4 -P /dev/ttyACM0 -c avrispmkII -U flash:w:MIDI.hex
avrdude: stk500v2_ReceiveMessage(): timeout

As to why am I using different options than arduino IDE? I dont know what Im doing. Im so glad that I even got the project to compile successfully, and now, I just need to figure out the simplest(nothing ever works the way its supposed to for me) part - upload to Arduino. Im trying to find where exactly in those files is the avrdude command located, because right now I only found makefile, where I can edit only the programmer, the arduino cpu/speed/architecture

bperrybap:
If you are not using an atmel ISP programmer over USB then the stuff I pointed out does not apply.

I am no fan of leonardo. I have had many serial port issues with that board due to the way the virtual com is implemented.
I avoid it. For an AVR processor with native USB support, I much prefer the Teensy products. They "just work".

--- bill

I will definitely consider this the next time when buying microcontroller for these kinds of tasks. What Im trying to do with the makefiles etc.. is only because there is no simple and clear way (at least for me) to control the USB device aspect of the Leonardo without knowing basically everything about programming and microcontrollers

I'm really not understanding what you are doing.
I can't tell if you are using an ISP programmer or trying to talk to a bootloader over a virtual serial connection to the leonardo.
One big difference is the baud rate.

The makefile should have everything needed to tell make how to build the image and flash it.
The makefile is a script like file that tells make how to work/behave.
but if the IDE is able to build your project and flash it, then use that instead of make.

--- bill

What about using the Arduino IDE from the command line rather than creating your own code to use AVRDUDE?

That is how I do all my Arduino programming with Linux Mint on this laptop. I have created this short Python program to compile and upload using the Arduino IDE command line,

...R

But I dont have an ino file. As I said, i dont know what im doing. All I know is that I need to run the command "make avrdude".

motorko:
What Im trying to do with the makefiles etc.. is only because there is no simple and clear way (at least for me) to control the USB device aspect of the Leonardo without knowing basically everything about programming and microcontrollers

make doesn't have anything to do with the actual s/w or its functionality. i.e. controlling the USB interface from a leonardo.

make is just unix tool used to, well, "make" things.
It has existed for around 50 years. The Arduino team decided not to use it and instead decided to re-create the world by building a similar, but less functional, equivalent of a build tool that is used by the Arduino GUI IDE.

The tool(s) you use to build your image and flash it into your device are independent of your actual code.
i.e. you can use the Arduino IDE, or make with your own custom written makefiles, I do that typically when not using the Arduino environment and Arduino libraries,
or you could use eclipse with Arduino plugins, or MPIDE, etc...
Any of those tools as well as others can be used to build images and flash it to devices.

--- bill

bperrybap:
make doesn't have anything to do with the actual s/w or its functionality. i.e. controlling the USB interface from a leonardo.

make is just unix tool used to, well, "make" things.
It has existed for around 50 years. The Arduino team decided not to use it and instead decided to re-create the world by building a similar, but less functional, equivalent of a build tool that is used by the Arduino GUI IDE.

The tool(s) you use to build your image and flash it into your device are independent of your actual code.
i.e. you can use the Arduino IDE, or make with your own custom written makefiles, I do that typically when not using the Arduino environment and Arduino libraries,
or you could use eclipse with Arduino plugins, or MPIDE, etc...
Any of those tools as well as others can be used to build images and flash it to devices.

--- bill

I wanted to point out that all this things - make, avrdude etc. I know what they do, but I dont know how to use them. In fact this is probably my second time Ive compiled something using make. So if there were more good libraries and documentation on how to handle leonardo usb, I could just use Arduino IDE with normal ino file. Instead, I dont know what Im doing and Im hoping that at the end of this make stuff I will be able to upload the program to the arduino.

motorko:
So if there were more good libraries and documentation on how to handle leonardo usb, I could just use Arduino IDE with normal ino file.

I think you would be much happier with a teensy product.
Pauls s/w that he provides for his teensy products is much better than the stock Arduino.cc code.
They also upload much faster than the standard Arduino products.

Here is a link to the teensyduino s/w, which includes good USB support and examples:
https://www.pjrc.com/teensy/teensyduino.html

--- bill

Ok guys I did it!

So, firstly, we need to set the same parameters as Arduino IDE uses for avrdude:
(root LUFA folder)/LUFA/Build/DMBS/DMBS/avrdude.mk.
Open in text editor, and on this line:
# Construct base avrdude command flags
BASE_AVRDUDE_FLAGS := -v -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b 57600 -D
add things like -D etc., you should copy the commands that Arduino IDE uses when it successfully uploads a sketch.
Save it, now you can execute the command make avrdude, let it compile the program and let it fail to upload, then terminate it. Now, prepare make avrdude command in the terminal, but dont press Enter yet. On Leonardo, quickly double press the reset button, the LED 13 should start fading (if it doesnt, just double click again until you get it right). Right when it starts fading, press Enter to execute make avrdude (that should now just go straight to upload without compiling again). And you should be done!

If it doesnt work, make sure that:

  • avrdude uses avr109 as a programmer
  • carefully read the error message, and what happened before it stopped, make sure that you have gcc-avr or any other thing that avrdude is missing installed
  • dont double click the reset button on Leonardo while uploading, as Leonardo will come back on a different port. If it does, exit avrdude, unplug your Leonardo, plug it back in (check with Arduino IDE that Leonardo is connected). It should come back on the first available port

motorko:
But I dont have an ino file.

In your Original Post you said (in red letters) "Uploading works fine through Arduino IDE." so I think it was reasonable of me to assume you are starting with a .ino file. And I was also working on the assumption that whatever works with the IDE will also work with its command line version.

...R