Trying to program Arduino using avrdude through command line and getting "avrdude: jtagmkII_getsync(): sign-on command: status -1"

Hello! I'm very new to Arduino. I'm trying to program my device through the command line by using the "avrdude" and "avrdude.conf" copied from the ide.
I can program with the ide, it generates this command:

C:\Users\goku6\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\goku6\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cjtag2updi -PCOM3 -b115200 -e -D -Uflash:w:C:\Users\goku6\AppData\Local\Temp\arduino_build_293019/basn_core_v1_test.ino.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x00:m {upload.extra_files} 

I took the files it's referencing, copied them into a different folder, and ran this version of the command:

avrdude -C avrdude.conf -v -p atmega4809 -c jtag2updi -PCOM3 -b115200 -e -D -Uflash:w:basn_core_v1_test.ino.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x00:m {upload.extra_files}

When I run the second command I get this output:

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean,
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is avrdude.conf

         Using Port                    : COM3
         Using Programmer              : jtag2updi
         Overriding Baud Rate          : 115200
avrdude: jtagmkII_getsync(): sign-on command: status -1
avrdude: jtagmkII_getsync(): sign-on command: status -1

Any idea on how I can fix this? I feel like I'm missing some step, but not sure what. Thank you in advance!

After some research, I think I have to open/close the port first. How would I do that using python or cmd?

I've corrected my issue. The reason is that the port was close and I had to open then close it to get back into programming mode. You can do this easily with python:

#pip install pyserial
import serial
ser = serial.Serial()
ser.baudrate = 1200
ser.port = 'COM3' #This has to be the port the Arduino is connected to, won't work if it's another.

Then you run the commands from the IDE and AVRDUDE should handle it from there.

1 Like

Well done and thanks for the feedback. You can tick the solution checkbox under the most useful reply ( your last one :wink: ) so others with the same problem know that a solution is provided.