"Uploading error: exti status 1" with "avrdude: ser_open(): can't set com-state for "\\.\COM2""

Working on a 4WD for an arduino uno board where it's ifno is:
"BN: Unown board
VID: 0x1A86
PID: 0x7523
SN: (null)

I have tried reinstalling the CH341SER Driver, it did not work.
I have tried changing the COM3 to COM8 and COM1 and COM2. It did not work.
This is the code Im trying to upload. It complies just fine:

#include <AFMotor.h>  //add Adafruit Motor Shield library
#include <Servo.h>    //add Servo Motor library
#include <NewPing.h>  //add Ultrasonic sensor library

#define TRIG_PIN A0                               // Pin A0 on the Motor Drive Shield soldered to the ultrasonic sensor
#define ECHO_PIN A1                               // Pin A1 on the Motor Drive Shield soldered to the ultrasonic sensor
#define MAX_DISTANCE 300                          // sets maximum useable sensor measuring distance to 300cm
#define MAX_SPEED 160                             // sets speed of DC traction motors to 150/250 or about 70% of full speed - to get power drain down.
#define MAX_SPEED_OFFSET 40                       // this sets offset to allow for differences between the two DC traction motors
#define COLL_DIST 30                              // sets distance at which robot stops and reverses to 30cm
#define TURN_DIST COLL_DIST + 20                  // sets distance at which robot veers away from object
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);  // sets up sensor library to use the correct pins to measure distance.

AF_DCMotor leftMotor1(1, MOTOR12_1KHZ);   // create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency
AF_DCMotor leftMotor2(2, MOTOR12_1KHZ);   // create motor #2, using M2 output, set to 1kHz PWM frequency
AF_DCMotor rightMotor1(3, MOTOR34_1KHZ);  // create motor #3, using M3 output, set to 1kHz PWM frequency
AF_DCMotor rightMotor2(4, MOTOR34_1KHZ);  // create motor #4, using M4 output, set to 1kHz PWM frequency
Servo myservo;                            // create servo object to control a servo

int leftDistance, rightDistance;  //distances on either side
int curDist = 0;
String motorSet = "";
int speedSet = 0;

//-------------------------------------------- SETUP LOOP ----------------------------------------------------------------------------
void setup() {
  myservo.attach(10);  // attaches the servo on pin 10 (SERVO_1 on the Motor Drive Shield to the servo object
  myservo.write(90);   // tells the servo to position at 90-degrees ie. facing forward.
  delay(1000);         // delay for one seconds
}
//------------------------------------------------------------------------------------------------------------------------------------

//---------------------------------------------MAIN LOOP ------------------------------------------------------------------------------
void loop() {
  myservo.write(90);  // move eyes forward
  delay(90);
  curDist = readPing();                       // read distance
  if (curDist < COLL_DIST) { changePath(); }  // if forward is blocked change direction
  moveForward();                              // move forward
  delay(500);
}
//-------------------------------------------------------------------------------------------------------------------------------------

void changePath() {
  moveStop();         // stop forward movement
  myservo.write(36);  // check distance to the right
  delay(500);
  rightDistance = readPing();  //set right distance
  delay(500);
  myservo.write(144);  // check distace to the left
  delay(700);
  leftDistance = readPing();  //set left distance
  delay(500);
  myservo.write(90);  //return to center
  delay(100);
  compareDistance();
}


void compareDistance()  // find the longest distance
{
  if (leftDistance > rightDistance)  //if left is less obstructed
  {
    turnLeft();
  } else if (rightDistance > leftDistance)  //if right is less obstructed
  {
    turnRight();
  } else  //if they are equally obstructed
  {
    turnAround();
  }
}


//-------------------------------------------------------------------------------------------------------------------------------------

