1

I have an Arduino Uno with a Wireless SD Shield and XBee S1 and a PC with another XBee S1 connected to it. What I'm after is for me to be able to send a message from my computer and receive a message back from the Arduino (For now let's just say if the Arduino receives a "1" I want it to send an "A" back) Here is the code I have been practicing with (courtesy of SparkFun)

#include <SoftwareSerial.h>
SoftwareSerial XBee(0, 1); // RX, TX

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

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

(I have changed the pins from 2,3 to 0,1 as the latter is on the Arduino itself) I have set my Xbees up and have been able to get them to talk to each other when both connected to separate PC's, but I am having trouble getting the Arduino to send information to the other XBee. When I try and send data from the Arduino IDE both RX and TX Led's flash. Could anyone steer me in the right direction?

1
  • 1
    I have changed the pins from 2,3 to 0,1 - change it back, no wonder it doesn't work. You can't have HardwareSerial and SoftwareSerial on the same two pins. It doesn't make any kind of sense.
    – Nick Gammon
    Feb 26, 2016 at 6:13

2 Answers 2

2

You don't need to declare an extra (software) serial port because the wireless shield connects the Arduino TX and RX on pins 0 and 1 directly to the TX and RX of the Xbee. So, Serial.available, Serial.read and Serial.write directly addresses the xbee. Just leave out the software serial from your code and it should work.

2

Pin 0 and 1 are the Hardware Serial of Arduino you cannot use it as the software serial and I also used that code once use pin 2 and 3 its issue regarding the configuration of your XBEE? Check your XBEE configuration XCTU

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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