Can't upload new sketch due to the existing sketch

I'm trying to upload a new sketch but am unable due to the existing sketch on both of my boards. I was previously testing communication between Arduinos using serial communication, and apparently the delay before they start trying to communicate is too short and so new sketches can't be uploaded via USB before the previous sketch starts spamming over the serial port. I've tried uploading a blank sketch hoping it would be as short of an upload time as possible, but the communication lights start flashing (indicating the previous sketch has started spamming) before the upload completes, and then the upload progress bar just gets stuck.

I have both an Arduino Uno and Arduino Nano, and they both have the same issue. Is there any way to "factory reset" these boards without code? The only suggestion I've seen is to upload a blank sketch, but that doesn't work since I can't upload it.

All I can say is, the described phenomenon does not occur with any of my Nano, Uno, Mega2560, or Every products, be they clone or genuine. I have a strong suspicion you have something more going on.

If you have anything wired to your devices, first remove anything wired to RX and TX, pins 0 and 1, and test again.

I've removed those connections so nothing is connected except for the USB cable to the computer but unfortunately I still get the same problem.

Your sketch stops at the moment that avrdude opens the serial port and asserts DTR to start the upload. That will reset your board and the bootloader is activated and your sketch is not running at that moment. So your scenario is highly unusual.

The bootloader will be active for a few seconds if no data is transferred or will stay active during the upload.

Burn the bootloader. You will need a programmer or an other Arduino that is programmed with a programmer sketch.

In the Arduino IDE, I selected Tools -> Programmer -> Arduino as ISP, then Burn Bootloader, but it also gets stuck. The existing sketch starts communicating around one second after it gets reset which seems to be before the process completes.

It looks like I could use SPI to burn the bootloader as well according to this page: https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP/#:~:text=of%20the%20target.-,How%20to%20wire%20your%20boards,-The%20following%20table.

I'm not familiar with SPI but I assume that this would circumvent the issue with using serial communication? With the caveat that I'd need another (functional) board like you said?

No "as well". You need an ISP to burn the bootloader. Another Uno or Nano set up as described in the link you included is the ticket.

Having said that, I direct your attention to the following link that requires less hardware, but a bit of good timing.

But I'm with @camsysca; I think there's something else going on that you haven't mentioned. Loading this sketch

void setup() {
   Serial.begin(115200);
}

void loop() {
   Serial.println("Spam spam wonderful spam!");
}

which spams the serial port mercilessly, does not prevent uploading another sketch on an Uno.

2 Likes

You all were right in that the issue involved the bootloader, and that my guess for what the problem was is incorrect. It turns out that in the Arduino IDE I needed to choose Tools -> Processor -> "ATmega328P (Old Bootloader)" instead of "ATmega328P", and then I was able upload a new sketch successfully.

Thanks for the help!

1 Like