USB COM port keeps changing

I am fairly new to Arduino so there may be a simple answer to this.

I am connecting a Nano 33 BLE to a PC via USB for build / upload / debug etc, and it shows up on COM7.

However, frequently when I do a compile and upload, at the end of the upload, the COM port switches to COM8 all on its own. The serial monitor then won't work.

It is a simple enough matter to change it back to COM7 (the COM port selection recognises that is where the Arduino is), but it is irritating as it keeps happening (not all the time). There is a COM8 with a USB driver on it that gets used for something else (not currently plugged in), and presumably the IDE is getting confused.

Is there any way to say in the IDE setup "use COM7 and don't change it"?

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

You will also notice that two com ports is standard for some boards.

The Arduino Nano 33 BLE and IoT use native USB. That means the USB stack runs on the same processor. To write a new sketch the device needs to switch to bootloader mode and when it is done the device needs to switch back. In both cases the device will reset and therefore loose the USB connection. The two modes have different USB endpoint configuration which Windows detects and therefore assign a different COM port.

On older Arduinos there is a separate chip that can stay connected the whole time. This has the advantage that the COM ports never changes. On the other hand, native USB is faster and allows some additional applications e.g., USB keyboard and mouse.

The IDE can handle the switch most of the time automatically. I try to confirm the port is set before I upload a new sketch. Sometimes I forget and must click upload a second time.

1 Like

Thanks, I realise that. Not clear however why it makes the wrong decision when COM8 does not show up in the available port list.

You just need to be patient. Close the Serial Monitor before you upload a new sketch and check the COM port setting. Once upload is done check the port again and open the Serial Monitor if you need it. If you stick with the procedure, you will be fine most of the time.

I am sure this is not easy to program in the IDE. There are many uncertainties, Windows is not real-time, the hardware is different from one PC to another, different drivers, and the Arduino is connecting and disconnecting the USB port.

Yes, thanks, I do all that as a workround.

However it does not alter the fact that the IDE appears to get confused over ports, other applications that connect in similar ways - also running on the same Windows system - don't, so I am forced to the conclusion that there is a bug / implementation issue in the IDE.

My question really therefore is whether this is a known issue with a known fix / workround - apart from the above.

After programming my 33 BLE with the Arduino IDE i've have changed from Arduino IDE to Atmel Studio and programm with the Arduino plugin.
Since i've change i haven't the port-problem again.
It could work for you :wink:

And: I like Atmel Studio much more :smiley:

Thanks, interesting. Didn't know there was that alternative.

I've been having this problem ever since I got my 33BLE and it has always been aggravating. My uploads now fail occasionally even when the correct port is selected before compiling. After compilation the ide will print
"PORTS {COM3, COM4, } / {COM3, COM4, } => {}" and checking TOOLS>PORT will have "COM4(Arduino Nano 33 BLE)" checked during compile until upload is started, then switches to com3 and fails. Selecting Com3 before compilation is started still results in failure.
I'm sick of playing USB PORT WAK-A-MOLE. I'm sorry to all who disagree, but, this IS either a bug, IDE programming issues, or poor 33BLE design. I'm not a perfect syntax programmer and will have to recompile, reload, run to see results. Having to WAK-A-MOLE the correct port every other time if not everytime breaks your train of thought and delays getting results. I love programming and enjoy chasing bugs and achieving desired results, but this constant round robin port selection takes all the fun out of it.

I have found better success if you don't rely on the ide to select the correct port under all circumstances. Double press the reset button to go into programing mode and then select the programming port before uploading.

No Not a bug at all.
Many of the Arduino boards have the second port.
Often referred to as the BOOTLOADER..

Often turns out to be a good thing too when many users have uploaded and errant sketch which seems to make some boards appear to be bricked.
As Cattledog says just double tapping the reset will almost always bring those boards back to life and offer the user a second chance.

