Hi, so... like on the topic I need a solution about uploading a program like this I dunno why this happen cause before on my old laptop I can upload like usually.
Sketch uses 8854 bytes (27%) of program storage space. Maximum is 32256 bytes.
Global variables use 557 bytes (27%) of dynamic memory, leaving 1491 bytes for local variables. Maximum is 2048 bytes.
"C:\Users\myusu\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\myusu\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM5" -b115200 -D "-Uflash:w:C:\Users\myusu\AppData\Local\Temp\arduino\sketches\0897AEDD926878404F62A344C918E9F2/Sensor_Suhu_Non_Contact_Dengan_Indikator_Jarak.ino.hex:i"
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Users\myusu\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can't set com-state for "\\.\COM5"
avrdude done. Thank you.
Failed uploading: uploading error: exit status 1`Teks terformat`
Hi @teaoncup
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.
- Open the Windows Device Manager.
- 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 tried all these steps and am still getting the same error.
To expand upon this, I have three models of Arduino Uno, 1 light blue and 2 darker blue ones (I can't find any difference in make/model numbers), the only discernable difference between the two is that the darker one's cylinders read 47, 35V, VT; and the lighter one's says 100, 35V, VT.
The light blue one successfully accepts all uploads but the darker blue ones show the com-state errors. In the device manager, all 3 are labeled as CH340. two weeks ago, the dark one also accepted all code uploads. Apart from uninstalling the driver, I have tried two versions of IDE software (1.8.14 and 2.1.1), restarting my laptop, pressing the reset button, holding the reset button for 10 seconds, and half a dozen different connectors.
The past programmed codes are still functional in both dark blue Arduino, so there's no issue with that. Please suggest what else I could try.
OK, I have something else you can try:
Some of the affected users have 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.
- Open the Windows Device Manager.
- 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.
- Select "Update driver" from the context menu.
- 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 before. Hopefully this time you will not encounter that "can't set com-state
" error during the sketch upload.
Thank you. It seems to be working now. Would you be able to let me know what the root of the issue was? And whether this process will revert back and need to be repeated each time.
I don't have any special knowledge about the subject. What I know is that around April of this year we started seeing a huge spike in the number of reports here on the forum of uploads failing with this error message.
The common characteristics of these reports:
CH340 Chip
The error occurs for uploads to boards that have a WCH CH340 USB chip.
It seems clear that the triggering event was the release of a new version (3.8.2023.2) of the CH340 driver via a Windows update.
It seems that the problem is not universal because many users (including myself) with boards that have the CH340 USB chip are still able to upload even with the problematic driver version installed. There is some speculation that it is specific to certain batches of chips, perhaps with a dubious provenance (such chips are unfortunately common in the electronics world these days).
AVRDUDE
The error occurs when using the AVRDUDE uploader tool.
However, I wouldn't say this necessarily indicates that a defect or deficiency in the tool is involved. There are two factors to consider:
1) We are identifying the problem by the fairly distinctive error message string "can't set com-state for
". It may be that the same root cause is also causing failing uploads via other tools, but they produce a different error message that we have not associated as being causes by this chip/driver problem.
2) Although the CH340 chip is also found on boards that use other upload tools (most prominently the esptool of the ESP8266 and ESP32 boards), it is by far most commonly found on the AVR boards, all of which use AVRDUDE as their upload tool. Even though the ESP8266 and ESP32 boards are very popular, the use of alternative models of USB chips is more common on those boards.
There is some additional interesting discussion and speculation (but nothing authoritative) here:
I'm not sure. Unfortunately I'm not able to reproduce the error myself so I am operating completely based on the feedback from the affected users.
I can tell you that I have successfully assisted dozens of users with this problem using the technique I shared in my previous reply and I only remember one of them reporting a later reversion. I feel like I would have seen many reports if the fix I provided was only temporary.
However, I did see some other discussions I did not participate in (because they had already been resolved independently before I found them) where people mentioned having to somehow disable the automated Windows updates of the driver.
If you do encounter a reversion, please let us know so the helpers here on the forum can understand the problem better.
I don't know whether this is even relevant, but I should add here that I recommend against ever disabling operating system updates entirely, since these updates often contain important security fixes. I would instead recommend looking for a way to selectively disable automated updates of the driver specifically if you do find that the problem is frequently returning due to the problematic driver version being reinstalled by Windows.
Hey @ptillisch, while updating the driver, I'm getting a message " Windows has successfully updated your drivers".
I've downloaded the ch340 driver from SparkFun.
I'm trying to resolve the same error "avrdude: ser_open(): can't set com-state for "\.\COM5"
Failed uploading: uploading error: exit status 1"
Could you please help me out with this?
this fixed the issue for me as well....seems like the 2023 driver has some issues where the 2014 driver from SparkFun doesn't
Pro Tip: never verify code over CH340 boards don't know what the issue but it'll fail in the middle....you can enable upload verbose though to see the uploading process if want.
you can verify(only if really needed) CH340 boards by uploading code over ISP via a separate external programmer or Arduino as ISP with a working Arduino.
I followed your 2 methods but the problem is still not resolved. I have to unplug and plug it back in many times every time I want to upload.
Hello,
As I feared, the problem does have a lot of reversion. Initially, it only reverted every few hours but now if I try to upload a code into multiple Arduinos, it reverts within minutes. The uploading function continues to work once I redo the steps to roll back the driver again, however, this is a fair bit of work to do multiple times every session.
Please let me know if this issue has a better resolution, 3 months later.
I'm sorry to hear that. I still haven't received a memorable number of reports of this problem so I have the impression Windows is smart enough to understand that if the user does a "roll-back", they want Windows to continue to use that version of the driver rather than just updating it back to the pre-roll-back version immediately.
Even though my CH340 boards work fine even with the new driver, I used the "roll-back" procedure described above to switch to using the old driver a few days ago after someone asked me about the driver being updated. I just checked and the old driver version is still intact. Three days is not exactly conclusive proof that it won't be updated, but it at least doesn't match your experience of having it update within a matter of hours or minutes..
The better resolution is to replace the boards with a sketchy CH340 chip.
If you purchase official Arduino boards you can be certain that you won't experience this problem because Arduino doesn't use CH340 on any of the boards they manufacture. You can purchase official boards from any of these sources:
As I mentioned above, the problem isn't even universal to the CH340 chip. Many of us have CH340 boards that work find with the new driver. So I think that it is safe to buy boards with CH340 chips as long as they are purchased from a reputable source (rather than from a random seller on Amazon/eBay/Aliexpress, even if they do have a good feedback score).
I have seen a couple of other solutions mentioned:
- Disabling all driver updates in the Windows settings
- Installing a 3rd party driver that was produced as a workaround for the problem
However, both of those are somewhat risky from a security perspective so I would not recommend them.
I got the msg has "The best drivers are already installed". now what should i do ?
I have found that when the driver installation gets into this state, it can be solved by uninstalling and then reinstalling the drivers. After that, the "roll back" option should be enabled.
I'll provide 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.
- Open the Windows Device Manager.
- 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 (COMn)" under the "Ports (COM & LPT)" section (where "COMn" is some serial port e.g., COM4). Double click on that item.
The "USB-SERIAL CH340 (COMn) Properties" dialog will open. - Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
- Click the "Uninstall Device" button.
The "Uninstall Device" dialog will open. - Check the box next to "โ Attempt to remove the driver for this device.".
- Click the "Uninstall" button.
The "Uninstall Device" and "USB-SERIAL CH340 (COMn) Properties" dialogs will close. - Disconnect the USB cable of the Arduino board from your computer.
- Reconnect the USB cable of the Arduino board to your computer.
- Wait for the "USB-SERIAL CH340 (COMn)" device to appear under the "Ports (COM & LPT)" section of the Device Manager tree.
This will take a couple of minutes as Windows must first automatically reinstall the driver.
It might appear first as a "USB2.0-Serial" device under the "Other devices section of the tree. Just wait for a little longer and it will appear in its final place under the "Ports (COM & LPT)" section.
- Click the following link to download the previous version of the driver from the chip manufacturer's website:
https://www.wch-ic.com/downloads/file/65.html?time=2023-03-16%2022:57:59 - 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 open. 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.
- Switch back to the Windows "Device Manager".
- Double click on the "USB-SERIAL CH340 (COMn)" device under the "Ports (COM & LPT)" section.
The "USB-SERIAL CH340 (COMn) Properties" dialog will open. - Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
- Click the "Update driver" button.
An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open. - Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" 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.
- Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
The dialog will close. - Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COMn) 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.
The "Driver Package rollback" dialog will close. - Click the "Close" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.
Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error before. Hopefully this time you will not encounter that "can't set com-state
" error during the sketch upload.
Thank you ptilliseh. I was about to give up until I tried your (long) process to fix my "can't set com-state..." problem. Everything else offered did not work for me.
For what it's worth, I've had stable use my Arduino programming for years. Last time I coded was about 3 months ago. Today I started Arduino IDE and I was prompted for the 2.3.2 update. Once that was done, I could not access any of my Nano modules. Windows 11 system.
Anyway, thanks again... I was about to go back to my PIC micro controllers
Gary
You are welcome. I'm glad it is working now.
I think the IDE update was purely coincidental. The "can't set com-state for ...
" error is introduced when Windows updates the driver for the WCH CH340 USB to serial bridge chip, which is completely unrelated to the IDE update.
Regards, Per
I did the same. no improvement. "uploading" shows for output continuously.
Hi @dinuka_83. I'm going to ask you to post the full verbose output from an upload.
This procedure is not intended to solve the problem. The purpose is to gather more information.
Please do this:
- Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open. - Uncheck the box next to Show verbose output during:
โ
compilation in the "Preferences" dialog. - Check the box next to Show verbose output during: โ upload.
- Click the "OK" button.
The "Preferences" dialog will close. - Attempt an upload, as you did before.
- Wait for the upload to hang, as indicated by no new output being printed to the black "Output" panel at the bottom of the Arduino IDE window, or of the output going into a perpetual loop.
- Right click on the black "Output" panel at the bottom of the Arduino IDE window.
A context menu will open. - From the context menu, click Copy All.
- Open a forum reply here by clicking the "Reply" button.
- Click the
<CODE/>
icon on the post composer toolbar.
This will add the forum's code block markup (```
) to your reply to make sure the error messages are correctly formatted.
- Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
This will paste the compilation output into the code block. - Move the cursor outside of the code block markup before you add any additional text to your reply.
- Click the "Reply" button to post the output.
I tried this also. Its not worked. However, I changed the processor (from Tools -->processor) from Atmega328P to Atmega328P(Old Boot loader) , and upload the program again, then it fixed. anyway, thanks for your help.