Sending simple data to Arduino/Xbee module

Hi. This is probably going to be one of those questions… but even after a hundred hours on this stuff, I am still a beginner.

My question is pretty simple, though. I have device A and B. Device A is a properly wired Xbee and Arduino Uno on a breadboard. Device B is simply an Xbee on an explorer connected via USB to my computer. I am easily able to get the two to communicate, but I want to know how to send data from the Computer Xbee to the Arduino Xbee. Here is my code and I am wondering what is wrong.

#include <SoftwareSerial.h>

SoftwareSerial XBSerial = SoftwareSerial(2, 3);

int inByte = 0;

void setup()  {
  pinMode(9, OUTPUT);
  XBSerial.begin(9600);
  XBSerial.println("Setup finished.");
}

void loop()
{
  if (XBSerial.available()> 0) {
    inByte = XBSerial.read();
        if (inByte == 'R') {
          digitalWrite(9, HIGH);
        }else if (inByte == 'G') {
          digitalWrite(9, LOW);
    }
      else {
         digitalWrite(9, HIGH);
      }
              XBSerial.print((char)inByte);
  }
  delay(10);
}

As it shows, I want to be able to send the letter “R” or “G” from the Xbee using XCTU terminal to turn the LED on. However, I am realizing that this is probably impossible. I know Xbee uses AT commands such as +++, ATID, ATWR, etc. How can I get it to send a string command such as “R” to the other Xbee, which is then interpreted as a string by the Arduino?

As of right now, the only thing that works is the XCTU terminal will display “set up finished” although with some rather weird characters before it.

Furthermore, the portion of the code that turns on the LED regardless does not work, so there must be something wrong there as well…

Thank you.

Even if this is my code...

void loop()
{
  if (XBSerial.available()) digitalWrite(9, HIGH);
}

I cannot get the LED on..

To eliminate wiring issues, does the led come on if you remove the if?

I am easily able to get the two to communicate, but I want to know how to send data from the Computer Xbee to the Arduino Xbee.

Getting the XBees to communicate means that you send data from one XBee and the other receives it. If you KNOW that they are communicating, that means that you have some way of sending data to the one XBee for it to broadcast, and that the other XBee does something with the received data that illustrates that it received what was sent.

Given that, this:

but I want to know how to send data from the Computer Xbee to the Arduino Xbee.

doesn't make sense.

        if (inByte == 'R') {
          digitalWrite(9, HIGH);
        }else if (inByte == 'G') {
          digitalWrite(9, LOW);

R for on, G for off. Interesting choice of letters...

I know Xbee uses AT commands such as +++, ATID, ATWR, etc.

To enter programming mode, and to be programmed, yes. Once programmed, you do NOT use AT commands to send data.

wildbill:
To eliminate wiring issues, does the led come on if you remove the if?

Yes

PaulS:
Given that, this:

but I want to know how to send data from the Computer Xbee to the Arduino Xbee.

doesn't make sense.

Module A
Arduino Uno with Xbee set up in the TX/RX lines communicated via USB to computer (could be issue?)

Module B
Xbee on USB explorer device connected to same computer.

Using XCTU's terminal and Arduinos serial monitor, I can send data from Module A to Module B, but not opposite. What could be the problem? Why can I not enter data in the XCTU terminal and send it to Module A?

How about using Hyperterminal or Putty, instead of X-CTU to talk to the XBee on the Explorer?

PaulS:
How about using Hyperterminal or Putty, instead of X-CTU to talk to the XBee on the Explorer?

Why?

Why?

Why not? There is the possibility that a different serial interface application might produce different results.

I can’t seem to achieve anything with either of those =/

Ugh.... Xbee module was set to API for some reason...