Xbee recieving data but arduino gets stuck while reading

Hey all,

This is my first time posting a thread I would really appreciate some insight here. I am using two xbee transceivers with sparkfun shields, they are being used through one Arduino due (receiver) and one Arduino mega 2560 (transmitter) to send and receive signals to move a stepper motor remotely. Right now all I am trying to do is send simple data from the transmitter, the '12345", and just have the Serial print it out on the other side of the receiver. The issue I'm having is when I send the data, I can even find that the receiver is receiving the data as the Serial prints "received" but then stops. I found that when I unplug the a cable on either side only then would it output the results in the Serial, BUT it prints it over and over, as in "123451234512345123451234512345", as if it had stored all the digits it was reading from the continuous signal. I hope I did a well enough job explaining my issue. I have also tried multiple different arduino boards, different shields, different xbee's and I get the same result across all of them. The RSSI light is on for both shields and like I said earlier, they are communicating, the other xbee is getting the data its just not printing. Here is the codes:

Transmitter:

void setup() {
  Serial.begin(9600);
//   Serial1.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  Serial1.print("12345");
  Serial.println("sent");
  // delay(2); 
  // if(Serial2.available() > 0){
  //   Serial.println(Serial2.readString());
  // }
  delay(100);
}

Reciever:

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

void loop() {
  Serial.println("waiting");
  if(Serial1.available() > 0){
        Serial.println("received");
    String temp = Serial1.readString();
    Serial.println(temp);
    Serial.println("done");
  }
  delay(1000);
}

Also here is an example of the results I'm getting on the receivers side in the serial monitor.

Update: I found that if I increase the delay to 5 seconds on the transmitter side the receiver can differentiate between each "packet" that was sent to it, is there any way to be able to adjust this to be able to keep a smaller delay?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.