XBee interferes with USB serial

First, about what works: Arduino (I think it was rev. 1 or 2) and xBee Pro 868MHz: I connect Rx and Tx pins of Arduino and xbee (Rx->Tx, Tx->Rx) and power xbee with external power source (3.3V, the same gives 5V to Arduino). When I connect external power source it powers both xbee and arduino. Serial communication works via xbee. When I connect USB to Arduino, it powers only Arduino, and serial works beautifully via USB. Everything is OK.

Now I need second device, I bought one more xbee and Arduino (it looks slightly different, but it's also rev 1 or 2, definitely not 3). Connected everything the same way. But now when I connect it to USB, serial connection doesn't work. Well it works sort of, but its very unstable. At the moment I don't know how to debug it and get some more info what works and what doesn't.

Any ideas what is wrong? Maybe I should add some optocouples on Rx/Tx pins?

On an Arduino UNO the USB connection is converted into a serial interface with the onboard ATmega16U2 "coprocessor" and the fed to the serial interface of the main processor on pin 0 and 1. If you connect a XBee to these pins you cannot use the USB serial at the same time as you use the XBee. If you need a debug serial, buy a USB2Serial converter (p.e. the USB2Serial Light from Arduino) and connect it to two other pins and install a SoftwareSerial on these pins. Another possibility is to use an Arduino Leonardo which handles the USB connection directly in the main processor and leaves the serial interface free for you to use even when using the USB connection for debugging. The hardware serial is available via the Serial1 object to the sketch then.

But if xbee is not powered, why USB does't work? I don't need two Serial connections at the same time, just USB or hardware serial, depending on what is the power source.

But if xbee is not powered, why USB does't work?

What does that mean? Did you disconnect the XBee? Just not powering the XBee may leave the XBee's serial pins in some undefined state that may disturb the regular serial communication over USB of the Arduino.

But why it worked with my first arduino, and doesn't work with the second?

You probably should describe again, which constellation worked and which didn't. I got that differently, I didn't realize that you didn't disconnect the XBee from the first Arduino.

Which type of Arduino did you use for these tests (UNO, Duemillanove, etc.)? What kind of shield did you use to connect the XBee to the Arduino?

pylon: You probably should describe again, which constellation worked and which didn't. I got that differently, I didn't realize that you didn't disconnect the XBee from the first Arduino.

Exactly, the first arduino worked perfectly: when connect via USB serial worked over USB (xbee is not powered in this situation), when connected via external power source, which also powered xbee, data went through xbee.

Which type of Arduino did you use for these tests (UNO, Duemillanove, etc.)?

I'm using Arduino Uno, but two units were bought not at the same time, and bought on ebay, so I doubt they are original. And they look a little bit different. Everything I can say for sure is they both are not the newest Arduino Uno rev. 3.

What kind of shield did you use to connect the XBee to the Arduino?

None, I just connected Arduino Rx to xbee Tx and Arduino Tx to xbee Rx.

Can you post pictures of the two Arduinos? Maybe we can see something on them.

The behavior of the second unit is the behavior I would expect from an original Arduino UNO Rev3.

I hope it will help :)

The one on the left works perfectly, the one on the right - no.

It seems both are forged Arduinos and not original ones. The right one even doesn’t have a resonator but a crystal as the clock source. The left one seems to be a copy of the UNO rev. 1 with an almost identical layout while the right one looks like a mixture between an UNO and a Duemillanove.

The one on the left works perfectly, the one on the right - no.

Does “works perfectly” mean that it turns the the XBee off if powered by the USB? That may be your desired functionality but the Arduino doesn’t work correctly if it behaves that way. No matter what power source it should power external components too.

Debugging this is probably a heavy task because you have absolutely no schematics of the badly copied boards and you cannot rely on anything behaving as expected.

pylon:
Does “works perfectly” mean that it turns the the XBee off if powered by the USB?

No, xbee is not powered by EXTERNAL power source. Xbee is not powered, but Rx/Tx pins are interconnected between arduino and xbee.

No, xbee is not powered by EXTERNAL power source. Xbee is not powered, but Rx/Tx pins are interconnected between arduino and xbee.

In your first post you wrote exactly the contrary.

Quoting myself:

When I connect external power source it powers both xbee and arduino. Serial communication works via xbee. When I connect USB to Arduino, it powers only Arduino, and serial works beautifully via USB.

:)

Quoting myself:

Does “works perfectly” mean that it turns the the XBee off if powered by the USB?

Doesn’t that mean the same? I wanted to know if you mean that by the term “works perfectly”? Does it?

And if it does: it may be appreciated by you but it’s the wrong behavior for an Arduino UNO.

Maybe I'm explaining it not very clearly, but let me put it in other words:

Xbee is powered independently from arduino. It gets its 3.3V NOT from arduino.

Desired behavior is: 1. Rx/Tx pins of arduino and xbee are connected; 2. Arduino is powered through USB 3. xbee is NOT powered at all (0 is connected, but 3.3V is NOT) 4. Arduino should communicate via USB serial.

On my first board it works that way. On the second - no.

On my first board it works that way. On the second - no.

Except the different board, all other devices (XBee) and wiring are the same (not just identical!)?

pylon:

On my first board it works that way. On the second - no.

Except the different board, all other devices (XBee) and wiring are the same (not just identical!)?

Yes, everything is connected the same way. Last year (when the question was originally asked) I've used a tumbler that disconnects rx and tx wires between arduino and xbee, but it's not very convenient. Maybe this year someone will have a better idea how to make it work? :)