0

XBees appear to only communicate one way
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

XBees appear to only communicate one way

by heychuck on Mon Sep 12, 2016 6:49 pm

I had a setup with my arduino Uno with which I could control a DC motor using wireless serial communication using XBees.

A few days later when I attempted to test it again, I ran into problems. The motor was not responding. I discovered that the arduino board's TX and RX LEDs were not flashing when I sent commands, and determined that the issue was with the communication.

After testing the XBee modules using a simple sketch, I'm unsure what the problem is (though I'm confident it's still with the communication) and would appreciate some help.

Now for some details:

Components used:

I purchased both XBee PRO S2B modules from adafruit sometime last year. I don't see them on adafruit's website anymore, but I think they're similar to these. I also purchased these adapter kits.

Here's a picture of my modules and adapters:
xbee_module_and_adapter.png
My Xbee modules and adapters. Coordinator on the left, Router on the right.
xbee_module_and_adapter.png (1014.86 KiB) Viewed 517 times


I usually connect the coordinator XBee to my laptop using a USB to FTDI adapter. Since the adapter is essentially a small breakout with some female-female jumper wires, I'll post pictures in case that is the issue. You can also see in the picture below how I have it connected to the adapter.
usb_to_FTDI_top.jpg
Top view of my usb-FTDI adapter that I use to connect my XBee to my laptop.
usb_to_FTDI_top.jpg (273.19 KiB) Viewed 517 times

FTDI_connection_to_adapter.jpg
View of the adapter kit being plugged into the FTDI-USB adapter
FTDI_connection_to_adapter.jpg (300.47 KiB) Viewed 517 times


To see if the problem was with my FTDI adapter, I also repeated the testing by accessing the coordinator through my Arduino Uno as described in this video. No difference was observed with the exception of being able to see RX/TX LEDs flash (or not) on the Arduino.

To test the XBees on another board, I also used an Arduino Micro (not to connect the coordinator to the laptop, but to run the sketch).

Test Sketch
I adapted some code found on an Adafruit XBee guide.
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>
// XBee's TX is connected to pin 2 (Micro's RX)
// XBee's RX is connected to pin 3 (Micro's TX)
SoftwareSerial XBee(2, 3); // RX, TX

void setup()
{

   Serial.begin(9600);      // Com with serial monitor
   delay(2000);         // Wait for port to open
   Serial.println("Goodnight moon!");
   // Both XBees configured for 9600 baud
   XBee.begin(9600);     // Com through XBee using RX/TX pins
   XBee.println("Hello, world?");
 

}

void loop()
{
   if (XBee.available())
      {
         Serial.println((char)XBee.read()); // send xbee data to serial montor
      }

   if (Serial.available())
   {
      XBee.println((char)Serial.read()); // send serial monitor data to XBee
   }
 
}


Software Used

For a serial monitor, I have been using visual studio 2013. To send/receive data through the XBee attached to my laptop, I've been using XCTU.

Before recommending that I check/change settings in XCTU, please keep in mind that the modules were working previously and that none of the settings have been changed. My suspicion is that too much current got away from the motor and fried something either on an adapter or on one of the modules. Right now I'm hoping you can help me find out what exactly needs replacing.

Testing Setup
Using the Arduino Mico I connected:
    Laptop USB to Arduino Micro USB
    5V and GND on Micro to adapter 5V and GND
    D2 on Micro to TX on XBee
    D3 on Micro to RX on XBee

I can supply a picture of this setup if required (already reached maximum).

Testing and Results

I attempted to send characters from the XCTU console to the serial monitor and vice versa. I did this test multiple times, switching XBee modules and switching adapters. Changing adapters didn't seem to make a difference. I'll put below what I did followed by what I observed.

Computer/XCTU connected to the coordinator
    Typing characters into the XCTU console log
    The red LEDs on both of the XBee adapter kits light up for about 4 seconds, but the coordinator lags behind the router by about 1 second.
    No RX/TX LEDs flash on the Micro
    No message appears in the serial monitor
    When connecting the coordinator to the computer through the Arduino Uno, the RX LED on the Uno does flash
    Typing characters into the serial monitor (and pressing send of course)
    The RX LED on the Micro flashes
    The red LEDs on both of the XBee adapter kits light up for about 4 seconds (synchronized this time)
    The character appears in the console log
    When connecting the coordinator to the computer through the Arduino Uno, the TX LED on the Uno does flash

Computer/XCTU connected to the router
    Typing characters into the XCTU console log
    The red LEDs on both of the XBee adapter kits light up for about 4 seconds (synchronized)
    No RX/TX LEDs flash on the Micro
    No message appears in the serial monitor
    When connecting the router to the computer through the Arduino Uno, the RX LED on the Uno does flash
    Typing characters into the serial monitor (and pressing send of course)
    The RX LED on the Micro flashes
    The red LEDs on both of the XBee adapter kits light up for about 4 seconds (again the coordinator lags behind the router by about 1 second)
    The character appears in the console log
    When connecting the router to the computer through the Arduino Uno, the TX LED on the Uno does flash

