Avrdude not working with Arduino Micro

Press and release reset.

avrdude -cavr109 -pm32u4 -b57600 -P/dev/ttyACM?

/dev/ttyACM? use the /dev/ttyACM that shows when the bootloader is running, typically will be /dev/ttyACM0

Thanks a lot guys!

Setting the baud rate to 1200 first and then sending to my original message while adding "-cavr109" did the trick.

It's working perfectly as expected now. :slight_smile:

Ingo

Can you post your bash file (or whatever you are using). Both for my learning and for others to learn.

The command is exactly what I had used before with the addition of the "-cavr109". The command is being sent from Pd within something like a hardware box. There is no feedback during programming.

OK,

this is getting very strange now:

If I reupload the sketch everything works fine.
The Arduino will restart and go through the programmed startup screen, etc.

However, if I put on the blink program first and then upload it will not upload to the Arduino!
I see the Arduino LEDs receiving something but after a few seconds it goes back to the Blink sketch.
No restarting is happening.

Programming with the Arduino IDE software works fine, though.
I can upload my programming and go beack to blink as many times as I want.

Not so with the command line from the Pd shell.

Something is still wrong.
As mentioned earlier, with my upload I cannot get any feedack.
Even if I add a print command the Arduino seems to be connected exclusively to Avrdude.
The Pd console reports during uploading "[comport]: serial port is not open".
After transmitting it will connect to Pd again normally and work again.

As of now I cannot tell if the sketch was uploaded or not.
I will have to make some change in the startup message to see if it did.

Now I tried a similar sketch with another startup message.
After uploading I got the old startup message.

So it is not uploading!

Eliminated "-D" in the command. No change!

It is doing something and restarting the Arduino but does not accept the code which is working perfectly fine when uploading from the Arduino IDE software.

I'm using 1.82 Arduino software and version 6.3 of avrdude.

When inputting the command into a Debian Bash Console I get this error:

avrdude: stk500_getsync () attempt 1 of 10 not in sync: resp=0x fd
avrdude: stk500_getsync () attempt 2 of 10 not in sync: resp=0x 05
avrdude: stk500_getsync () attempt 3 of 10 not in syn ...
...
...avrdude: stk500_getsync () attempt 10 of 10 not in sync: resp=0x 05

Here's what I'm doing:

avrdude -p m3u24 -P /dev/ttyACM0 -c arduino -b 1200

then wait for a second or two and input:

avrdude -cavr109 -p m32u4 -P /dev/ttyACM0 -c arduino -b 57600 -U flash:w:/"path_to_file"/arduremote_XO.ino.hex:i

Press and release the reset button.
Then run:
avrdude -cavr109 -pm32u4 -b57600 -P/dev/ttyACM0

This works 100% of the time on my system.
You do not have to fool around with the serial port, pushing the reset starts the booloader.
DO NOT include -carduino in your avrdude command line.

Thanks, tf68!

It works!
I can get it to upload reliably now by using /dev/ttyACM0 and pressing the reset button beforehand.
The (UDEV) link in the subfolder does indeed not work. However, I can get the ttyACM number. This is important since I have one MICRO and two LEONARDO boards that need to be identified correctly before uploading. The UDEV rule does this as it should. Then I use the number for the ttyACM.

However my problem is that the Micro is inside of a closed box with no access to the reset button.
I cannot add a hardware button on the reset pin because the units and pcbs are already built.

So, I somehow need a command line reset.

Using avrdude -c arduino -p m32u4 -P /dev/ADM0 -b 1200
seems to work at first glance when looking ar the board but gives me this error:
ioctl ("TIOCMGET"): Input/output error

Using avrdude -c avr109 -p m32u4 -P /dev/ADM0 -b 1200 returns:

Connecting to programmer
avrdude: butterfly recv(): programmer is not responding
Found programmer: Id = "?"; type =
Software Version = ?.? Hardware Version = ?.?
avrdude: error: buffered memory access not supported.
Maybe it isn't a butterly/AVR109 but a AVR910 device?
avrdude: initialisation failed, rc=-1
Double check connections and try again, or use -F to override this check.

avrdude: error: programmer did not respond to command: leave prog mode
avrdude: error: programmer did not respond to command: exit bootloader

avrdude done. Thank you.

(the "?" characters are som unreadable korean looking characters)

I was doing a search for "avrdude command line reset" but only found suggestions for Windows but not Linux.
There must be something since I don't have to push the reset button when uploading from the IDE software.

I have to correct myself for saying "I can get it to upload reliably now by using /dev/ttyACM0 and pressing the reset button beforehand."

