xBee not working with Teensy 3.1

Status
Not open for further replies.

joe_prince

Well-known member
I'm having an issue when trying to use 2 xBees with the Teensy. Eventually I will need 2-way communication (for telemetry on the quadcopter), but for now I'm just trying to get simple 1-way communication to work.

Below is the bill of materials list for the circuit:
- Teensy 3.1
- xBee Series 2 (2mW): https://www.adafruit.com/products/968
- XBee USB Adapter Board: https://www.parallax.com/product/32400
- 3.3V Regulator: https://www.sparkfun.com/products/526

For the configuration of the xBees, I'm using transparent communication with a Coordinator in AT mode (which will be sending the data), and a Router in AT mode (which will be receiving the data). The settings that have been changed in XCTU are the pan ID [ID] to match for both xBees, the destination address high [DH] and low [DL] to match the other xBee, and the baud rate [BD] to 115200. Below are screenshots from XCTU for both the coordinator and router:

XCTU Coordinator Settings:
XCTU_coordinator.jpg
XCTU Router Settings:
XCTU_router.jpg

I'm using the USB adapter board for the xBees, which takes a 3.3V input from the regulator. The TX pin of the xBee is connected to the RX pin on the Teensy, and vice versa. Below is a screenshot of the schematic and photos of the actual circuit:

Schematic:
circuit_diagram.png

Actual Circuit (one for the Coordinator, one for the Router):
actual_circuit.jpg

Actual Circuit Close-up:
actual_circuit_close-up.jpg

For now, I'm trying to establish simple communication using the following code:

Coordinator (sender):
Code:
// SENDER
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println('K');
  delay(20);
}

Router (receiver):
Code:
// RECEIVER
int LED = 13;

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    if (Serial.read() == 'K') {
      digitalWrite(LED, HIGH);
      delay(50);
    } 
    else {
      digitalWrite(LED, LOW);
    }
  }
}

Just to make sure my xBees were working properly, I used the same circuit and code with 2 Arduino Uno's and it worked as expected (i.e., the router received the 'K' character and turned on the LED on pin 13). I even tested other variations where I sent a larger packet of data and the receiving Arduino Uno received it all. I also have the longer-range series 2 xBees (63mW) that I will be using for the actual quadcopter, but again those worked fine using 2 Arduino Uno's but didn't work with the Teensy.
 
Quick sanity check, is that board you are using there a level converter? If so the Teensy 3.1 may be struggling to get the TX pin high enough?

If you have a working Uno setup suggest only changing one end at a time, since the Xbee's won't care (except for the voltages) what is giving them data.
 
Why not use the Teensy 3V3 output instead of the voltage regulator? Do you need more than 100 mA to drive the XBees? If so, consider the nRF24L01+ or one of the lower frequency, longer range radios instead.
 
GremlinWrangler: Thanks for the sanity check! I don't see any mention of a level converter on Parallax's page...
But I also have the XBee Adapter kit (https://www.adafruit.com/products/126) which does have the level-shifting circuity, and still no luck using those.

onehorse: Thanks for the suggestion! The 2mW module only pulls about 40mA for TX, and another 40mA for RX. So using the 3V3 output from Teensy would be fine. However, the 63mW version that I will be using on the quadcopter pulls over 200mA. I've looked at the nRF24L01's, but wasn't pleased with the range (~100m). What's the range on the longer-range version?
 
I think the ~900 MHz radios have much longer than 100 m range. See here. I think the RFM69HW has several 100 m range but higher power requirements.
 
Last edited:
The Xbee and the Teensy are both 3.3V so I've used them directly connected via a componentless PCB that brought the pins out to 0.1" headers. If your test case worked with a 5V Uno then whatever hardware you used has 5V level converter hardware on it. This should work at the RX end since the T3.1 is 5V safe for inputs but the output level will be causing trouble going into a level converter expecting 5V to turn into 3.3 for the Xbee. Hence suggestion to test Uno->T3 and vice versa.

Would as a matter of principle suggest always using a separate regulator for a radio and micro just to keep the noise sources separate.

And off topic slightly can confirm the nRF24s range at <100 meters (at least for the modules I have) having just been caught out with things not quite reaching.
 
So I just tried using the Arduino as the sender, and the Teensy as the receiver. This did not work. I then tried the Teensy as the sender, and the Arduino as the receiver. Still did not work. Just to make sure the xBees were still working, I tried Arduino-to-Arduino and that worked just like before.

What do you think the problem could be?

(and just to note, I've tested both Teensy's with other code (such as BLINK), and they are working fine.)
 
First, get the XBees talking to a PC's USB/Serial port using a USB to 3.3V logic level cable. FTDI sells these cables.
Hook this up and then use Digi's XCTU on the PC to prove you can talk to the XBee and configure it.
Spend 2+ hours reading the XBee user/OEM manual, downloaded from Digi's web site.

These are simple, but not plug and go. They are essentially a smart modem.
 
stevech: Thanks for the advice! I've already confirmed the xBees are talking to each other (using Arduino's). I've got the manual saved on my computer and reference it all the time. I appreciate the feedback.

shouldn't that be Serial1 not Serial?

That did it! Seems to communicate fine now from Teensy-to-Teensy. I thought 'Serial' and 'Serial1' could be used interchangeably on the Teensy? Apparently I was wrong in assuming that...

Thanks a bunch for the simple, but helpful tip! :) And many thanks to everyone else for all the feedback as well!
 
As you've probably now sorted, Serial1-3 are hardware UARTs on various pins while Serial is the USB serial emulation. They joys of supporting Legacy code.
 
There's an XBee arduino library if you want to use the binary API - which is necessary for other than trivial point to point with one pair
 
There's an XBee arduino library if you want to use the binary API - which is necessary for other than trivial point to point with one pair

Thanks stevech. I'll take a look at the library if I need to add point-to-point communication with many xBees. Cheers!
 
Thanks stevech. I'll take a look at the library if I need to add point-to-point communication with many xBees. Cheers!
That's a network where each node has a unique address. You can use a peer-to-peer topology, or star, or mesh. Digi has free and great mesh protocol firmware to load into the XBee; it's called DigiMesh, for XBee series 1. Series 2 are by contract, ZigBee only (bleah).
 
Status
Not open for further replies.
Back
Top