So let me understand, this port changing IS as by design? EVERYTIME I want to reload I have to reset ble, select port, and then reload. There is NO way this could be alleviated with software? Even though SOMETIMES it is not necessary?

MOST of the time it is not needed.
It does however provide an escape method for many users who have run into issues.

Yes it is a design element. As stated it is available on a lot of Arduino boards even down to the Leonardo.

There is however a bug in the windows operating system that can cause "creeping com port" issues for users of multiple boards at once.
That scenario is actually quite rare though but still worth noting.

So other programming UI's do this too? Like the atmel mentioned earlier? And if you don't have this dual port roulette in the UI you can brick your chip?

It is not a matter of you bricking the board.
An errant sketch is possible which may "appear" to lock the board.
And yes other IDE's not part of Arduino also do this when needed.

Simply google bootloader and a board of your choice.
There should be plenty of alternate mcu's have it too.
Some deliberately seperate the two and may have a BOOT SELECT switch or port.

The Arduino IDE is supposed to transparently manage the port selection and switching between the programming and communication port you use with the monitor and a running sketch. In my experience it is not perfect.

I'm not certain if one of the earlier posters indeed claimed that Atmel Studio is better at handling the two ports than the Arduino IDE.

No, it isn't perfect. I started this thread quite some time ago.

It definitely is not right from a UI perspective. I been living with manual resets of the port at odd intervals ever since. I don't often need to make changes, which is why I haven't bothered to try to find a real answer. A real answer probably being a different IDE.

I did see somewhere a suggestion that PlatformIO, presumably with Visual Studio Code, can be used. Since I use VSC for other things anyway, when it gets to a sufficient level of irritation, I probably need to explore that option.

Update:

I've now had a quick look at Visual Studio Code as the IDE. I tried it out on a PC that had never had VSC, Arduino IDE, or anything like that installed before. Used a YouTube video as a guide.

Installed VSC, then plugins for PlatformIO, C/C++ Intellisense. Created a new project for an Arduino Nano and made it blink the LED - very basic. It all worked excellently, auto-detected the right COM port, compiled, uploaded and worked.

Initial project creation was slow as it downloaded all the libraries, but after that it seemed pretty fast. It was a very simple test, of course, but it looks like a good start. VSC is a much more sophisticated platform than the Arduino IDE in terms of what it offers. Intellisense worked well, and it looks like there is a working debugger too, though I didn't try it. Contrary to what I have read, it did not appear to need the Arduino IDE separately installed - it downloaded all the necessary Arduino libraries itself.

This was only a very simple test, and it is down to what one wants, I guess. The Arduino IDE is a good 'get you going' platform, and simple to use, especially if you are new to software development. But VSC is a very powerful platform if you want something that has more tools.

I use VSC for Unity game development (C#) and Marlin 3D printer code builds (C) already, and I'm a long time professional software designer anyway, so I'm fine with complex tools. This may not be for everyone, but for me it looked like a good start. I may come across some show stopping gotcha at some point, but for now it's a good beginning and is looking hopeful.

Does VSC handle the usb ports better on dual channel usb mcu's? My application is as a remote weather station so I would like to be able to make edits remotely. Having to physically reset is not an option, and having to recompile up to three times is time and resource inefficient.

There are lots of IDE's out there that are more advanced than the current offering from Arduino.
But let us not forget that Arduino's offering is generally meant for the masses and not for those that have outgrown it.

Many of the more advanced users move to different IDE's to overcome some of the shortfalls of the current IDE. Myself as more of a tester/noob find the current IDE fine for my uses.
Yes there are quirks and yes some of those quirks can be annoying but I understand the target audience and accept them.

I did try a couple of alternate IDE's at various points in time but often found the hoops I had to jump through to get a simple project working were often too complex. Exactly as you have described by installing this then that then the other and sometimes slow compile times.
Yes there are occasions where the code may be slightly smaller and more efficient but the cost in complexity is not always worth it.