Can't upload on Arduino Nano

I am trying to upload this code on an arduino nano for an acoustic levitator, but every time I try to upload the code, I get this error message.

  Using Port                    : COM6
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200

avrdude: ser_open(): can't set com-state for "\.\COM6"

avrdude done. Thank you.

Failed uploading: uploading error: exit status 1

I am using the latest IDE update for windows 11. Please help!

Hi, you could try checking your drivers on the IDE to make sure they are correctly installed. Go to the device manager and COM port settings and make sure the arduino nano is connected to the right port.

Hi @moonymon10. 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.
    The dialog will close.
  8. Click the X icon at the top right of the "DriverSetup(X64)" dialog
    The dialog will close.
  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

I tried COM5 first and it worked, but now it's taking forever to upload, so I don't know if it fully works. When I realized how long it was taking and tried COM6, it said the best drivers had already been installed.

Edit: it has been about 20 minutes and it is still uploading! Is this normal?

It is probably a completely unrelated problem.

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.
    The "Preferences" dialog will close.
  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.

There is no error to send, It just won't stop uploading. It stays uploading for a very long time and so far hasn't stopped.

The Nano series consists of many boards with different processors, and there are clones from other manufacturers. So: triple check that the board you selected in the IDE is indeed the board you have.

OK, thanks for the clarification. Please try this:


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


Please do this:

  1. Select File > Quit from the Arduino IDE menus.
    All Arduino IDE windows will close.
  2. Start Arduino IDE.
  3. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  4. Uncheck the box next to Show verbose output during: compilation in the "Preferences" dialog.
  5. Check the box next to Show verbose output during: ☐ upload.
  6. Click the "OK" button.
    The "Preferences" dialog will close.
  7. Attempt an upload, as you did before.
  8. Wait for until you are sure the upload has hung, as indicated either by no new text being printed to the "Output" panel for some time, or else by the same text content being printed repeatedly.
  9. Right click on the black "Output" panel at the bottom of the Arduino IDE window.
    A context menu will open.
  10. From the context menu, click Copy All.
  11. Open a forum reply here by clicking the "Reply" button.
  12. 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
  13. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the upload output into the code block.
  14. Move the cursor outside of the code block markup before you add any additional text to your reply.
  15. Click the "Reply" button to post the output.
Sketch uses 3110 bytes (10%) of program storage space. Maximum is 30720 bytes.
Global variables use 761 bytes (37%) of dynamic memory, leaving 1287 bytes for local variables. Maximum is 2048 bytes.
"C:\Users\****\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\****\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\****\AppData\Local\Temp\arduino\sketches\2C83D51750AB581387D4C4484AB31D88/FJ1MSSNJ66Q8UBZ.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\****\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: stk500_getsync() attempt 1 of 10: not in sync: resp=0x34
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x32
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x35
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x0d
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x0a
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x34
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x32
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x32
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x0d
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x0a

A program called a "bootloader" is stored in a special area of memory in the Nano board's microcontroller. The classic Nano (as well as its 3rd party derivatives) have been manufactured with two different types of bootloader installed.

You must configure the Tools > Processor menu in Arduino IDE according to which bootloader is installed on your Nano. Having the incorrect configuration selected in this menu is one of the potential causes of uploads failing with the "avrdude: stk500_recv(): programmer is not responding" error.

I can see from the upload output that you have Arduino IDE configured for use with the Nano boards that have the "new" bootloader. Although this bootloader has been in use in the official Nano boards for the last six years, the manufacturers of the low quality Chinese Nano derivative boards like the one you have are still using the inferior "old" bootloader.

Select Tools > Processor > ATmega328P (Old Bootloader) from the Arduino IDE menus and then try uploading again.

Hopefully this time the upload will finish successfully.

IT WORKED!!!!

Thank you so much! I've had this problem in the past as well, and had a month delay in a project due to this error! You are a lifesaver! Thank you

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.