Arduino to Arduino using XBee serial Communication, receiving weird data

I have a setup where two xbee modules are talking to each other, both using xbee shields, one attached to an uno arduino and the other a mega arduino. One xbee sends the data and the other receives it and prints it to an LCD display. Currently, I am just in the testing stage so I am using a random number, in this case 1537. Later, this value will be used to indicate the amount of time the xbee should go to sleep. Currently, I am recording each value separately and combining them later. However, the data that is received and printed to the LCD is quite odd. It is as follows:

49 4294967295 4294967295 4294967295

I realize that the values sent are in ASCII which makes sense for the first byte received, the 49 which is equal to 1 as it should be, however the other three received bytes are all the same and a very large number at that, 4294967295. Does this number have some significance or does it have something to do with my code? Any assistance would be greatly appreciated. My code is below.

Sending XBee:

const int ledPin = 13; unsigned long sleepPeriod = 1537;

void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); }

void loop() { Serial.print(sleepPeriod); digitalWrite(ledPin, HIGH); delay(sleepPeriod); digitalWrite(ledPin, LOW);


Receiving XBee:

const int ledPin = 13; // the pin that the LED is attached to

unsigned long sleepPeriod=0; //set sleep variable low unsigned long sleepPeriod1=0; //set sleep variable low unsigned long sleepPeriod2=0; //set sleep variable low unsigned long sleepPeriod3=0; //set sleep variable low unsigned long sleepPeriod4=0; //set sleep variable low

void setup() { // initialize serial communication: Serial.begin(9600);//xbee baudrate Serial1.begin(9600); //start lcd // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); Serial1.print("Sleep Test"); delay(1000); Serial.flush(); clearLCD();


void loop() {

if(Serial.available()) { clearLCD(); //read the values in the buffer;;;;

//print all the received values Serial1.print(sleepPeriod1); Serial1.print(" "); Serial1.print(sleepPeriod2); Serial1.print(" "); Serial1.print(sleepPeriod3); Serial1.print(" "); Serial1.print(sleepPeriod4); Serial1.print(" "); } }

void clearLCD() { Serial1.print(0xC, BYTE); //clear command for my lcd }

How are the XBees configured? AT/API mode?


AT mode.

     //read the values in the buffer;;;;

If there is a value to be read, read all 4 of them. Ok. So, how’s that working out for you?

I see my problem now. Thanks. A second pair of eyes always helps.