Go Down

Topic: [SOLVED (Workaround solution)] Arduino Xbee to USB Xbee Communication Problem (Read 255 times) previous topic - next topic

LawrenceFrance

Hi :) So I've got two Xbee Pro S2C 802.15.4 modules configured in API [1] mode. They communicate with each other fine while connected using USB explorers to my computer and using XCTU. (One is set as the Coordinator, the other as the End.)

I am now trying to get one Xbee, which is mounted on an Xbee shield on an Arduino Uno, to transmit data to the other Xbee, which is still connected by a USB explorer to my computer.

I have used an almost direct copy of Andrew Rapp's example code for Xbee Arduino API frame transmission, found HERE. Here's the version of that code I'm using:

Code: [Select]
#include <XBee.h>

//XBee radio object
XBee xbee = XBee();

//Starting time for reference
int start = millis();

//Creating the frame to transmit \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Syntax for transmitting to 64 bit address is:
//Tx64Request frame = Tx64Request(64bitaddress,char_payload,sizeof(char_payload));
//Syntax of 64bitaddress is:
//XBeeAddress64 addr64 = XBeeAddress64(0xSerialHigh,0xSerialLow);


XBeeAddress64 addr64 = XBeeAddress64(0x0013a200,0x4103f12a);    
uint8_t payload[] = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!'};
Tx64Request tx = Tx64Request(addr64,payload,sizeof(payload));

//Transmit status object
TxStatusResponse txStatus = TxStatusResponse();

void setup(){

  Serial.begin(9600);
  xbee.setSerial(Serial);
    
}

void loop() {
    
    // SEND \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    
    if (millis()-start>15000) { //start sending after delay (this was in example)
    
      xbee.send(tx); //send the frame we made

    }

    // Now we expect to receive a status response
    // Wait 5 seconds for one
    if (xbee.readPacket(5000)){

      //Serial.println("got response");

      
      // Check API ID of response (sent status) if sent status is present
      if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {

          //assign response to txStatus object
          xbee.getResponse().getTxStatusResponse(txStatus);

          //if this status is successful sending of frame
          if (txStatus.getStatus() == SUCCESS) {
            //Serial.println("awesome");
          }

          //unsuccessful sending frame
          else {
            //Serial.println("not received");
          }
      }
    }

    //we get a response, but it's an error
    else if (xbee.getResponse().isError()) {
      //Serial.println("Response error");
    }

    //we don't get a response
    else {
      //Serial.println("No response");
    }
      
    
    delay(1000);
}



The MAC addresses of each module are:
COORD 0013A200 40EB6583
END 0013A200 4103F12A

Right now, I am getting no signs of contact between the two modules. I see nothing in XCTU  - the Sent/Received frames list, nor the Serial Console.

What appears in the Serial Monitor window of the Arduino IDE during each transmission loop is the following string:

~��}3�A��*Hello, world!a


Can anyone spot any problems? I've looked around the forum for similar problems, but most people seem to get past this point!

Thanks

LawrenceFrance

After some physical troubleshooting, I have come up with a workaround.

By hooking up the Serial of the Arduino to a USB Explorer (so no physical Xbees were involved) I could use XCTU to view what the bytes written to the Serial in the XCTU Serial Console. For a frame with data "hi", the bytes written to the Serial should have been:

7E 00 0D 00 01 00 7D 33 A2 00 41 03 F1 2A 00 68 69 19

Instead Xbee::send() would write these bytes to the Serial:

7E 00 10 10 01 00 7D 33 A2 00 41 03 F1 2A FF FE 00 00 48 69 2C

Which looks like it incorrectly processed "hi", thereby changing the checksum and length bytes. And unsurprisingly in the DIGI literature it states that the Xbee will not send if the checksum does not checkout 8) which explains why the frame was not sent even though it looks like it could be.

I ended up manually rewriting the Xbee::send() function in my code, which now works well. I construct the frame into a giant String, then use String::getBytes() to produce a uint8_t array for writing to the Serial.

Therefore I am not using the Xbee.h library at all. I suspect the library may not be fully compatible with the S2C modules and a few bugs occur while creating an API frame.

I hope this may help someone somewhere!

Pgchaer

heyy
if you can provide us with the code that would be really helpful since i still didn't find a good library for the S2C and stuck

symmer10

I may be wrong but I tried multiple times with XBee S2 in API-1 mode..and I could not recieve any data on XCTU.

I have learned that the XBee need to be set in API-2 mode and for me it worked. May be you wanna give it a try.

(it's never late to share something you know ..so as to learn)

Go Up