Arduino-cli upload sees Serial.println() output

I'm using an Adafruit Feather 328P which can be used as an Arduino Pro Mini. On first uploading an ethernet sketch from a raspberry pi 4b, it responded with programmer not responding but it uploaded the sketch anyway.

Now when I try to upload with arduino-cli:

arduino-cli upload --port /dev/ttyUSB0 --fqbn arduino:avr:pro:cpu=8MHzatmega328 Blink

I get:

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x0a
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x5b
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x77
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x65
Failed uploading: uploading error: exit status 1

the first few bytes of which correspond with the setup() output of the sketch:

if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
  Serial.println(F("Failed to access Ethernet controller"));

sudo screen /dev/ttyUSB0 57600

[webClient]
Failed to access Ethernet controller

and the sketch runs normally showing output.

I tried to upload a blink sketch but uploading no longer works. The uploader just sees the Serial.println() output in setup().

Is there anything I can do "clear" the board?

The "can only upload once" symptom could be caused by your board's auto-reset circuit not working.

Normally you need to do a hardware reset of the microcontroller to activate the bootloader, then start an upload before the bootloader times out and starts the user application. However, if there is no application in memory (as might be the case on a new board) the bootloader is perpetually activated so no reset is necessary, meaning the first upload will work with or without a reset.

The auto reset circuit (for an example, see these "minimal setup" schematics) is the DTR pin of the USB-TTL serial chip connected to the reset pin of the microcontroller via a 0.1 uF capacitor. In combination with the pull-up resistor on that pin, it generates a reset pulse when the serial connection is opened. If the board is not being reset, and thus the bootloader not being activated, this could explain the result you observed of the sketch application continuing to produce output during the upload (which would never happen while the bootloader was activated).

To test this, you could see whether uploads work after a manual reset:

  1. Hold down the reset button on the Adafruit Feather 328P board.
  2. Invoke the arduino-cli upload command from the command line, just as you did before.
  3. Immediately release the reset button on the board.

Were you able to perform a successful upload by using that technique?

thanks for that information but I've tried that lots of times from the arduino ide and arduino-cli. Holding down the reset button, then releasing with command but the error is the same. In the ide I wait until I see the "Global variables" line then release the button.

Lots of people seem to have burned a new bootloader to sort this problem.

That result does indicate that the bootloader has somehow been erased or corrupted. So I think burning the bootloader would be worth a try.

You will need an "ISP programmer" in order to perform a "Burn Bootloader" operation. An ISP programmer is a piece of hardware that allows your computer to write directly to the flash memory of the primary microcontroller on the Arduino board.

If you don't have an ISP programmer, you can use a spare Arduino board as a DIY programmer (known as an "Arduino as ISP"). I'll provide instructions you can follow to do that. The instructions I happen to have on hand are for use with Arduino IDE. If you prefer using Arduino CLI, you can adapt them without much difficulty.

Burning Bootloader with "Arduino as ISP" Programmer

A. Prepare "Arduino as ISP" programmer

Although the "Arduino as ISP" only works for programming targets of the AVR architecture, you can use some boards of other architectures (e.g., "AVR", "SAMD", "megaAVR") as an "Arduino as ISP" programmer.

I will refer to the board which will used as an "Arduino as ISP" as the "programmer board" from here on. The board you are burning the bootloader to will be referred to as the "target board".

  1. Disconnect the USB cable of the Arduino boards from your computer.
  2. Make the following connections between the pins on the "programmer board" and the "target board".
    Programmer Target
    CIPO (AKA "MISO") CIPO
    VCC 5V (VCC on 3.3 V boards)
    SCK SCK
    COPI (AKA "MOSI") COPI
    10 RESET
    GND GND
    The documentation for the boards you are using will identify the location of these pins. If you are using an official Arduino board, check the pinout diagram on the documentation page for the board.
  3. Connect the "programmer board" to your computer with a USB cable.
  4. Select File > Examples > 11.ArduinoISP > Arduino ISP from the Arduino IDE menus.
    You can download the sketch here if you are using Arduino CLI:
    https://raw.githubusercontent.com/arduino/arduino-examples/main/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino
  5. Select your "programmer board" from Arduino IDE's Tools > Board menu.
  6. Select the port of your "programmer board" from Arduino IDE's Tools > Port menu.
  7. Select Sketch > Upload from the Arduino IDE menus.
  8. Wait for the upload to finish.

You are now ready to burn the bootloader using your "Arduino as ISP" programmer.

B. Burn Bootloader

Instructions for burning the bootloader:

  1. Select the "target board" from the Tools > Board menu, and any other custom Tools menus (e.g., Tools > Processor).
  2. Select the appropriate programmer from the Tools > Programmer menu in Arduino IDE.
    This is dependent on which board you are using as the "programmer board":
  3. Select Tools > Burn Bootloader from the Arduino IDE menus.
    Or arduino-cli burn-bootloader if using Arduino CLI.
  4. Wait for the process to finish successfully.
  5. Disconnect the USB cable of the "programmer board" from your computer.
  6. Disconnect the "programmer board" from the "target board".

thank you very much for the detailed instructions. A combination of 5 hits on the reset button, waiting one second, then another 2 hits and the sketch uploads!

I have a usbasp I use to program an attiny85. I'll use that with the 3.3v jumper to burn a new bootloader onto the feather.

This result would indicate the bootloader is present after all and point me back towards my original hypothesis of something being wrong with the auto-reset circuit.

I tried this with a usbasp but it gave the error:

Arduino: 1.8.19 (Linux), Board: "Arduino Pro or Pro Mini, ATmega328P (3.3V, 8 MHz)"

Error while burning bootloader.
avrdude: verification error, first mismatch at byte 0x7800
0x00 != 0x0c
avrdude: verification error; content mismatch

and now the board is unusable.

thanks for the information. I hooked it up to an Arduino Uno, followed the excellent instructions in this post, burned a new bootloader and now it's working fine. Everyone's help here is very much appreciated.

You are welcome. I'm glad it is working now. Great job on accomplishing the "burn bootloader" operation with the DIY "Arduino as ISP" programmer!

Regards,
Per

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