Recurring problem with detecting Arduino Board

My IDE keeps returning the error "COM 3 not detected". The solution which I have discovered is that I need to uninstall the CH340 driver and install it again. But now I have to do it too often, like every few minutes.

How do I solve it permanently?

If I communicate with the board using my own desktop application instead of the IDE, would I still get this trouble?

Edit : Had mentioned wrong error message above, the correct error message is can't set com-state for ".\COM3"

Try a different cable and board, if that solves it which I think it will swap just the cord and try again. If the problem comes back trash the cord.

I have been facing this problem for a long time. With all my boards and all my chords, but Humpty Dumpty is still not together again.

Hi @thekinginthenorth

Which version of Arduino IDE are you using (e.g., "2.0.1")? The version is shown on the window title bar and also in the Help > About (or Arduino IDE > About Arduino IDE for macOS users) dialog.


Which Arduino board are you using?

Please provide a detailed description of what you are doing when you encounter that error.

Is there additional content in the error output? If so, please provide the full and exact text of the output in a reply here.

This depends on at which layer the problem is occurring.

If the origin of the problem with the port is at the operating system level or lower, then the answer to your question is "yes", as everything at a higher layer will also be affected.

If the origin is in the Arduino IDE application (or its helper tools) or higher, then the answer is "no".

We can get some indication of whether it is occurring at the operating system layer by performing a simple experiment:


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


  1. Wait for the fault to occur.
  2. Open the Windows Device Manager.
  3. Select View > Devices by type from the Device Manager menus.
  4. Open the "View" menu.
  5. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  6. Open the "Ports (COM & LPT)" section of the Device Manager tree.

If you see the port of the board listed in Device Manager, that would indicate that the operating system is able to detect the port as expected.

The problem just returned, so posting the full error message below.

I am using version 1.8.19

Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Lenovo\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Lenovo\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Lenovo\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10819 -build-path C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776 -warnings=none -build-cache C:\Users\Lenovo\AppData\Local\Temp\arduino_cache_230547 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avr-gcc.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -verbose C:\Users\Lenovo\AppData\Local\Temp\untitled1772779686.tmp\sketch_oct26a\sketch_oct26a.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Lenovo\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Lenovo\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Lenovo\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328old -vid-pid=1A86_7523 -ide-version=10819 -build-path C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776 -warnings=none -build-cache C:\Users\Lenovo\AppData\Local\Temp\arduino_cache_230547 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avr-gcc.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -verbose C:\Users\Lenovo\AppData\Local\Temp\untitled1772779686.tmp\sketch_oct26a\sketch_oct26a.ino

Using board 'nano' from platform in folder: C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6

Using core 'arduino' from platform in folder: C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6

Detecting libraries used...

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino" "-IC:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\sketch\sketch_oct26a.ino.cpp" -o nul

Generating function prototypes...

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino" "-IC:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\sketch\sketch_oct26a.ino.cpp" -o "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\preproc\ctags_target_for_gcc_minus_e.cpp"

"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\preproc\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino" "-IC:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\sketch\sketch_oct26a.ino.cpp" -o "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\sketch\sketch_oct26a.ino.cpp.o"

Compiling libraries...

Compiling core...

Using precompiled core: C:\Users\Lenovo\AppData\Local\Temp\arduino_cache_230547\core\core_arduino_avr_nano_cpu_atmega328old_d7b2ab928e552b1ec3d8aa4c19ce459f.a

Linking everything together...

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/sketch_oct26a.ino.elf" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776\sketch\sketch_oct26a.ino.cpp.o" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/..\arduino_cache_230547\core\core_arduino_avr_nano_cpu_atmega328old_d7b2ab928e552b1ec3d8aa4c19ce459f.a" "-LC:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776" -lm

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/sketch_oct26a.ino.elf" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/sketch_oct26a.ino.eep"

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/sketch_oct26a.ino.elf" "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/sketch_oct26a.ino.hex"

"C:\Users\Lenovo\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\Users\Lenovo\AppData\Local\Temp\arduino_build_729776/sketch_oct26a.ino.elf"

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.

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

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

An error occurred while uploading the sketch

Hi @thekinginthenorth. There were some previous reports of this "can't set com-state for ..." error occurring specifically when uploading to the boards that use the WCH CH340 USB chip (and apparently only specific batches of those chips). 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:

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

Thank you, will test it out and let you know if the problem persists.

1 Like

I often get the problem, it occurs when I attach an Arduino clone. I sort it by cycling through the permutations of programmer, old boot loader, unplugging the usb cable, restarting the IDE. Sometimes I set the port to the incoming bluetooth. I faff about like this until the IDE surrenders and populates the COM port. Sometimes I have to restart the computer.
It is associated exclusively with one brand of arduino nanos and does it to all. My other Arduino and ESP 8266 and ESP32s and Raspberry PI CO are acceptable to the IDE.

@ptillisch @fritigern So my problem still persists. I am using Nano clones. Is the problem likely to go away if I use original Nano?

Is the problem likely to go away if I use original Nano?

Yes, it would definitely go away. This problem is specific to the CH340 USB to serial converter chip. The official Arduino Nano board uses a different USB to serial converter chip (FTDI FT232R) that does not suffer from this problem.

1 Like

I was looking for a mega 2560 pro also, but the ones available on net are all with CH340G chips. The arduino store doesn't show any Mega 2560 Pros.

Something to note is that the problem only occurs with specific CH340 chips. Many thousands of people are using CH340-based boards with Arduino IDE on Windows every day without any problems. There seems to be a correlation with the chips that don't have any labeling on them (the chips usually have writing on them like this: CH340).

My guess is that if you buy a CH340-based board from a reputable source (instead of a random seller on online marketplaces like eBay, Aliexpress, Amazon, etc.), then you will get a good CH340 chip and the board will not have this problem.

Something to note is that the product photos on the marketplaces don't always reflect what you are actually receiving. All the sellers of the Chinese boards tend to reuse the same small set of product photos, even in cases where the items they are selling have some small differences. So just because you see the labeling on a chip from a random seller doesn't mean that mean that the board you receive will have a labeled chip. Conversely, the Chinese have an odd practice of photoshopping out the labeling on chips in the product photos so it is common to see no labeling in a product photo and then receive an item that does have labeling on the chips.

2 Likes

got it, thanks

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

Everything said by @ptillisch is spot on. My unreliable nanos do not have any identifying names on them, they're completely anonymous.
F

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