Wiring Arduino Micro with Xbee Radio

Greetings!

I am having some trouble using the Arduino Micro board with an Xbee S1 and S2 radio, neither have worked. I am trying to directly connect the Xbee to the Micro without a shield. After wiring the boards up I tried receiving serial data on another radio with a FTDI USB shield with the same PAN ID / channel using a terminal program. Is it not possible to directly wire to an xbee radio? If not any suggestions would be extremely helpful.

Here is my wiring diagram: Xbee Arduino VCC or 3.3 V ----------- 3V3 TX or DOUT ------------ RX or 0 RX or DIN ------------ TX or 1 GND ------------ GND

I hope your XBees aren't fried. It has been discussed numerous times (search the forum) but XBees are not 5V tolerant; therefore, signals from a 5V microcontroller (e.g. TX) should not be directly hooked to XBee inputs. Do some research on level-conversion circuits.

http://www.digi.com/support/kbase/kbaseresultdetl?id=2160

What jack said! +1

Nolebrain: Greetings!

I am having some trouble using the Arduino Micro board with an Xbee S1 and S2 radio, neither have worked. I am trying to directly connect the Xbee to the Micro without a shield. After wiring the boards up I tried receiving serial data on another radio with a FTDI USB shield with the same PAN ID / channel using a terminal program. Is it not possible to directly wire to an xbee radio? If not any suggestions would be extremely helpful.

Here is my wiring diagram: Xbee Arduino VCC or 3.3 V ----------- 3V3 TX or DOUT ------------ RX or 0 RX or DIN ------------ TX or 1 GND ------------ GND

You can shift 5V to 3.3V using 2 resistors to make a voltage divider. 1 resistor should be half the ohms of the other (I used 2 4.7k resistors in series to make a 9.4k, got plenty 4.7k and no 9.4k). 5V goes into the smaller resistor and connects to both the larger resistor (which goes to ground and drains 1/3rd of the 5V) and the 3.3V (the other 2/3) out wire.

You can run 5V through 2 diodes to get 3.6V. Each diode drops .7V.

If the Arduino is connected to a PC through the USB cable then don't connect the XBEE to pins 0 and 1 since the USB connect uses them. Instead use the SoftwareSerial library and 2 other pins like 8 and 9. I can get 57600 maximum speed using SoftwareSerial but that should be fast enough.

My favorite XBee level shifting circuit is a diode and a resistor.

xbee level shift.png

That took me a while but I figured it out.

3.3V through the resistor provides a pullup. When TX is low it pulls that down. Mostly TX is high so there's not much wasted where a voltage divider would waste more.

GoForSmoke: That took me a while but I figured it out.

3.3V through the resistor provides a pullup. When TX is low it pulls that down. Mostly TX is high so there's not much wasted where a voltage divider would waste more.

Spot on! Took me a while too -- I think I stole the idea from Sparkfun :D

TTL serial is one of those things where the state of the wires is inverted to what I expected. OFF is HIGH.

hello I am trying to connect my arduino micro to an xbee. I came across this topic and was curious on literally what pins are connected with what resistors. As of right now we are testing with the micro hooked up via USB..Is there any way I can communicate with GoForSmoke??

In reply #3 of this thread, Jack gives a good circuit diagram that wastes less power than a divider will.

Is there a way we can contact you via email or phone number. my partner and I are having a very difficult time trying to have everything communicating.

That could be for a whole raft of reasons. Jack can give you better help that I but maybe if you post what you've got so far there will be even more help. That's the advantage of a forum, more eyes see your messages means more chances that someone will have good answers.

I don't have XBee but I do have 3.3V devices and had to figure out that serial works opposite the way you'd expect which led to a 1+1=2 moment for me, it does that to cut down on false signals. Serial "1" bits are sent by pulling the line LOW, not HIGH. The line is kept HIGH so it doesn't float and the LOW's are too short for much of that in normal use.

The 5V Arduino TX line has to be leveled down to 3.3V going to RX on the 3.3V device. TX from that 3.3V device is enough to work directly on the 5V RX.

TX works as OUTPUT. RX works as INPUT. INPUT doesn't put volts on the line, OUTPUT does. Going from 5V to 3.3V you need to protect the 3.3V RX pin and the 3.3V power line as well. For XBee and my 3.3V serial devices that seems about it, and my Arduinos have clean 3.3V power.

The circuit that Jack shows has DOUT (data out) instead of "TX" and DIN (data in) instead of "RX". Arduino RXD connects to DOUT and Arduino TXD connects to DIN the same as normally you connect RX of one device to TX of the other to make a serial connection. So you look at the diagram and see that Arduino RX connects directly to XBee DOUT. But Arduino TX that carries 5V, well the solution he shows is beautiful. The diode keeps the 5V out of the XBee so the XBee only sees the 3.3V on its power pin and through that 4.7k resistor when the line is 5V HIGH. When the Arduino TX does send a "1" bit, the line goes LOW and the 3.3V at the XBee end flows right through the diode to the Arduino TX pin leaving the XBee DIN pin seeing 0V LOW instead of 3.3V HIGH, exactly what it would see if the Arduino transmitted 3.3V on a direct wire. The circuit is superior because current only flows for those short periods when "1" bits are sent while with a voltage divider, current flows even when no message is sent.

Hi,

May I know whether anything would be added in the circuit given by Jack Christensen at pin DOUT of Xbee if I wanted to receive data at my Arduino Leonardo? (pin DOUT is connected to Rx pin of Arduino)