My Conclusion
The delay in the coordinator's LED makes me think that there's an issue with the coordinator module (not the adapter since switching adapter's didn't make a difference). However, I'm not sure how this accounts for the communication being "one-way." I call it one way because the console can receive data from the monitor, but the monitor cannot receive data from the console. In my mind, switching the router and the coordinator would reverse that, but I could be wrong.

Or maybe nothing is broken but I misspelled something in my code? I have no idea at this point. It's been taking a long time to fix something that was almost literally working fine yesterday. Any help would be appreciated. Thanks!

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by adafruit_support_rick on Tue Sep 13, 2016 2:47 pm

heychuck wrote:I attempted to send characters from the XCTU console to the serial monitor and vice versa. I did this test multiple times, switching XBee modules and switching adapters. Changing adapters didn't seem to make a difference. I'll put below what I did followed by what I observed.

Computer/XCTU connected to the coordinator
Typing characters into the XCTU console log
The red LEDs on both of the XBee adapter kits light up for about 4 seconds, but the coordinator lags behind the router by about 1 second.
No RX/TX LEDs flash on the Micro
No message appears in the serial monitor
When connecting the coordinator to the computer through the Arduino Uno, the RX LED on the Uno does flash
Typing characters into the serial monitor (and pressing send of course)
The RX LED on the Micro flashes
The red LEDs on both of the XBee adapter kits light up for about 4 seconds (synchronized this time)
The character appears in the console log
When connecting the coordinator to the computer through the Arduino Uno, the TX LED on the Uno does flash

Computer/XCTU connected to the router
Typing characters into the XCTU console log
The red LEDs on both of the XBee adapter kits light up for about 4 seconds (synchronized)
No RX/TX LEDs flash on the Micro
No message appears in the serial monitor
When connecting the router to the computer through the Arduino Uno, the RX LED on the Uno does flash
Typing characters into the serial monitor (and pressing send of course)
The RX LED on the Micro flashes
The red LEDs on both of the XBee adapter kits light up for about 4 seconds (again the coordinator lags behind the router by about 1 second)
The character appears in the console log
When connecting the router to the computer through the Arduino Uno, the TX LED on the Uno does flash


Let me make sure I understand this part. So, you can *always* write from the serial monitor to the computer The problem is that you can't write from the computer to the serial monitor. Swapping xbees and adapters doesn't make a difference. Is that right?

adafruit_support_rick
 
Posts: 35086
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: XBees appear to only communicate one way

by heychuck on Tue Sep 13, 2016 5:22 pm

Correct on all counts.

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by adafruit_support_rick on Wed Sep 14, 2016 12:57 pm

OK, so that tells me that the XBees and adapters work. You've got two XBees and adapters, call them A and B. In one configuration, B can talk to A, A can't talk to B.
Swap them, and now A can talk to B but B can't talk to A.
The net takeaway from that is that A can talk to B and B can talk to A.

So the problem is in the connection to the computer or in the connection to the Micro.

That's easy to check. Just loop back RX to TX. So, connect the Micro to A. On B, put a jumper between RX and TX. Whatever you send from the Micro should be echoed back to it.

Do the same thing from the computer. Connect the computer to B, and put the loopback wire on A. See if you get the echoed data back that way.

adafruit_support_rick
 
Posts: 35086
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: XBees appear to only communicate one way

by heychuck on Wed Sep 14, 2016 11:33 pm

Thanks for your help! I followed your instructions and here's what happened.

When I plugged one into the computer and the other had TX and RX linked, I got the echo when typing into the XCTU.

When I connected one to the Micro using pins 2 and 3 and looped back the TX and RX of the other module, I didn't get any echo in the serial monitor.

What do you suggest doing next?

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by franklin97355 on Thu Sep 15, 2016 1:23 am

When I plugged one into the computer and the other had TX and RX linked, I got the echo when typing into the XCTU.
OK one last test. Swap the devices that worked (A to B) and see if it still works.

franklin97355
 
Posts: 18567
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: XBees appear to only communicate one way

by heychuck on Thu Sep 15, 2016 11:17 am

