3

I want to use xbee's to communicate between two different arduinos. I'm using this tutorial as a guide to setup my xbee's. I've already used XCTU to setup one xbee as a router and another as a coordinator (both in ZIGBEE AT mode). I used XCTU's terminal feature to verify that info was being sent and received properly.

Basically, I have both arduinos connected to the same PC via USB cables, but the communication is taking place through the Xbee's. I also made sure to disconnect the TX & RX wires when uploading the sketches to avoid an AVRDUDE error.

I wanted to test the communication by sending a "hello world" message once every five seconds, from the router to the coordinator. To do this, I wrote the following code:

//Code for Arduino attached to Xbee in Router AT mode
void setup(){
 Serial.begin(9600); 
}

void loop(){
  Serial.println("Hello World!");
  delay(5000);
}

and

//Code for Arduino attached to Xbee in Coordinator AT mode
void setup(){
  Serial.begin(9600); 
}

void loop(){
  if (Serial.available()>0){
    Serial.write(Serial.read());
  }
}

I checked the serial monitor for the arduino connected to the router, and it does exactly what I expected to see: a new Hello World message once every 5 seconds. However, the serial monitor on the arduino connected to the coordinator does not produce the desired effect: the "hello world" message instantly displays the message over a hundred times per second and repeats without end, each time on a separate, new line. Sometimes, when I turn the serial monitor on, the message instantly appears with a few repetitions before displaying some strange characters and stopping altogether.

I'm not sure if the problem is with the serial monitor or with the xbee. Any help with this problem would be greatly appreciated.

1

Code is correct and it does what it is asked to. The receiver code reads the RX pin of arduino which is connected to the Xbee. The same pin is used by the FT232 interface IC to send data to your computer through USB.

The "hello world" you send is received by the Xbee and is send to microcontroller and FT232 at same time as that pin is shared between them. Thus the "hello world" will be seen in serial monitor, first time from Xbee and second time, from Serial.write(Serial.read()) of the program.

Also check whether the settings are correct from this tutorial, as Xbee will not be configured as P2P.

enter image description here

  • But why would the message repeat infinitely and fill up the serial monitor at a rate faster than one message every 5 seconds? – Paul Aug 12 '14 at 14:17
  • The problem is that the message repeats over a hundred times a second, much faster than the "once per 5 seconds" that the message is being sent from the other xbee. Why would this happen? – Paul Aug 12 '14 at 15:03
  • Did you check the baud rate configured for xbee and serial monitor is same as in the code (9600)? – gmuraleekrishna Aug 12 '14 at 18:22
  • I checked, and it was, in fact, set to 9600 baud rate. – Paul Aug 12 '14 at 19:58
  • Is there any way to work around this problem? I just want to be sure that the data that was sent is received and displayed at the proper speed in which it was sent. – Paul Aug 19 '14 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.