Using the circuit on breadboard#1, I could send data from Xbee#1 to Xbee#2. Xbee#2 was connected to my laptop by a Xbee Explorer. I moved Xbee#2 to breadboard#2 and connected Xbee#2 to an Arduino Leonardo (I reused the circuit given by Jack). I could not receive data at Xbee#2.

Does anyone have any suggestion? Tks a lot.

pamin: Hi,

May I know whether anything would be added in the circuit given by Jack Christensen at pin DOUT of Xbee if I wanted to receive data at my Arduino Leonardo? (pin DOUT is connected to Rx pin of Arduino)

Using the circuit on breadboard#1, I could send data from Xbee#1 to Xbee#2. Xbee#2 was connected to my laptop by a Xbee Explorer. I moved Xbee#2 to breadboard#2 and connected Xbee#2 to an Arduino Leonardo (I reused the circuit given by Jack). I could not receive data at Xbee#2.

Does anyone have any suggestion? Tks a lot.

It should work the same. Surely XBee #2 must still be receiving the data, assuming it is powered and connected correctly. Else it must be a code issue. The Leonardo is reading the XBee on Serial1, correct?

Thank you Jack for replying me so fast.

I am debugging the system by doing this:

  • Your circuit is on a breadboard and I have Xbee#1 on it.
    -Arduino Leonardo uses pin 10 and 11 for Rx and Tx, respectively.
  • Xbee#2 is connected to my laptop using a Xbee Explorer. X-CTU is used to control Xbee#2

Result:

  • I can send data from Xbee#1 (Arduino controls this) to Xbee#2.
  • BUT: I cannot use X-CTU to send data from Xbee#2 to Xbee#1. The red LED (connected to pin 6 in your circuit) is not ON when data is sent from Xbee#2.
  • I am using the following code

#include <SoftwareSerial.h>

uint8_t pinRx = 10, pinTx = 11;
SoftwareSerial mySerial(pinRx, pinTx);

long BaudRate = 9600;

int led = 12;

void setup()
{
pinMode(led, OUTPUT);

Serial.begin(BaudRate);
mySerial.begin(BaudRate);
mySerial.listen();
}

void loop()
{
// transmit
if (Serial.available())
{
char gotChar = Serial.read();
Serial.print(gotChar);
mySerial.print(gotChar);
digitalWrite(led, HIGH);
delay(20);
digitalWrite(led, LOW);
}

// receive
if (mySerial.available())
{
char gotChar = mySerial.read();
Serial.print(gotChar);
digitalWrite(led, HIGH);
delay(20);
digitalWrite(led, LOW);
}
}

Your suggestion is much appreciated. Tks a lot.

pamin: - BUT: I cannot use X-CTU to send data from Xbee#2 to Xbee#1. The red LED (connected to pin 6 in your circuit) is not ON when data is sent from Xbee#2.

That sounds like a different problem and a different setup than described in Reply #11.

Pick one. Which shall we work on first?

Also, we need to know what kind of XBees you have.

Hi Jack,
Thank you so much for your time.

I am trying to do scenario in post #13: connection between 2 xbees using Arduino and X-CTU.

I am using two Xbee S1. One is coordinator and the other is end device. They have the same Channel (C) and PAN ID. DH and DL of one Xbee are the appropriate addresses of the other.

Xbee#1 is connected to Arduino. I use SERIAL MONITOR to send data to Xbee#2.

From Xbee#2 (controled by X-CTU) I tried two ways: 1) keying directly on CONSOLE LOG window and 2) adding package and send (just below the CONSOLE LOG window). But Xbee#2 → Xbee#1 is not successful.

I've never worked with S1 modules configured as coordinator/end device. Is there some reason for not using just the regular peer-to-peer configuration? Maybe you have already done this, but what I would do first would be to get the microcontroller out of the picture, connect both XBees to XCTU or some other terminal program, i.e. run two copies of the terminal program and verify that they can communicate. End devices can be a bit tricky, making sure they wake up appropriately to communicate.

Sorry but not sure I can be of much more help than that.

Thank you Jack.

I tried two Xbees connected to laptop using two Xbee Explorers + X-CTU. They worked well. That's why it was so confusing when they did not work when I added Arduino.

BTW, please correct me if I am wrong. I though in a network, one Xbee should be Coordinator and the other should be End Device. Is it wrong?

Can the End Device talk back and if so, how? Because that is where you are having the problem, no?

pamin: Thank you Jack.

I tried two Xbees connected to laptop using two Xbee Explorers + X-CTU. They worked well. That's why it was so confusing when they did not work when I added Arduino.

OK, good. Sounds like a code problem then.

BTW, please correct me if I am wrong. I though in a network, one Xbee should be Coordinator and the other should be End Device. Is it wrong?

Well, that is one of two ways XBee 802.15.4 modules (f.k.a. Series 1) can be configured. There is also a peer-to-peer configuration and I believe that is the way they come from the factory. I also think most of the discussion I've seen here on the forum is for peer-to-peer. If you don't have the product manual, download a copy.

XBee ZB modules (f.k.a Series 2) OTOH require one coordinator in every network. The rest of the network can consist of routers and/or end devices.

I would assume that the XBee 802.15.4 modules configured as coordinator/end device operate somewhat differently than the XBee ZB modules. How much different they are I cannot say. My experience is primarily with the XBee ZB modules, so I can't comment much more on the XBee 802.15.4 modules and especially when they are configured as coordinator/end device.

So let's have a look at the the code. How about reposting it just so we know we are looking at the latest code. Put the code between code tags (#), not quote tags. See http://forum.arduino.cc/index.php/topic,148850.msg1118324.html#post_codetags