Error is coming while uploading code

Arduino: 1.8.18 (Windows 10), Board: "Arduino Uno"

Sketch uses 2622 bytes (8%) of program storage space. Maximum is 32256 bytes.Global variables use 126 bytes (6%) of dynamic memory, leaving 1922 bytes for local variables. Maximum is 2048 bytes.avrdude: ser_open(): can't set com-state for "\.\COM8"An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Have you tried following the suggestion to enable the verbose output in Preference? Please post the output here.

Clearly there is a communication problem with COM8 and there are many reasons for COM port problems including wrong or missing driver, USB cable, wrong board or port selected in the IDE. The verbose output may provide more clues as to the cause.

1 Like

Try:
IDE >> TOOLS >> BOARD >> AVR BOARDS >> Arduino Uno
IDE >> TOOLS >> PORT >> your port

Hi @harsh57. This "can't set com-state for ..." error occurs when uploading to the boards that use specific batches of the WCH CH340 USB chip. The problem only occurs when using the latest version of the CH340 driver.

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 you can follow to do that:

  1. 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
  2. Wait for the download to finish.
  3. Run the downloaded CH341SER.EXE file.
  4. 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.
  5. A "DriverSetup(X64)" dialog will open. Click the "INSTALL" button in the dialog.
  6. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  7. Click the "OK" button in the "Driver install success!" dialog.
  8. Click the X icon at the top right of the "DriverSetup(X64)" dialog to close it.
  9. Close Arduino IDE if it is running.
  10. Connect the Arduino board to your computer with a USB cable.
  11. Open the Windows Device Manager.
  12. Select View > Devices by type from the Device Manager menus.
  13. Open the "View" menu.
  14. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  15. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  16. 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.
  17. Select the "Driver" tab of the "USB-SERIAL CH340 (COMn) Properties" dialog.
  18. You will see a "Roll Back Driver" button in the dialog. If it is not clickable, perform the following instructions:
    1. Click the "Update driver" button.
      An "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog will open.
    2. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
    3. 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.
      :exclamation: 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.
    4. Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COMn)" dialog.
      The dialog will close.
  19. Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COMn) Properties" dialog.
    The "Driver Package rollback" dialog will open.
  20. Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
  21. Click the "Yes" button.
    The "Driver Package rollback" dialog will close.
  22. 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.

1 Like

now it shows this error Arduino: 1.8.18 (Windows 10), Board: "Arduino Uno"

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

OK, this might be progress of sorts. When undertaking complex technical endeavors as we often do in our Arduino projects, it is common to end up in a situation where the system has multiple distinct problems. This means that solving one problem only advances you to encountering the next problem in the stack. That makes it difficult to see that any progress is being made, but with enough perseverance you can solve all the problems and finally reach a fully functional state.

It is possible that you have now solved the problem that caused the "can't set com-state " error, but that only got you to the next problem, which is this "not in sync" error.

In order to allow us to better understand the situation with this new error, I'm going to ask you to post the full verbose output from an upload attempt.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to Show verbose output during: compilation in the "Preferences" dialog.
  3. Check the box next to Show verbose output during: ☐ upload.
  4. Click the "OK" button.
  5. Attempt an upload, as you did before.
  6. Wait for the upload to fail.
  7. You will see a "Upload error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  8. Open a forum reply here by clicking the "Reply" button.
  9. 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.
    Code block icon on toolbar
  10. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the error output from the upload into the code block.
  11. Move the cursor outside of the code block markup before you add any additional text to your reply.
  12. Click the "Reply" button to post the output.
1 Like

after attempting multiple time , i dont know how the code is now uploading but i want to know the reason of this error and sometimes it uploads but sometimes it doesn't

>Arduino: 1.8.18 (Windows 10), Board: "Arduino Uno"

Sketch uses 2622 bytes (8%) of program storage space. Maximum is 32256 bytes.

Global variables use 126 bytes (6%) of dynamic memory, leaving 1922 bytes for local variables. Maximum is 2048 bytes.

C:\Users\Harsh khanna\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Harsh khanna\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -PCOM8 -b115200 -D -Uflash:w:C:\Users\HARSHK~1\AppData\Local\Temp\arduino_build_371562/Blink.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\Harsh khanna\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"



     Using Port                    : COM8

     Using Programmer              : arduino

     Overriding Baud Rate          : 115200

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x89

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x89

avrdude done. Thank you.

Problem uploading to board. See https://support.arduino.cc/hc/en-us/sections/360003198300 for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

See post #3 and post #4 and post your observations.

1 Like

after doing the following steps again the problem has been solved thank you all for helping me @xfpd @ptillisch

@BitSeeker

You are welcome. I'm glad it is working now.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.