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.

Paul
  • 371
  • 4
  • 16

1 Answers1

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

gmuraleekrishna
  • 183
  • 2
  • 6