There were some previous reports of this "can't set com-state for ..." error occurring specifically when using the cheap derivative boards like yours 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.
Hello @hihohi - When my Nanos with CH340 fail to communicate in this manner, it is usually due to my not selecting IDE >> TOOLS >> PROCESSOR >> (old bootloader)
I'm going to ask you to post the full output from the upload when in verbose mode.
NOTE: These instructions will not solve the problem. They are only intended to gather more information which might provide a clue that eventually leads to a solution.
Please do this:
Select File > Preferences... 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.
Attempt an upload, as you did before.
Wait until you are sure the IDE startup has gone into the hang state
(as indicated by no additional output being printed to the "Output" panel at the bottom of the Arduino IDE window).
Right click on the black "Output" panel at the bottom of the Arduino IDE window.
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 Ctrl+V.
This will paste the compilation output into the code block.
Move the cursor outside of the code tags before you add any additional text to your reply.
The Problem was the chip, which is installed on the board seamed to be a Atmega328PB the "B" at the end changed everything. This is why arduioni IDE couldnt establish a connection.
Therefore i tried to install a proper bootloader. This instruction helped me to install a bootloader
At my first try i got a error response, that the signature of the chip on board my china-Nano doesnt match with the expected one.
This Hub provided me finaly with the needed package to support the Atmega328PB. After I istalled this board details into arduino IDE, I was able to istall the bootloader.
I hope this could help other people having the same problem of buying things too cheap
Thanks for taking the time to post an update @hihohi
You might also take a look at the excellent MiniCore as an alternative for adding support for the ATmega328PB to Arduino IDE:
Unlike that amoehl/uino-atmega328pb repository, MiniCore is actively maintained (the last activty in amoehl/uino-atmega328pb was 7 years ago. But if amoehl/uino-atmega328pb is working for you then all is well.
Hi an thank you very much again. I have looked into thats Hub also, cause the other one seems to be outdated as you mentioned.
I uploaded the Bootloader like instructed to the nano using an Uno.
But when i try to upload a simple blink code, i got timeout.
Sketch uses 1232 bytes (3%) 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.
"C:\Users\Sim\AppData\Local\Arduino15\packages\MiniCore\tools\avrdude\7.1-arduino.1/bin/avrdude" "-CC:\Users\Sim\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2/avrdude.conf" -v -V -patmega328pb -carduino -PCOM3 -b115200 -D "-Uflash:w:C:\temp\arduino\sketches\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.hex:i"
avrdude: Version 7.1-arduino.1
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is C:\Users\Sim\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2\avrdude.conf
Using Port : COM3
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 1 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 2 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 3 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 4 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 5 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 6 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 7 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 8 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 9 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 10 of 10: not in sync: resp=0x00
avrdude main() error: unable to open programmer arduino on port COM3
avrdude done. Thank you.
Failed uploading: uploading error: exit status 1
I Think i am using the right setting to compile my code for the PB Version like it is stated in the first row:
FQBN: MiniCore:avr:328:bootloader=uart1,variant=modelPB,BOD=disabled
Using board '328' from platform in folder: C:\Users\Sim\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2
Using core 'MCUdude_corefiles' from platform in folder: C:\Users\Sim\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2
Detecting libraries used...
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-IC:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.2.2\\cores\\MCUdude_corefiles" "-IC:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.2.2\\variants\\pb-variant" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\sketch\\Blink.ino.cpp" -o nul
Generating function prototypes...
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-IC:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.2.2\\cores\\MCUdude_corefiles" "-IC:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.2.2\\variants\\pb-variant" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\sketch\\Blink.ino.cpp" -o "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\builtin\\tools\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++17 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-IC:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.2.2\\cores\\MCUdude_corefiles" "-IC:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.2.2\\variants\\pb-variant" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\sketch\\Blink.ino.cpp" -o "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\sketch\\Blink.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\temp\arduino\cores\d7507696a4a4833a413841b151107294\core.a
Linking everything together...
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -Wl,--gc-sections -mmcu=atmega328pb -o "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.elf" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258\\sketch\\Blink.ino.cpp.o" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/..\\..\\cores\\d7507696a4a4833a413841b151107294\\core.a" "-LC:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258" -lm
"C:\\Users\\Sim\\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:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.elf" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.eep"
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.elf" "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.hex"
cmd /C echo. && "C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objdump" --disassemble --source --line-numbers --demangle --section=.text "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.elf" > "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino_atmega328pb_16000000L.lst"
"C:\\Users\\Sim\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\temp\\arduino\\sketches\\AD5329FA71A3CAD9AAEE127C777BB258/Blink.ino.elf"
Sketch uses 1232 bytes (3%) 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.
In the instruction at github there is also mentioned a second way to upload the code by
Use the option Sketch > Upload Using Programmer, this will erase the bootloader and upload your code using the programmer tool.
This is rsulting in the same error as above:
avrdude: Version 7.1-arduino.1
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is C:\Users\Sim\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.2.2\avrdude.conf
Using Port : COM3
Using Programmer : stk500v1
Overriding Baud Rate : 19200
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 1 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 2 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 3 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 4 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 5 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 6 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 7 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 8 of 10: not in sync: resp=0x00
avrdude stk500_recv() error: programmer is not responding
avrdude stk500_getsync() warning: attempt 9 of 10: not in sync: resp=0x00
So I think i did something wrom by istalling the new bootloader but i cant figure out what.
Do you have any thoughts on that?