It's very sproadic. Sometimes it works - sometomes it doesn't.
Now I can't get it to work anymore at all with the same command that was working earlier.

I press the reset button and send to a shell:

avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/"path_2_file"/"filename".ino.hex:i

This is the exact command that my Arduino IDE software uses for uploading. I used it before and it was working. Now all the sudden it's not working anymore! I tried two Arduinos and the number for the ttyACM0 is corrcect.


But it won't matter anyway because I cannot do a software reset.
What does the IDE software do to make it work? And why is it a secret that the verbose output doesn't tell you everything that it does during uploading?

OK, this is what it does during compilation:
"Forcing reset using 1200bps open/close on port /dev/ttyACM0"

I tried: avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -B1200
and avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b1200

How do you set 1200bps and open/close?
Is tis the baudrate or the bitclock?

Sterretje had mentioned this already in the beginning.
However, there is no mention about how this is done or what the command is ...

What kind of a manual or help system is this?
Ardunino can do it but doesn't let the users know how to do it?

Here's why it keeps failing:

As soon as I press the reset button the number of the ttyACM changes. Usually it goes up by one but it might also go back and forth between two numbers.

So I'm looking at ttyACM0 and as soon as I send the reset command (see below) I would have to send the programming command to ttyACM1. I havn't tested what happens exactly if this number exists. I'm assuming it takes the next unused number.

So if I see ttyACM0 I need to do a reset with
avrdude -patmega32u4 -carduino -P/dev/ttyACM0 -b1200

Then I can program the Micro with
avrdude -patmega32u4 -cavr109 -P/dev/ttyACM1 -b57600 -D -Uflash:w:/"path_2_file"/"filename".ino.hex:i

Resetting only works with -c arduino while programming works only with -c avr109.

Now it actually works for the first time (with one sinle board)!
At this point I only have to figure out what exactly happens with the numbering if I have 3 boards.

To my knowledge, it's your operating system that is responsible for the enumeration of the serial ports.
2)
If you look at the output that I gave in reply #3, the IDE does a scan by talking to every port. It first tried COM1 (and failed) and next COM7 (and succeeded). I do not know where it it's exactly done; maybe successive calls to avrdude or maybe to something else till it succeeds.

PS
You have access to the source code of the IDE :wink:

Use ls /dev/ttyACM? to see if port has changed.
The ports enumerate based on the order they are discovered or devices are plugged in.
The port can change because the original port is still valid when a new port is discovered. It is sort of by chance.
I have never had the port change when using the reset button try holding the button down for second before releasing it.

Well, the problems are that

  1. ttyACM? does not show up in /dev anymore once you have initialized the reset.
  2. the number does NOT change if you use the reset button. But it changes with the command line.

What do dmsg and lsusb (??, not really a linux user (anymore)) say under the different conditions?

In windows my COM6 (in this case) disappears and COM7 shows up when either pressing the reset button or forcing a reset using the 1200 baud from a terminal program. COM6 is 'Arduino Leonardo', COM7 is 'Arduino Leonardo bootloader'.

This works on my Linux system, it should work on yours.
On my system the Leo is on /dev/ttyACM1, /dev/ttyACM0 is being used by something else.
Open /dev/ttyACM1 at 1200 baud.
ls shows /dev/ttyACM1.
Close port, bootloader begins to run.
ls shows /dev/ttyACM1.
Upload with avrdude - success.

Whatever I do the ttyACM number goes up by 1.

I'm suspecting that I don't open and close the port correctly.
I had asked this before but unfortunately I didn't get any answer so I'm asking again:

How do you open and close the ttyACM0 port correctly?
What is the exact command?

Thanks!

The reset happens when you open and close the port with a baudrate of 1200.

You can try it manually with e.g. minicom. No idea how to script it, need a refresher in Linux.

Thanks!

Unfortunately I need to open and close from a shell and it looks like that's where the problem is.
The ttyACM0 is probably not closed properly for any reason so it reopens with a new increased number.

I found command line - How to connect to a serial port as simple as using SSH? - Unix & Linux Stack Exchange.

Hacked it a bit and it does reset a Leonardo (Ubuntu 12.04; yes I need an update)

#!/bin/sh

# connect.sh

# Usage:
# $ connect.sh <device> <port speed>
# Example: connect.sh /dev/ttyS0 9600

# Set up device
stty -F $1 $2

dmesg | tail -f

# Let cat read the device $1 in the background
cat $1 &

# Capture PID of background process so it is possible to terminate it when done
bgPid=$!

# Terminate background read process
kill $bgPid
dmesg | tail -f

I added dmesg to see, but not sure if it's useful.

Run with port and baudrate as parameters.