Hex upload works in IDE but not in CLI (avrdude)a

Hello I'm new in the arduino world, so I'am trying to write my first blink program

With the IDE I can compile and upload it. But with the CLI , it Generating this output:

code:

void setup()
{
  pinMode(22, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(22, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  // turn the LED off by making the voltage LOW
  digitalWrite(22, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

output:

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/xxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/xxx/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Wiring
         Description     : Wiring
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "/tmp/arduino/sketches/7C8AAA777F9E7DDAEFDB5D1880A1A0BA/Shine.ino.hex"
avrdude: writing flash (1536 bytes):

Writing | ################################################## | 100% 0.24s

avrdude: 1536 bytes of flash written

avrdude done.  Thank you.

However I want flash it by avrdude CLI, so installed it and I used the tried this: sudo avrdude -c wiring -P /dev/ttyUSB0 -v -x delay=9000 -b 115200 -p atmega2560 -U flash:w:Shine.ino.hex:i
resulting in the following error,

Avrdude version 8.0-20240901 (30e19f23)
Copyright see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

System wide configuration file is /usr/local/etc/avrdude.conf
User configuration file /root/.avrduderc does not exist

Using port            : /dev/ttyUSB0
Using programmer      : wiring
Setting baud rate     : 115200
Error: timeout
Error: timeout
Error: timeout
Error: timeout
Error: timeout
Error: timeout
Error: timeout communicating with programmer
Error: stk500v2_getsync() failed; try -x delay=n with some n in [-80, 100]
Error: unable to open port /dev/ttyUSB0 for programmer wiring

Avrdude done.  Thank you.

I'm trying to do that for some time now so a little help is very much appreciated

Thank you in advance for your Time :slight_smile:

PS: English is not my primary language so so sorry for any grammatical issues

If you enable verbose output during upload under file/preferences in the IDE you can see the exact command that is used for the upload.

On my system uploading blink to an original Mega (you seem to be using a clone):

/home/wim/Downloads/1_arduino_ide_1.x/arduino-1.8.19-attiny/portable/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/wim/Downloads/1_arduino_ide_1.x/arduino-1.8.19-attiny/portable/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino_build_245020/Blink.ino.hex:i 

If you issue the command used by the IDE on the command line, does it work?

Note
To run avrdude from the command line, you do not need the Arduino-CLI because the avrdude is already installed.

Hello thank you i didn't tried that, but unfortunately it not worked, the resulting output is

"/home/xxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" "-C/home/xxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega2560 -cwiring "-P/dev/ttyUSB0" -b115200 -D "-Uflash:w:/tmp/arduino/sketches/7C8AAA777F9E7DDAEFDB5D1880A1A0BA/Shine.ino.hex:i"
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/xxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/xxx/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't open device "/dev/ttyUSB0": Device or resource busy
ioctl("TIOCMGET"): Inappropriate ioctl for device
ioctl("TIOCMGET"): Inappropriate ioctl for device
vrdude: stk500v2_ReceiveMessage(): timeout
vrdude: stk500v2_ReceiveMessage(): timeout
vrdude: stk500v2_ReceiveMessage(): timeout
vrdude: stk500v2_ReceiveMessage(): timeout
vrdude: stk500v2_ReceiveMessage(): timeout

The system is identifying the arduino [ 5275.377125] usb 1-2: ch341-uart converter now attached to ttyUSB0 and the permissions for /dev/ttyUSB0 are defined as:

crwxrwxrwx+ 1 xxx dialout 188, 0 set  2 13:03 /dev/ttyUSB0

my system is Ubuntu 22.04.3 with gnome terminal, what could be different between the IDE and the terminal?

Hi @mateus_habdig7oficial.

This error is probably being caused by you having the port open in the Arduino IDE Serial Monitor. Only one process at a time can have control over the port, so when it is open in Serial Monitor, AVRDUDE can't use it to upload.

You don't experience this when uploading via Arduino IDE because the IDE is smart enough to automagically juggle the control over the port between Serial Monitor and the upload tool; closing the port in Serial Monitor at the start of the upload and reopening it again after the upload finishes.

Click the X icon on the Serial Monitor tab in the bottom panel of the Arduino IDE window:

image
, then try the upload again.

Oh I'm dumb kkk, it worked now :slight_smile: , now I have to compare the command that I'm tried and the parameters of the IDE right?

I'm glad it is working now.

The command you showed here is good:

Regards, Per

thank you all for your help not it's working the final command i used is that:

avrdude -v -V -patmega2560 -cwiring "-P/dev/ttyUSB0" -b115200 -D "-Uflash:w:Shine.ino.hex:i"
Avrdude version 8.0-20240901 (30e19f23)
Copyright see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

System wide configuration file is /usr/local/etc/avrdude.conf
User configuration file /home/xxx/.avrduderc does not exist

Using port            : /dev/ttyUSB0
Using programmer      : wiring
Setting baud rate     : 115200
AVR part              : ATmega2560
Programming modes     : SPM, ISP, HVPP, JTAG
Programmer type       : Wiring
Description           : Wiring bootloader using STK500 v2 protocol
Programmer model      : AVRISP
HW version            : 15
FW Version Controller : 2.10
SCK period            : 0.1 us

AVR device initialized and ready to accept instructions
Device signature = 1E 98 01 (ATmega2560)
Reading 1536 bytes for flash from input file Shine.ino.hex
in 1 section [0, 0x5ff]: 6 pages and 0 pad bytes
Writing 1536 bytes to flash
Writing | ################################################## | 100% 0.23 s 
1536 bytes of flash written
Avrdude done.  Thank you.

Now I just need to learn to compile with avr-gcc and I no longer need to use arduino IDE :slight_smile:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.