Serial port disappears after code upload

I am working with the Nano 33 IOT. I have seen this problem with two different sketches. The one I am attaching is part of a repackaging of the WifiNtpUdpClient example in the WifiNINA library. The example works fine. When it’s downloaded to the Nano33IOT, it usually downloads on one com port and produces the serial output on another.

The problem is that this behavior is not seen with my repackaged version. It downloads and then no serial port is available and the Nano has to be reset in order to download again.

Another, larger program that I won’t post has started to show the same problem. It was working fine, and I started adding “print” statements to it for debugging. And suddenly it started showing the same problem, it would download but not produce a serial port. Even after removing my debug code, it would show the same behavior, after download the serial port was not available. Code size does not seem to be an issue.

Other info, I’m running this on an HP laptop running Windows 10. Resetting the Nano always clears the problem for another download. So what can interfere with the serial port being established?

The code with a portion of the WifiNtpUdpClient code repackaged is attached.

P.S. I thought I posted this two days ago but couldn’t find it. And now that I’ve seen it on another program with no Wifi code, I think it’s more general. If I did post it, please point me to it. since I looked for it.

TestWifiMod.ino (9.78 KB)

I have had similar problems but have not found the solution.

If you open Device Manager and leave it open when you do an upload you will see the Nano change COM ports during the process, then change back to the original. The latter sometimes does not happen, leaving your sketch attempting to communicate with a non existent port.

Various combinations of unplugging the USB port and plugging it back in again and uploading again eventually sorts things out but it is very frustrating and has put me off this board although I have a small project for which it would be ideal.

There is a Nano 33 IOT section of this forum which I will consider moving this thread to but it does not get many views I suspect

I found my problems - I had debug serial port code in my class initialization which occurs before the serial port is available. That seems to hang the code. Some days I feel like an idiot.