Go Down

Topic: Wiring Arduino Micro with Xbee Radio (Read 18776 times) previous topic - next topic

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


JChristensen

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

GoForSmoke

What jack said! +1


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.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

JChristensen

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

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.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

JChristensen


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

GoForSmoke

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

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

lizgrian90

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??

GoForSmoke

In reply #3 of this thread, Jack gives a good circuit diagram that wastes less power than a divider will.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

lizgrian90

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.

GoForSmoke

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.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

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.

JChristensen


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?

pamin

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
Quote
#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.

JChristensen


- 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.

Go Up