Serial monitor connection breaks on each upload

I just got the new Nano ESP32 board, and I'm generally impressed. My old code (with at least 6 external libraries) compiles without changes except for the watchdog timer. I have plans to make good use of the increased memory, smaller size, and WiFi.

Unfortunately, there is an issue I never had with the Arduino Mega. When I first upload a sketch and turn on the the Serial Monitor, it works fine. Then every time I recompile and upload the serial monitor connection is broken. It displays "Arduino Nano ESP32 on 1-10" in the bottom right of the window, there before it had ... on COM4. I can manually re-select the COM port from the tools window but that often doesn't solve the problem. Sometimes it reconnects, but more often I have to physically unplug the USB cable and plug it back in.

It seems that the system is switching to DFU ports for the upload and not switching back to COM correctly, but I know almost nothing about DFU, so this is just a guess.

This is bad enough during development and debugging, but it is going to be a big problem when I hand this off to users who expect to see data on the monitor. They will be confused if it is unreliable.

Test code:

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

int i = 0;
void loop() {
  Serial.print("This is "); Serial.println(i++);
  delay(4000);
}

IDE: Arduino 2.1.1 on Windows 11
Board: Arduino Nano ESP32

Other combinations I have tried:

  • Hitting the reset button on the board does NOT break the connection. The count resumes from 1 as expected.
  • Hitting the reset button when the serial monitor is not working does not fix the connection.
  • IDE 1.8.x with Nano ESP32 shows the same broken-connection behavior, but with fewer messages.
  • Arduino Mega on IDE 1.8.x looks perfect
  • Arduino Mega on IDE 2.1.1 shows a few bad characters (square blocks) at the time of the new upload, but then resumes correctly with no lost data.

There are topics on the forum which look similar, but they all turn out to be slightly different. Either they are about the command line interface, or the suggested solutions require Tools-menu items I don't have or multiple buttons on the device, which the Nano ESP32 doesn't have.

Hey Steve,

My ESP32 is having the same problem, if its any consolation. Did you happen to get a solution in the meantime?

1 Like

I have not seen a fix, but this helps keep things working:

  • In setup() insert delay(15000) after Serial.begin(). You lose 15 seconds of your life each time you load the program, but I have found no better way.
  • Before or during each compilation close the serial monitor.
  • Several seconds after the upload is done and after any beeping and light-flashing related to the USB connection, use the dropdown near the top of the window and select your board with its COM port, if the "1-10" version has been selected instead.
  • Re-open the serial monitor
  • If you do this within the 15-second delay you won't miss any output

This doesn't work every time, but it mostly does. Of course being happy with code that "usually works" is a good way to get fired from a software engineering job.

Hi @VeloSteve and @sameekshaagrawal

We are aware of this bug in Arduino IDE and there is work in progress on a fix:

If you have a GitHub account, you can subscribe to that issue to get notifications of any new developments related to this subject.

2 Likes

I updated to IDE 2.2.1 today (I was on other things for a while). The problem seems to be gone, and I can load a new sketch without losing the serial monitor. The 15000 ms workaround is no longer needed.

Thanks!

1 Like

You are welcome. I'm glad it is working now. Thanks for taking the time to post an update!

Regards,
Per

I have IDE 2.2.1 and the problem persists.
As soon as Done! is shown in the output, the COM port is killed.
I hit the reset button a lot and the COM port comes back with an additional connection below it saying:
Arduino nano ESP32
2-2
Note that adding delay(15000); does not help because the COM drops as soon as the upload is done.

Happens on both win11 and win10 machines.
On win10 I can see the COM port cycling on and off.
This problem appears to be coming from the Arduino nano ESP32.

I bought 4 boards, and now the second board is showing the same behavior.
They work correctly for a day, but on the second day this error pops up.
I'm not doing anything different between day 1 and day 2.

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