0
votes

I use Xbee in my project with arduino. I have set up Xbee configuration(i can send massge in xctu serial consol), but i have problems with arduino code. I try to use "SoftwareSerial" library, but it doesn't work properly. For example I send data using Xctu, but Xbee connected to arduino cannot receive data. Can you please help me with receiver and transmiter arduino code? Thank you, in advance.

The code:

#include <SoftwareSerial.h>
#define rxPin 1 
#define txPin 0

SoftwareSerial xbee =  SoftwareSerial(rxPin, txPin);

void setup(){

xbee.begin(9600);
Serial.begin(9600);
//Serial.println("Starting XBee Comunication");
xbee.listen();
}


void loop(){

if(Serial.available()){
xbee.write(Serial.read());
}
else{
Serial.println("not available");
}


if(xbee.available()){

byte x = xbee.peek();
Serial.println(x);

}
else{
Serial.println("none to read"); 
}

delay(2000);
//Serial.println(rec);
}
1

1 Answers

0
votes

Some quick debugging tips:

  • Disconnect the XBee and short your TX and RX pins together. Make sure you read back what you send.
  • Are you sure you have the TX and RX pins connected to the XBee module correctly? TX out of the Arduino goes to RX of the XBee and vice versa.
  • Have you powered the XBee module correctly? XCTU should have support for finding nodes on the network and interacting with them. Make sure the module is powered up and responding on the network.