XBee Coordinator not receiving data from end point

Howdy!

I am very new to Arduino and XBee, so please bear with me if I get a few things wrong! I have done quite a bit of research to try to implement what I am about to describe, but have hit a road bump that I can’t seem to overcome.

I have two Arduinos (one Nano and one Uno) each with their own XBee. I am attempting to send data (just a 1 value for now) from the Uno to the Nano, and display that data on an LCD (based on this tutorial).

Currently, the tx (dout) led of the Uno’s XBee is blinking as expected, but the rx (din) led of the Nano’s XBee never blinks, and it doesn’t seem to be picking up any data at all. Any help with this would be greatly appreciated! (I have tried switching rx and tx connections between XBee’s and Arduino’s, too.) All specifications below.

Both XBee’s are connected 5V → 5V, GND → GND, DIN → RX, DOUT → TX for both Arduino’s.

I have configured the XBee’s in the following way:

Nano’s XBee: CH - C, PAN ID - 1001, API Enabled, DL - 88, MY - 77, Coordinator

Uno’s XBee: CH - C, PAN ID - 1001, API Enabled, DL - 77, MY - 88, End Device

The code for each Arduino is as follows:

Nano:

/*   ~ Simple Arduino - xBee Receiver sketch ~

  Read an PWM value from Arduino Transmitter to fade an LED
  The receiving message starts with '<' and closes with '>' symbol.
  
  Dev: Michalis Vasilakis // Date:2/3/2016 // Info: www.ardumotive.com // Licence: CC BY-NC-SA                    */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Constants
