0

I have two XBees:

  • One is a router AT reading and sending analog data from one analog pin.
  • The other is a coordinator API connected to an Arduino Mega serial port (rx1 and tx1).

Whenever I try to read from the XBee serial in the Arduino, the readings are mostly zeros (instead of data packets as they should be).

It must be noted that using xctu terminal or any other terminal I can read the correct data with no problems whatsoever.

Here is some sample code I'm using:

void setup() {
    Serial1.begin(9600); // Here the XBee is connected
    Serial.begin(9600);
}

void loop() {
    if (Serial1.available()){
        Serial.print(Serial1.read());
    }
2
  • You have to check the connection between Xbee and the Arduino. It must be [Tx(arduino) <=> Rx(Xbee)] & [Rx(arduino) <=> Tx(Xbee)]. Commented Oct 3, 2016 at 9:56
  • Isn't there a "}" missing in loop()? Or does loop() contain more code than shown? Or more code in the if clause? Commented Oct 13, 2016 at 20:06

1 Answer 1

0

After hours upon hours I have finally been able to fix it. I don't know exactly why, but it seems that connecting tx1 and rx1 in reversed order has solved the problem, and now I can communicate between my XBees.

Sign up to request clarification or add additional context in comments.

1 Comment

You typically connect TX (Transmit) of one device to RX (Receive) on the other. Is that how you have it working now?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.