When I first tried to reproduce the echo I couldn't, but then I realized that for some reason the module not connected to my computer hadn't turned on (at least the green LED wasn't on). It was supposed to be getting 5V from the Arduino Uno. After unplugging and plugging the USB to the Arduino, the LEDs came on and I got the echo. I thought this was strange because during all my testing the other day I never noticed the LEDs not come on.

Then I switched the modules (including adapter kits) and got the echo again.

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by adafruit_support_rick on Thu Sep 15, 2016 12:19 pm

If I'm following this correctly, you get echoes using the Uno/Micro with A<->B and B<->A. So it seems like both XBees and the Uno/Micro communications work properly.

That leaves the FTDI cable. You can also do a loopback on that to test it.

adafruit_support_rick
 
Posts: 35086
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: XBees appear to only communicate one way

by heychuck on Thu Sep 15, 2016 9:25 pm

adafruit_support_rick wrote:If I'm following this correctly, you get echoes using the Uno/Micro with A<->B and B<->A. So it seems like both XBees and the Uno/Micro communications work properly.

That leaves the FTDI cable. You can also do a loopback on that to test it.


Sorry for the confusion, actually the echo test was only "passing" (meaning I get what I send echoed back) when my XBee module was connected to the computer. However, that is no longer the case. I realized that I hadn't done the echo test with the Arduino Uno yet so I gave it a shot and it passed. This confuses me a lot since the Uno board is what I was using when I first noticed the issue. I even tried moving the circuit with the Micro around on the breadboard, thinking maybe the holes I was first using weren't gripping the pins properly but the testing with the Micro still failed the test.

For a simple summary of what's working and what's not, see the two lists below (A and B refer to XBee Module/Kit combinations):

List of passing echo tests:
  1. A connected through FTDI-USB adapter, B powered with 5V and TX/RX pins looped, data sent/echoed through XCTU.
  2. B connected through FTDI-USB adapter, A powered with 5V and TX/RX pins looped, data sent/echoed through XCTU.
  3. A connected to Uno pins 2 and 3, B powered with 5V and TX/RX pins looped, data sent/echoed through serial monitor.
  4. B connected to Uno pins 2 and 3, A powered with 5V and TX/RX pins looped, data sent/echoed through serial monitor.

List of failing echo tests:
  1. A connected through Micro pins 2 and 3, B powered with 5V and TX/RX pins looped, data sent/not echoed through serial monitor.
  2. B connected through Micro pins 2 and 3, A powered with 5V and TX/RX pins looped, data sent/not echoed through serial monitor.
  3. I also tried to test the USB-FTDI adapter by disconnecting the jumper wires from the XBee adapter and looping the TX and RX. I didn't get any echo back through the serial monitor doing this but I'm not sure if that's because I didn't have anything connected to the other pins on it.

Any idea why this isn't working with the Micro?

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by adafruit_support_rick on Fri Sep 16, 2016 10:13 am

Ah, OK. So it's the micro that's the problem. You can't use 2 and 3 for software serial. You can only use any of 8, 9, 10, 11, 14, 15, or 16 for software serial receive. Software serial transmit can be any pin. Instead of 2 and 3, try 8 and 9.

adafruit_support_rick
 
Posts: 35086
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: XBees appear to only communicate one way

by heychuck on Fri Sep 16, 2016 11:18 pm

Success! Thank you so much for all the help. I guess I don't know what the problem was before switching to the Micro though. I'm going to try rebuilding my original circuit and see if that's working.

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by adafruit_support_rick on Sat Sep 17, 2016 8:04 am

Great!

adafruit_support_rick
 
Posts: 35086
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: XBees appear to only communicate one way

by heychuck on Sat Sep 17, 2016 4:22 pm

Alright so I rebuilt my original circuit and haven't been able to get serial communication to happen wirelessly (though it works perfectly with the USB cable plugged into the Uno). I've been running different tests and can't seem to find where the problem is.

I ran some echo tests to be sure the USB-FTDI adapter is working as well as the setup with the Uno. They all passed.

What isn't working is when I run my sketch to control the motor. Again, this sketch works when the USB cable is plugged in:
Code: Select all | TOGGLE FULL SIZE
/*
Name:    Sketch1.ino
Created: 8/10/2016 9:57:27 AM
Author:  Charles Ward
*/
/*

Description

DC_Motor_Control will allow a user to control the speed and direction of the DC motor using serial communication

*/
/*

H-Bridge Pin Information

1-ENABLE PIN    - Use PWM to control the speed of the motor connected to PINs 3 and 6
2-DIRECTIONAL PIN - One direction if PIN 2 is LOW and PIN 7 is HIGH, other direction if opposite, no power if both are HIGH or LOW
3-MOTOR LEAD    - Connect to a motor lead
4-GND       - NOTE THAT GND FROM ARDUINO MUST CONNECT TO GND FROM EXTERNAL POWER
5-GND       - NOTE THAT GND FROM ARDUINO MUST CONNECT TO GND FROM EXTERNAL POWER
6-MOTOR LEAD    - Connect to a motor lead
7-DIRECTIONAL PIN - One direction if PIN 2 is LOW and PIN 7 is HIGH, other direction if opposite, no power if both are HIGH or LOW
8-PWR Motor     - Connect to external power for motor

9-ENABLE PIN    - Use PWM to control the speed of the motor connected to PINs 11 and 14
10-DIRECTIONAL PIN  - One direction if PIN 10 is LOW and PIN 15 is HIGH, other direction if opposite, no power if both are HIGH or LOW
11-MOTOR LEAD   - Connect to a motor lead
12-GND        - NOTE THAT GND FROM ARDUINO MUST CONNECT TO GND FROM EXTERNAL POWER
13-GND        - NOTE THAT GND FROM ARDUINO MUST CONNECT TO GND FROM EXTERNAL POWER
14-MOTOR LEAD   - Connect to a motor lead
15-DIRECTIONAL PIN  - One direction if PIN 10 is LOW and PIN 15 is HIGH, other direction if opposite, no power if both are HIGH or LOW
16-PWR H-Bridge   - Connect to 5V to power bridge

*/

/*

Arduino Hookup (Use Xbee for wireless serial)

**PIN**   **COMPONENT**
GND     9V GND, XBEE GND, H-Bridge GND (12&13)
5V      XBEE 5V, H-Bridge 16
D3      H-Bridge 9
D2      H-Bridge 10
D4      H-Bridge 15

Other Hookup

9V +   - H-Bridge 8
Motor1 - H-Bridge 11
Motor2 - H-Bridge 14

*/

// Define Variables and Constants

int const dirpin1 = 2;
int const dirpin2 = 4;
int const spdpin = 3;
char const motor1reg = 0x01;
char state  = 0;
char state0 = 0;
float spd = 0;

byte inBytes[] = { 0, 0 };

void setup() {

   // Set Pin Modes

   pinMode(dirpin1, OUTPUT);
   pinMode(dirpin2, OUTPUT);

   // Begin Serial Communication

   Serial.begin(9600);

   // Turn off motor

   digitalWrite(dirpin1, LOW);
   digitalWrite(dirpin2, LOW);
   analogWrite(spdpin, spd);

}

void loop() {

   // Engage the motor

   if (bitRead(state, 7)==1){

      digitalWrite(dirpin2, HIGH);
      digitalWrite(dirpin1, LOW);

   }
   else
   {

      digitalWrite(dirpin2, LOW);
      digitalWrite(dirpin1, HIGH);

   }

   spd = (float)((byte)state << 1);
   
   analogWrite(spdpin, spd);

   // Receive/Reassign Speed and direction

   if (Serial.available() == 2) {
   
      for (int x = 0; x < 2; x++){

         inBytes[x] = Serial.read();

      }

      switch ((char)inBytes[0]){

      case motor1reg:

         state = (char)inBytes[1];

      }

   }

}


This was originally used when I had XBee TX and RX connected to digital pins 0 and 1, respectively, on the Uno. When I ran into problems, I switched them to be on 8 and 9 and implemented the software serial library just like in the echo tests. I then basically switched "Serial" for "XBee" in all the calls to Serial.available etc. However, it's still not sending/recieving (as confirmed by the RX/TX pins) and I don't think the serial connection is even being established.

I noticed that for some reason, the pin 13 LED on the Uno is lit all the time (I don't know if it is supposed to do this. As you can see, it's not mentioned in my sketch at all). When I click the button on my GUI to establish serial communication when the Uno is plugged in with the USB, the light blinks rapidly when the connection is established. This never happens when trying to connect wirelessly.

Basically, I have no idea what is broken at this point. It could be part of my sketch that I changed without realizing that messed it all up, but I can't think of any likely reason why it stopped working.

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Re: XBees appear to only communicate one way

by adafruit_support_rick on Sun Sep 18, 2016 10:23 am

You're using a 9V power supply for the Uno? If so, you can still plug USB into the Uno and write some debugging information to Serial.
That's what I would do. Sprinkle some debug prints around and see if you can find out what's going on.

adafruit_support_rick
 
Posts: 35086
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: XBees appear to only communicate one way

by heychuck on Mon Sep 19, 2016 7:52 pm

So I tried to start doing this but for some reason my USB-FTDI adapter and my Uno want to have the same port (but obviously can't). Any idea how to fix this? No matter which USB slot I plug them into, they both want to be COM4. In the past they've numbered up to COM7 so this is kind of weird.
sharing_com4.png
screenshots when trying to communicate with Uno AND XBee via adapter
sharing_com4.png (54.19 KiB) Viewed 383 times


What I'll do in the meantime is start adding bits of my DC motor controlling sketch into the loop back echo test. Hopefully I'll be able to find what breaks it.

Thanks

heychuck
 
Posts: 14
Joined: Tue Aug 25, 2015 12:15 pm

Please be positive and constructive with your questions and comments.