int readPing() {  // read the ultrasonic sensor distance
  delay(70);
  unsigned int uS = sonar.ping();
  int cm = uS / US_ROUNDTRIP_CM;
  return cm;
}
//-------------------------------------------------------------------------------------------------------------------------------------
void moveStop() {
  leftMotor1.run(RELEASE);
  leftMotor2.run(RELEASE);
  rightMotor1.run(RELEASE);
  rightMotor2.run(RELEASE);
}  // stop the motors.
//-------------------------------------------------------------------------------------------------------------------------------------
void moveForward() {
  motorSet = "FORWARD";
  leftMotor1.run(FORWARD);                                 // turn it on going forward
  leftMotor2.run(FORWARD);                                 // turn it on going forward
  rightMotor1.run(FORWARD);                                // turn it on going forward
  rightMotor2.run(FORWARD);                                // turn it on going forward
  for (speedSet = 0; speedSet < MAX_SPEED; speedSet += 2)  // slowly bring the speed up to avoid loading down the batteries too quickly
  {
    leftMotor1.setSpeed(speedSet);
    leftMotor2.setSpeed(speedSet);
    rightMotor1.setSpeed(speedSet);
    rightMotor2.setSpeed(speedSet);
    delay(5);
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------
void moveBackward() {
  motorSet = "BACKWARD";
  leftMotor1.run(BACKWARD);                                // turn it on going backward
  leftMotor2.run(BACKWARD);                                // turn it on going backward
  rightMotor1.run(BACKWARD);                               // turn it on going backward
  rightMotor2.run(BACKWARD);                               // turn it on going backward
  for (speedSet = 0; speedSet < MAX_SPEED; speedSet += 2)  // slowly bring the speed up to avoid loading down the batteries too quickly
  {
    leftMotor1.setSpeed(speedSet);
    leftMotor2.setSpeed(speedSet);
    rightMotor1.setSpeed(speedSet);
    rightMotor2.setSpeed(speedSet);
    delay(5);
  }
}
//-------------------------------------------------------------------------------------------------------------------------------------
void turnRight() {
  motorSet = "RIGHT";
  leftMotor1.run(FORWARD);    // turn motor 1 forward
  leftMotor2.run(FORWARD);    // turn motor 2 forward
  rightMotor1.run(BACKWARD);  // turn motor 3 backward
  rightMotor2.run(BACKWARD);  // turn motor 4 backward
  rightMotor1.setSpeed(speedSet + MAX_SPEED_OFFSET);
  rightMotor2.setSpeed(speedSet + MAX_SPEED_OFFSET);
  delay(1500);  // run motors this way for 1500
  motorSet = "FORWARD";
  leftMotor1.run(FORWARD);  // set both motors back to forward
  leftMotor2.run(FORWARD);
  rightMotor1.run(FORWARD);
  rightMotor2.run(FORWARD);
}
//-------------------------------------------------------------------------------------------------------------------------------------
void turnLeft() {
  motorSet = "LEFT";
  leftMotor1.run(BACKWARD);  // turn motor 1 backward
  leftMotor2.run(BACKWARD);  // turn motor 2 backward
  leftMotor1.setSpeed(speedSet + MAX_SPEED_OFFSET);
  leftMotor2.setSpeed(speedSet + MAX_SPEED_OFFSET);
  rightMotor1.run(FORWARD);  // turn motor 3 forward
  rightMotor2.run(FORWARD);  // turn motor 4 forward
  delay(1500);               // run motors this way for 1500
  motorSet = "FORWARD";
  leftMotor1.run(FORWARD);   // turn it on going forward
  leftMotor2.run(FORWARD);   // turn it on going forward
  rightMotor1.run(FORWARD);  // turn it on going forward
  rightMotor2.run(FORWARD);  // turn it on going forward
}
//-------------------------------------------------------------------------------------------------------------------------------------
void turnAround() {
  motorSet = "RIGHT";
  leftMotor1.run(FORWARD);    // turn motor 1 forward
  leftMotor2.run(FORWARD);    // turn motor 2 forward
  rightMotor1.run(BACKWARD);  // turn motor 3 backward
  rightMotor2.run(BACKWARD);  // turn motor 4 backward
  rightMotor1.setSpeed(speedSet + MAX_SPEED_OFFSET);
  rightMotor2.setSpeed(speedSet + MAX_SPEED_OFFSET);
  delay(1700);  // run motors this way for 1700
  motorSet = "FORWARD";
  leftMotor1.run(FORWARD);  // set both motors back to forward
  leftMotor2.run(FORWARD);
  rightMotor1.run(FORWARD);
  rightMotor2.run(FORWARD);
}

Is there anybody out there?

I moved your topic to an appropriate forum category @elektrerik.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hi @elektrerik. 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:

  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 appear. 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.

It's considered very impolite to kick a topic within 24 hours. Give it time to go around the world, those that might have the answer might be sleeping.

I would kiss you if I could. I was able to upload it once, but when i try to reupload, it gives me a different error. Still exit status 1, but now with this:
"
avrdude: reading on-chip flash data:

Reading | ##############avrdude: stk500_recv(): programmer is not responding
#avrdude: stk500_recv(): programmer is not responding
avr_read(): error reading address 0x0000
read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_recv(): programmer is not responding

avrdude done. Thank you.

Failed uploading: uploading error: exit status 1
"

Thank you for your time and help!

I think this is progress at least. 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 if you can manage to solve all the problems in turn you will finally reach the point where the system is fully functional.


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.