Windows 10 com port changes after uploading program

Every time after uploading a program to the Sense board, the com port changes from com5 to com6 or vv. This does not happen for an UNO board, which connects at com4.
I found an older topic here but no usable solution was given.
Especially when using the monitor for messages this is annoying.
The success rate of uploading a program and running it may be as low as 1:4. This is especially annoying since compiling takes a lot more time than for the UNO.

If the upload was successfull and try to open the serial monitor it will never find it, because the comport changed. This will also happen when I leave the monitor open. I have to reselect the comport where the Arduino is currently on in a list that gets longer and longer filled with com5 and com6 items.

After every upload the windows sound of a disconnecting and reconnecting USB device rings. This does not happen for the UNO board.

Does anybody have a solution?

Hello femmeverbeek,

The Nano 33's (all of them I think, but definitely the IoT and BLE) use two different ports.
Whilst I don't know the exact details, you can effectively think of that is as one port is for serial communications and one port is for uploading. If you look at the board when uploading, the yellow/orange light pulsing indicates that the ports have switched. Also if you press the reset button twice, which causes the pulsing light, you will notice in the IDE that the board is detected on its upload port.

This is a bit odd at first but you will get used to it. I think the IDE is starting to get better at handling this as I noticed that my IoT resets to the serial port but my sense does not. Alternately, and as the Sense takes a bit of time to compile, you can use Visual Studio Code with the Platform IO extension to code which allows you to specify which ports you want to upload on, but is a bit more daunting to use at first.

Hope that helps,
Matt

The reason is that the Arduino Nano 33 IoT and BLE handle the USB with the internal USB peripheral while the older boards have a separate USB controller. So, when the controller gets reset the USB connection needs to be restarted, while on older boards the USB chip stays connected to the PC and just waits for serial data to be send via TX and RX line.

The best procedure to ensure download at first trial seems to be:

  • 1.) double tap the reset button to get into bootloader mode (the green LED goes solid and the yellow LED fades on and off and you hear the Windows USB connect sound)
  • 2.) check the COM port which has the (Arduino Nano 33 BLE) after the COM port number
  • 3.) click on the upload (compile) icon

As matt_lee_smith stated there are two virtual COM ports and you need to switch after you download the code.

Matt Lee and Klaus, thanks for your support.
I didn't know the double reset button for starting the bootloader, but it does not seem to help either.

I did a lot of testing, which unfortunately took a lot of time. The problem is still driving me crazy, but my successrate is improving. The results sometimes appear inconsistent, which may be due to the large amount of things you can do different or what can go wrong. Trying to find a pattern, I had to write down all the steps and results. This is a very long list now.

The conclusions so far:
1 Before uploading always check which port the Arduino is connected to, identified by the hardware type showing between brackets
2 Make sure this port is selected, identified by the "V" before the port instance.
3 Do not leave the serial monitor open while uploading a new program!!!!!!!
4 After uploading, you always need to re-select the correct comport before opening the serial monitor!!!!!
5 If you need to see the first (debug) information the program produces,
put the statement while (!Serial); in the sketch code. This causes the program to wait for a serial connection.
6 If the Arduino needs to run stand alone without connection to the PC, be sure that you remove this statement before putting the board into the product.

Leaving the serial monitor open during upload, adds a new comport in the list either 5 or 6, but usuallly not the one the Arduino is connected to. So the list gets longer consisting of an increasing number of com5 and com6 instances. Inconsistent behavior: sometimes a port instance changes identity into the other 5 or 6. In at least one attempt this happened spontaneously doing nothing but with the Arduino already in bootload state. So the double reset before compiling may be counter productive, since it increases the time this can happen.

Pressing the reset button with the serial monitor closed, has no effect on the comports. Doing the same with the monitor open adds a port of the type the Arduino is connected to, it stays selected, but the monitor no longer functions.
Remedy: close and reopen the monitor.

There seems to be a preference for this Arduino to be on COM5. While uploading with the monitor closed, it stays there. But when the Arduino is on COM6, it moves back to COM5 which is not the selected one.

Closing and reopening the IDE clears the list of comports, leaving a single com5 port selected and connected.
In a few rare occasions after successfull upload and already running program, the message "Board COM6 unavailable" appeared in the IDE. Strange since at that moment there was only one deselected COM5 in the list. But no further negative effects.

Opening the monitor clears the screen and the first debug output with it. Finally figured this out (5th conclusion)

I don't think the board uses two com ports or is even capable to. The problem is in the cooperation between Windows and the IDE. Windows considers the monitor as a separate program. After uploading the board resets and tries to reconnect, but Windows does not allow the reconnect since it considers the port still occupied by the monitor. This is the reason why it creates a new COM port.

Am I the only one with this probleM? My request to the developers of the IDE would be to find a solution for this connection problem.

femmeverbeek:
I don't think the board uses two com ports or is even capable to. The problem is in the cooperation between Windows and the IDE. Windows considers the monitor as a separate program. After uploading the board resets and tries to reconnect, but Windows does not allow the reconnect since it considers the port still occupied by the monitor. This is the reason why it creates a new COM port.

The board might only enable one virtual COM port at a time but uses two different endpoint configurations. So, Windows assigns different COM port numbers. This works without the IDE. Just connect your Arduino and switch between bootloader (double tap reset) and normal mode (single tap reset). Then watch the Windows Device Manager COM ports.

The board is capable. You can create your own additional COM ports using the USB CDC class. Two additional COM works fine, three crashes mbedOS.

#include "USBCDC.h"

USBCDC cdc0;
USBCDC cdc1;

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

void loop()
{
  static long previousMillis = 0;
  
  long interval = 10000;
  unsigned long currentMillis = millis();
  if ( currentMillis - previousMillis > interval )
  {
    previousMillis = currentMillis;

    Serial.println( "Hello Serial" );

    char msg0[] = "Hello CDC 0\r\n";
    cdc0.send( ( uint8_t* )msg0, strlen( msg0 ) );

    char msg1[] = "Hello CDC 1\r\n";
    cdc1.send( ( uint8_t* )msg1, strlen( msg1 ) );
  }
}

You can use PuTTY with 3 instances and look at three different serial output windows at the same time. :slight_smile:

femmeverbeek:
Am I the only one with this probleM?

You are not alone. :slight_smile:

Does this somehow solve the changing port problem?

You are not alone.

thx, that helps :slight_smile:

femmeverbeek:
Does this somehow solve the changing port problem?

thx, that helps :slight_smile:

I had the same issue - then I decided to install ATOM & Platform IO IDE + Arduino NAnao BLE package. No headache during installation - very straight forward.. It is fully featured IDE - since I using it I love it.
You can write 'nearly' the same code as for Arduino IDE -compiling time is much shorter, uploading does require re-compilingof whole project, ports are automatically detected.
I use Arduino IDE for test purpose only of small piece of code.

thx for the tip.