Three Phase Square Wave - An error occurred while uploading the sketch

Hi there,

I hope you are doing well.

I tried to upload the program from this [Arduino Forum]
(Generation of three phase square wave using arduino(SIMPLE CODING))

I also made sure that I have the drivers for UNO installed from this location:
C:\Program Files (x86)\Arduino\drivers

And also I have the correct port selected from "Tools>Port:"

I tried all three USB Ports and updated the drivers separately for each.

But I encountered the following error messages:

1st Error:
Port: COM7
Error Message: Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"

Sketch uses 1070 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.

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

An error occurred while uploading the sketch

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

2nd Error:
Port: COM8
Error Message: Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"

Sketch uses 1070 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.

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.

3rd Error:
Port: COM6
Error Message: Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"

Sketch uses 1070 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.

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

An error occurred while uploading the sketch

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

I tried uploading the program by opening the .ino file directly, opening the .ino file from the new Arduino window and copying the code.

I get this error every single time.

BUT THE SAME CODE UPLOADED SUCCESSFULLY TO ARDUINO MEGA BOARD.

Would you please help me to figure this out?

Regards,
Haseeb

did you set the board to Uno under Tools->Board ?

Yes dear, I have set UNO in Board Menu

Hi, @m0hammad_haseeb
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Can you please post YOUR code?
Copy from your IDE please.

Thanks.. Tom... :smiley: :+1: :coffee:

Hi;
Have you tried another sketch that you have been able to load to the UNO?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi Tom!

Thanks for your time and reply...

Yes, you can have the code here:

void setup() {
// initialize digital pin 13,12&8 as an output.
pinMode(13, OUTPUT);
pinMode(12,OUTPUT);
pinMode(8,OUTPUT);

}

void loop() {
int var=0;
digitalWrite(13, HIGH);
digitalWrite(8,LOW);
digitalWrite(12,LOW);
delay(6.67);
digitalWrite(12,HIGH);
while(var==0){
delay(3.33);
digitalWrite(13,LOW);
delay(3.33);
digitalWrite(8,HIGH);
delay(3.34);
digitalWrite(12,LOW);
delay(3.33);
digitalWrite(13,HIGH);
delay(3.33);
digitalWrite(8,LOW);
delay(3.34);
digitalWrite(12,HIGH);
}
}

I have posted the ORIGINAL LINK to the code in my Question. You may have missed that, no problem.

I have tried the same code on Mega Board which works well but can't upload on UNO.

Yes dear,

I have tried the pre-installed program from Arduino Software (Blink program). But that also have an error.

Arduino: 1.8.15 (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.

An error occurred while uploading the sketch

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

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

Regards,
Haseeb

What is the label on the chip near the USB port? Common choices are:
ATMEL MEGA16U2 (Official Arduino UNO/MEGA and some better clones)
FTDI FT232RL (Official Arduino Diecimila/Duemilenove/Nano and most older clones)
WCH CH340G (Many newer clones)

Thank you John for replying :relaxed::two_hearts:

Here's the picture of UNO board

Any help on this issue will be highly appreciated :blush:

Thanks :blue_heart:

The maker of your Arduino UNO clone seems to have sanded off the label of the USB-to-Serial chip. It uses a 12 MHz crystal so I think it is likely a WCH CH340G. Try installing drivers for that chip to see if the board then shows up as a serial port.

http://www.wch-ic.com/products/CH340.html

1 Like

Dear John,

My laptop detects the UNO as the port shows up when I plug it in.

And you get the avrdude: ser_open(): can't set com-state for "\.\COM6" error every time you try to upload. This indicates something wrong with your operating system configuration or your serial driver. I had hoped that by installing known good serial drivers you might fix the problem.

Others have successfully fixed this error by using Windows Device Manager to remove the existing driver and let Windows pick a new driver when you plug in the hardware.

1 Like

Thanks for the clarification John !!!

I'll try to update the drivers with the link you provided. :slight_smile:

Thanks, John, It works very well !!! :slight_smile: :hugs: