Getting Timeout error when uploading a program to Arduino Mega when XBee Shield plugged in

I bought XBee 3 wireless kit from Sparkfun, I’m getting timeout error when uploading a program to Arduino Mega 2560 when XBee Shield plugged in the Arduino, but XBee module is not plugged on the shield. Below is the error from Arduino IDE console, what is the issue with the shield?

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_getsync(): timeout communicating with programmer

Please provide more details about your set-up - photos are very helpful!

So far it could be an incorrect ‘board selection’ in IDE, cable/wiring issue, power issue, etc…

Are you saying that you get an error ONLY when using the XBee shield, and no error without?

Make sure the switch is in the “DLINE” position when uploading sketches.

If the Shield is unplugged in, program upload successes. The board, processor and port are all correct

The board info:

BN: Arduino Mega or Mega 2560

VID: 2341

PID: 0042

SN: 558383230363517192B1

Error:

Sketch uses 2914 bytes (1%) of program storage space. Maximum is 253952 bytes.

Global variables use 246 bytes (3%) of dynamic memory, leaving 7946 bytes for local variables. Maximum is 8192 bytes.

C:\Users\xxxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\xxxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM8 -b115200 -D -Uflash:w:C:\Users\xxxx\AppData\Local\Temp\arduino_build_724801/Arduino_XBee_Led_No_Sensor_sketch_apr27a.ino.hex:i

avrdude: Version 6.3-20190619

Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is “C:\Users\Magnix\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf”

Using Port : COM8

Using Programmer : wiring

Overriding Baud Rate : 115200

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

An error occurred while uploading the sketch

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done. Thank you.

The switch MUST be in the “DLINE” position when uploading sketches or you will see the error you’re getting.