I must first apologise for my lack of knowledge, I have started attempting to learn the basics of Arduino today. When following the set-up process demonstated on https://realpython.com/arduino-python/, I have been unable to upload the file resulting in the following error message:
avrdude: ser_open(): can't set com-state for "\.\COM3" Failed uploading: uploading error: exit status 1
Would anybody be able to explain how I might fix this or where I may look for a solution?
I do not believe that the PC creates a new COM port.
COM3 has been selected in the IDE.
Nothing else is connected to the PC via any port, including COM3.
When unplugged, no ports are able to be selected. COM3 is only available when the Arduino is plugged in (no others are available). Does this mean that it is creating a COM port? I am unfortunately unfamiliar with how the IDE is supposed to look.
My PC is running the latest version of Windows 11.
There were some previous reports of this "can't set com-state for ..." error occurring specifically when using boards that have the CH340 USB chip. It seems that a driver upgrade included in a recent Windows update is the cause of this problem.
The affected users have found that uninstalling and reinstalling the CH340 device fixed the problem. I'll share the instructions you can follow to do that:
Close Arduino IDE if it is running.
Connect the Arduino board to your computer with a USB cable.
Select View > Devices by type from the menus in the Device Manager window.
Open the "View" menu in Device Manager.
If there is a ✓ to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
Open the "Ports (COM & LPT)" section of the Device Manager tree.
You should see a port identified as "USB-SERIAL CH340 (COM_n_)" under the "Ports (COM & LPT)" section (where "COM_n_" is some serial port e.g., COM4). Right click on that item.
A context menu will open.
Select "Uninstall device" from the context menu.
An "Uninstall Device" dialog will open.
Check the box next to "☐ Attempt to remove the driver for this device" in the "Uninstall Device" dialog.
Click the "Uninstall" button.
Wait for the uninstallation process to finish.
Unplug the USB cable of the Arduino board from your computer.
Wait for the Device Manager tree to reload.
Connect the USB cable of the Arduino board to your computer.
Wait for the "USB-SERIAL CH340 (COM_n_)" port to reappear under the "Ports (COM & LPT)" section of the Device Manager tree.
Select File > Exit from the Device Manager menus.
My experience is that the device will be reinstalled automatically by Windows after you plug the board back into the computer, as indicated by the "USB-SERIAL CH340 (COM_n_)" port reappearing in the last step of those instructions. However, it is maybe possible that the complete driver removal will actually have been accomplished by the above instructions, in which case it would be necessary to reinstall the driver. If this happens to you, please let me know and I'll provide instructions you can follow to install the driver.
Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error. Please reply here to let us know whether the error still occurs.
I have followed these intructions; unfortunately the error persists as described in the initial post. I appreciate the advice that you have given me, nonetheless.
I'm sorry to hear that. Some of the users who experienced these errors reported that doing a "roll back" to an older version of the driver was an effective workaround. You can give that a try.
I'll provide instructions:
Open this tutorial from SparkFun in your browser: https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all#drivers-if-you-need-them ⓘ We are using this tutorial as a source for an older version of the CH340 drivers. Generally I recommend only obtaining drivers from the manufacturer of the device, but WCH does not provide older versions of their drivers and SparkFun is trustworthy.
Click the "Windows (EXE)" link you see in red under the "Drivers (If You Need Them)" section of the tutorial.
Wait for the download to finish.
Run the downloaded CH341SER.EXE file.
A "User Account Control" dialog may now appear asking "Do you want to allow this app to make changes to your device?". Click the "Yes" button.
A "DriverSetup(X64)" dialog will appear. Click the "INSTALL" button in the dialog.
Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
Click the "OK" button in the "Driver install success!" dialog.
Click the X icon at the top right of the "DriverSetup(X64)" dialog to close it.
Close Arduino IDE if it is running.
Connect the Arduino board to your computer with a USB cable.
Select View > Devices by type from the Device Manager menus.
Open the "View" menu.
If there is a ✓ to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
Open the "Ports (COM & LPT)" section of the Device Manager tree.
You should see a port identified as "USB-SERIAL CH340 (COM_n_)" under the "Ports (COM & LPT)" section (where "COM_n_" is some serial port e.g., COM4). Right click on that item.
A context menu will open.
Select the "Drivers" tab of the "USB-SERIAL CH340 (COM_n_) Properties" dialog.
You will see a "Roll Back Driver" button in the dialog. If it is not clickable, perform the following instructions:
Select "Update driver" from the context menu.
An "Update Drivers Device - USB-SERIAL CH340 (COM_n_)" dialog will open.
Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COM_n_)" dialog.
You should now see the driver installation wizard update the driver. Wait for the update to finish, as indicated by the message "Windows has successfully updated your drivers" in the dialog. It is possible you will instead see the message "The best drivers are already installed". If so, please stop following the instructions here and reply on the forum thread to let me know. I'll provide alternative instructions you can follow.
Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COM_n_)" dialog.
Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COM_n_) Properties" dialog.
The "Driver Package rollback" dialog will open.
Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
Click the "Yes" button.
Click the "Close" button in the "USB-SERIAL CH340 (COM_n_) Properties" dialog.
Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error. Please reply here to let us know whether the error still occurs.