PeterH:
Is your XBee using the same serial port as the USB connection to the host?
I'm using the Xbee Sparkfun shield , it has a little switch that you need to move when you are uploading a sketch. This disconnects pin 0 and 1 from the Xbee so the sketch can be uploaded. After the sketch is uploaded, you slide it back and it reconnects pins 0 and 1 to the xbee can communicate with the Arduino. The serial monitor works when it's in the latter position. But I'm not really sure about the answer to your question. I don't have a deep understanding of the serial connections.
The answer to Perter's question is yes by the sound of it - the Xbee is talking to the Arduino's hardware serial port - you can't share it by using serial.print commands as well. Or rather, you can, but as you can see it doesn't work very well.
I suggest you study the instructions for your XBee shield to check how it's intended to be used, but what you're doing doesn't sound right to me. If you're running with the XBee serial port connected to the Arduino's hardware serial port then I don't think it is a good idea to also connect the Arduino's serial port to the PC. A serial connection is designed to connect two end points, not three.
PeterH:
I suggest you study the instructions for your XBee shield to check how it's intended to be used, but what you're doing doesn't sound right to me. If you're running with the XBee serial port connected to the Arduino's hardware serial port then I don't think it is a good idea to also connect the Arduino's serial port to the PC. A serial connection is designed to connect two end points, not three.
That's a good point. Unfortunately, there are no instructions to check, but I can probably ask the question in the Sparkfun comments. If the XBee was interfering with the serial monitor, I would expect to see some garbled characters from time to time, or most of the time, but I don't; only a couple when I first reboot the Arduino. I did a little test and slid the switch on the xbee shield so the xbee was not connected to the serial pins anymore, then I rebooted. I still had the same issue with a couple of garbled characters in serial monitor at the start of a reboot. So the XBee communicating over serial doesn't seem to be the cause.
Maybe it's designed to be used like that, although it still seems wrong to me. Why is the XBee connected to the serial port? Is it intended to send to the PC, or the Arduino, or what? The serial connection only has two end points, and if you have two devices trying to drive one end point then they're going to be fighting against each other. Anyway, you say that doesn't change the symptoms.
It's not uncommon with async serial comms for the receiver to need to receive a few characters to get synced to the bitstream. Perhaps this is what you're seeing? (Maybe aggravated by a serial line that has a distorted signal due to having two devices trying to drive it - but that's pure speculation.)
My Xbee shield is similar (although a switch would be nice - I have a jumper to change modes). The arduino and the Xbee communicate using the serial port, so you have to disable that communication to upload a new sketch. Because of this, you can't use the serial port for debugging/monitoring.
PeterH:
Why is the XBee connected to the serial port? Is it intended to send to the PC, or the Arduino, or what?
The XBee is communicating with the Arduino.
Then I suggest that the Arduino should use that serial port only to talk to the XBee, and should not be printing debug messages on it. (What do you suppose your XBee will be making of those debug messages?)
PeterH:
Then I suggest that the Arduino should use that serial port only to talk to the XBee, and should not be printing debug messages on it. (What do you suppose your XBee will be making of those debug messages?)
You're probably right. In practice, everything seems to run very well. Probably because I'm either writing to the serial monitor or getting data from xbee, I'm not doing both at the same time. I read on sparkfun's site that the xbee shield supports communication on digital pins 2 & 3, so I'm going to look into doing that.