Getting Compiled But Not Getting Uploaded...!?

I am trying to comunicate between Arduino And esp32.
this is my aurdino code:

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println("Hello Boss");
  delay(1500);
}

This is my esp32 code

#define RXp2 16
#define TXp2 17
void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXp2, TXp2);
}
void loop() {
    Serial.println("Message Received: ");
    Serial.println(Serial2.readString());
}

my esp32 code gets compiled and even gets uploaded,but my aurdino code gets compiled but while uploading it shows error:

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"

Sketch uses 1632 bytes (5%) of program storage space. Maximum is 32256 bytes.

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

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

An error occurred while uploading the sketch

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

Just for confirming i am using correct ports for both codes....

Welcome to the forum

Which Arduino board are you using ?

Note that most Arduino boards have 5V inputs and outputs and most ESP32 boards have 3.3V inputs and outputs. Have you got voltage shifters between the boards and a common GND connection ?

This is NOT the cause of the uploading problem but must be taken into account

Its Arduino UNO. I dont think its voltage isuue because i have been working with same bord since last year.

As I said

Please turn on verbose output for uploading and post the output here

Hi @kaifu99. Is the ESP32 board connected to pins 0 and 1 of the UNO board?

Yes it is

OK, then that is the cause of the upload failure. The pins on the UNO's primary ATmega328P microcontroller that are connected to pins 0 and 1 on the board are also used for communication with the computer over the USB cable. This means that if you connect anything to pins 0 and 1 on the board, it can interfere with uploads and cause them to fail.

For this reason, it is generally recommended to avoid connecting anything to pins 0 and 1. We would typically use the SoftwareSerial library in the sketch program running on the UNO to create a serial interface on pins other than 0 and 1, and connect those pins to the ESP32.

You can learn about the SoftwareSerial library from the documentation here:

https://docs.arduino.cc/learn/built-in-libraries/software-serial/

Thank you Guys my problem is solved ...
what i did was , while uploading the auduino code i removed all its pins ...and thats it i got uploaded and after successful upload i then connected the pins and now the project works fine...!

You are welcome. I'm glad it is working now.

Regards, Per

Is the Uno Tx pin still driving the 3.3V Rx pin on the ESP32 with 5V ?