ArduinoGeneral

Arduino/XBee communication using the shield troubleshoot

userHead robbng 2016-06-24 05:09:56 2591 Views3 Replies
I have a project that I need an XBee (Call it A) to talk to another XBee (B). B then needs to talk to my Arduino UNO. So far i have a program on the Arduino that when I type in the Arduino serial monitor will output though B to A (Prints out in CoolTerm). However if I Type in the CoolTerm window A will send the message to B (definitely happens) however it does't print out in the Arduino serial monitor (so i assume the Arduino never got the signal).

I have included the code below, can someone give me some guidance on how to fix this. I think it may have something to do with the legs the DIN/DOUT connect to


CODE:

// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3); // RX, TX

void setup()
{
XBee.begin(9600);
Serial.begin(9600);
}

void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
}


EDIT:
this is the shield's SKU DFR0015
2016-06-29 02:35:22 That's good userHeadPic Wendy.Hu
2016-06-28 21:55:07 solved it!!

the issue with the code was in the setup. I guess i was opening to many serial channels as when removing the 'Serial.begin(9600)' line it works as intended.

Thanks for the help anyway
userHeadPic robbng
2016-06-24 23:30:39 Hi robbng ,

I read your code that maybe there are some problems you need to change. If you want to print out in the Arduino serial monitor, you need to add Serial.println() function, and the code as flows:
Code: Select all
void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
Serial.println(XBee.write());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
Serial.println(Serial.write());
}
}


Hope this will help you!
userHeadPic Wendy.Hu