LiquidCrystal_I2C lcd(0x24, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//Variables
bool started= false;//True: Message is strated
bool ended  = false;//True: Message is finished 
char incomingByte ; //Variable to store the incoming byte
char msg[3];    //Message - array from 0 to 2 (3 values - PWM - e.g. 240)
byte index;     //Index of array

void setup() {
  //Start the serial communication
  Serial.begin(9600); //Baud rate must be the same as is on xBee module
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.clear();
}

void loop() {
  lcd.clear();
  lcd.print("Trying to receive");
  while (Serial.available()>0){
    //Read the incoming byte
    incomingByte = Serial.read();
    //Start the message when the '<' symbol is received
    if(incomingByte == '<')
    {
     started = true;
     index = 0;
     msg[index] = '\0'; // Throw away any incomplete packet
   }
   //End the message when the '>' symbol is received
   else if(incomingByte == '>')
   {
     ended = true;
     break; // Done reading - exit from while loop!
   }
   //Read the message!
   else
   {
     if(index < 4) // Make sure there is room
     {
       msg[index] = incomingByte; // Add char to array
       index++;
       msg[index] = '\0'; // Add NULL to end
     }
   }
 }
 delay(1000);
 lcd.clear();
 lcd.print(started);
 lcd.print(" ");
 lcd.print(ended);
 delay(2000);
 
 if(started && ended)
 {
   int value = atoi(msg);
   lcd.print(value);
   //Serial.println(value); //Only for debugging
   delay(2000);
   index = 0;
   msg[index] = '\0';
   started = false;
   ended = false;
 }
}

Uno:

/*   ~ Simple Arduino - xBee Transmitter sketch ~

  Read an analog value from potentiometer, then convert it to PWM and finally send it through serial port to xBee.
  The xBee serial module will send it to another xBee (resiver) and an Arduino will turn on (fade) an LED.
  The sending message starts with '<' and closes with '>' symbol. 
  
  Dev: Michalis Vasilakis // Date:2/3/2016 // Info: www.ardumotive.com // Licence: CC BY-NC-SA                    */

int value = 1;

void setup() {
  //Start the serial communication
  Serial.begin(9600); //Baud rate must be the same as is on xBee module
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  //Send the message:
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  Serial.print('<');  //Starting symbol
  Serial.print(value);//Value from 0 to 255
  Serial.println('>');//Ending symbol
  
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

Firstly disconnect the Arduinos and use the XCTU program to check that the two Xbees are able to communicate.

If that works, reconnect the Arduino and check the wiring.
The sending Arduino Tx goes the Xbee Din. The receiving Arduino Rx goes to Xbee Dout.

I would recommend that you use hardware flow control to limit the rate at which you send data otherwise it will overflow the sending Xbee's transmit buffer which will likely cause unpredictable behaviour.

Thank you for the response!

I have switched over to using an XBee with the Nano and another XBee on my laptop. I have confirmed that I can send data through XCTU to the Nano’s XBee in the working console.

I am now working on interpreting the packet received on the Nano’s end to use the data in a meaningful way. Per the code provided below, my lcd is correctly displaying something for serial available (a 10) and displays characters when I don’t use atoi(), and a 0 when I do use atoi(). I have specified in my transmit packet that the RF data should be an ASCII 1, and I would appreciate any direction in how I should go about parsing the received packet to obtain that RF data.

Currently I have the transmit packet setup in the following way from the frames generator in the working console:

0x01 Tx (transmit) request: 16-bit address
Frame ID: 01
16-bit dest. address: 0088
RF data: ASCII - 1

And this is the receiving code on my Nano now:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Constants
LiquidCrystal_I2C lcd(0x24, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//Variables
bool started= false;//True: Message is strated
bool ended  = false;//True: Message is finished 
char incomingByte ; //Variable to store the incoming byte
char msg[3];    //Message - array from 0 to 2 (3 values - PWM - e.g. 240)
byte index;     //Index of array

void setup() {
  //Start the serial communication
  Serial.begin(9600); //Baud rate must be the same as is on xBee module
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.clear();
}

void loop() {
  lcd.clear();
  lcd.print("Serial: ");
  lcd.print(Serial.available());
  while (Serial.available()>0){
    //Read the incoming byte
    incomingByte = Serial.read();
    //Start the message when the '<' symbol is received
   lcd.setCursor(0, 1);
   int value = atoi(incomingByte);
   lcd.print(value);
  }
  delay(2000);

}

What was wrong with the receiver code in the original tutorial? Did it not work, or have you changed the packet format?

Howdy!

Since my last post, here are the updates I have made to get this setup to work:

I figured out that just using Serial.print(1) (or something similar) was not working for my XBees (not completely sure why). So, I ended up sending signals as frames (the way they are created in the XCTU working terminal) in which there is a start byte, length byte, dest. address byte, etc. The code for the Uno (initial transmitter) is below. This is the frame I am currently sending:

7E (start) 00 06 (length) 01 (frame type - transmit) 01 (frame ID) 00 88 (dest. address) 00 01 (data) 74 (checksum)

If I vary the dest. address of the frame packet to be something other than 0x0088 (Nano’s XBee MY) the Nano XBee doesn’t even acknowledge the signal, which is fine.

Thus, I changed the Nano (initial receiver) code to now parse this frame that it receives. In the Nano code below, I am checking msg[8] because that index is the least significant bits of the data in the frame (I’m only sending 0-2, so I don’t need to look at the MSB).

So, this is the functionality of the system now:

  • The Uno sends the above transmit frame to the Nano via XBees
  • Upon receiving the frame, the Nano parses the signal, interprets the data sent, then continuously blinks an LED and LCD if the data is a 1 or 2
  • I then press a push button connected to the Nano, which enables an interrupt that resets the system to display an ‘all good’ message on the LCD

The final step I would like to implement is upon pushing the reset button on the Nano’s system, in addition to resetting it’s own components, I want to send a signal back to the Uno so that the Uno can reset it’s systems as well.

I have been able to accomplish this when using the XCTU working terminal instead of the Nano to send this frame:

7E 00 06 01 01 00 77 00 00 86

However, when I try to send the same frame through the Nano (in the Nano code below) the Uno does not acknowledge it. I’ve triple checked my connections, and as seen in the code below, tried using different digital pins with Software Serial to send the signal as well. No matter what I do, I can’t seem to get the Uno system to recognize the transmit frame when sent from the Nano, just from XCTU. I’ve also tried changing the frame parameters (dest. address to 0xFFFE for broadcast) and that didn’t help either.

Any suggestions as to what I could try next to accomplish this last goal would be very helpful!

(Note: I am attaching the Nano code because I exceeded the character limit)

Uno code:

#include <SoftwareSerial.h>

bool started = false;
int incomingByte;
int msg[10];
byte index;
bool messageSent = false;
SoftwareSerial mySerial(2, 3); //RX, TX

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW); //signal no message sent
  index = 0;
  delay(3000);
}

void loop() {
  started = false;
  while(mySerial.available() > 0) {
    //check reset signal 
    //read incoming byte
    incomingByte = mySerial.read();
      //read the message!
      if (index < 10) { //room for message
        msg[index] = incomingByte;
        index++;
        msg[index] = '\0'; //add null to end
        if (index == 9) { 
          started = true; 
          }
      }
        
  }
  
  if (started) {
    //interpret message
   /// if (msg[8] == 0) { //indeed reset signal
      digitalWrite(LED_BUILTIN, HIGH); //keep high
    //}
  }
  else if (!messageSent) {
    //send my data
    delay(2000);
    Serial.write(0x7E);
    Serial.write(0x00);
    Serial.write(0x06);
    Serial.write(0x01);
    Serial.write(0x01);
    Serial.write(0x00);
    Serial.write(0x88);
    Serial.write(0x00);
    Serial.write(0x01); //right now determines GET malfunction
    Serial.write(0x74);
    messageSent = true;
  }
  else {
    //reset msg?
    incomingByte = 0;
    index = 0;
    msg[index] = '\0';
  }

}

403_Cabin_System.ino (5.31 KB)

Have you looked at the Xbee API mode?
See GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode