Comm Ports Keep Changing

I use a mix of about 10 Arduino Megas and a couple Unos for my home flight simulator. Every time i shut down my PC and turn it back on, the Arduinos have changed their assigned comm port and i have to go back in to every sketch and reassign them to their correct comm port. Sometimes they keep the correct one, but the majority of the time, i have to reassign them. It gets pretty annoying and time consuming when i just want to start the game and play. Is there a reason why the comm ports keep changing or any way i can save the correct port? Thanks!

I am unclear on how the sketch is impacted by your PC changing com ports. Doesn't the sketch simply use Serial?

It matters when you try to upload the sketch again

Yes... back in the day a new com port was assigned for every combination of USB port and device. IOW, if you plug the same device in a different USB port, you get a different COM port. Obviously that is inconvenient. So some manufacturers (e.g. FTDI) supplied drivers that would re-use COM ports, or allow you to give an ID to devices so you get the same COM port every time.

Not sure what the current state of play with USB serial is in Windows 10/11, since COM ports
can now be handled natively. Google says "Windows assigns COM ports based on the device's Vendor ID (VID), Product ID (PID), and serial number. If multiple devices have the same VID, PID, and serial number, they might be assigned the same COM port"

Apparently you can go into device manager and assign a COM port there.

Ah, my mistake. I had thought that the OP's problems were in running the already uploaded sketch, not in uploading a new one. I will be more careful reading in the future.

Actually, I am not sure what problem he/she is describing here

Hey guys, sorry for any confusion. The sketches are already uploaded in to the arduinos. When I start my PC, and I go in to the sketches to verify the COMM Port assignments for the boards are correct, they're usually wrong, and I have to reselect the correct COMM port for the boards. So every time I want to play DCS, and run the arduino programs, I have to open each sketch and assign the correct COMM port. So I would like to not have to open every sketch and assign it's correct COMM Port every time I start my PC and want to play DCS. I hope that makes sense.

Okay thanks. That definitely sounds like the issue, the devices have the same VID, PID and or serial number. I'll try and assign the COM port in device manager, but do you think it will then "Save" the comm port? Or am I just going to have to keep assigning the ports cause of the same VID, PID, serial number?

I am still confused. Where in your sketch are you assigning a comm port? How are you assigning a comm port? All the sketch on the Arduino knows about is Serial. Can you show us a MRE of how a sketch requests the PC to assign a specific comm port to Serial? That seems completely backwards to me, so I must not be understanding what you are saying.

It's quite simple. Windows assigns COM ports when a USB device is plugged in. Sometimes it assigns different COM ports.

If you have an application such as flight simulator, it might be configured so that nav display is on COM6, trim controls are on COM7. If those port numbers change, then you have to reconfigure the flightsim application, which is inconvenient.

This is absolutely nothing to do with particular sketch needing to know the COM port number, or requesting a new one or anything else.

1 Like

That was my understanding as well. Which is why "opening up the sketch and assigning the correct com port" leaves me scratching my head. There's nothing in the sketch that can possibly affect which com port the Arduino is assigned by the PC when it's plugged in.

This. And here's a screen shot of what I was talking about as far as a sketch/arduino needing a COMM port assigned

Unless you're uploading a new sketch to the Arduino, changing the com port in the IDE will have no effect. And it will certainly have no effect on another PC program that needs to connect to that specific Arduino.

If the application on the PC requires a particular COM port to be used to communicate with the Arduino then if the Arduino is allocated a different COM port when it is plugged in then the PC application will not be able to communicate with it

Yes, I understand that.

But setting the com port in the Arduino IDE won't change anything. It's the com port in the other PC program that needs to change.

OK. I am with you now

@kenpilot How exactly do you go about going back into a sketch and reassigning the board to the correct COM port ?

No Arduino have such powers. It's your Operating System that takes care of this.

Google "usb serial port changes". You'll find plenty of answers how to assign a port to a certain USB to serial adapter.

in a project where a number of serial devices may be connected to a Windows or Linux PC (creating COM or dev/ttyUSBx ports) I find the simplest way is to program the target devices to respond to a prompt with a specific text pattern
e.g. this C# code is scanning COM ports for a modem - it transmits "AT" and expects an "OK" response

	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			// scan for COM ports and add to menu item if found
			for(int port = 0; port <= 20; port++)
				{
				serialPort1->PortName = "COM" + port.ToString();
				try
					{
					serialPort1->Open();			// attempt to open serial port
					serialPort1->BaudRate=115200;			
					textBox1->AppendText("Found " + serialPort1->PortName + "\n");
					Console::WriteLine("serial port open OK {0}", serialPort1->PortName);
					serialPort1->Write("AT\r\n"); 
                        Sleep(100);                         
                        String^ response = serialPort1->ReadExisting();                                                
                           Console::WriteLine("response " +  response);
                        if (response->Contains( "OK"))
                        {
                           Console::WriteLine("Fastrack XTEND modem found");
                        }

					serialPort1->Close() ;														//open OK, close it
					ToolStripMenuItem ^item = gcnew ToolStripMenuItem(serialPort1->PortName);	// create a new menu item
					item->Click += gcnew System::EventHandler(this, &Form1::cOMPortsToolStripMenuItem_Click);	// add event handler
					cOMPortsToolStripMenuItem->DropDownItems->Add(item)  ;	// add to the menu of COM ports
 					}
				catch ( Exception ^ex)
					{ Console::WriteLine("serial port open fail {0} ", serialPort1->PortName, ex); }
			}

        Console::WriteLine("COM ports found {0} ", cOMPortsToolStripMenuItem->DropDownItems->Count);
		textBox1->AppendText(String::Format("{0} COM ports found - select from COM ports menu\r\n\r\n", cOMPortsToolStripMenuItem->DropDownItems->Count));
        // if no COM ports were found display message
        if(cOMPortsToolStripMenuItem->DropDownItems->Count == 0 )
           textBox1->AppendText("No COM ports found\r\n");
  		}


if there were several modems attached to the PC one could request the modem model, e.g. transmit "AT+CGMM" and look for "SIMCOM_SIM800L"

1 Like

I'm not sure if kenpilot wrote the PC software himself or not. If not, it might be difficult to implement your suggestion :wink:

You can try to power on the arduinos in a fixed sequence, e.g. using a usb-bub with individual switches.