Better way to code XBee remote control for robot.

I’m trying to figure out how to control a pair of servos using a couple of arduinos and XBees.
This is the code sent from the remote:

void printData(){

and this is the code read by the receiver.

  while (!Serial1.available()) {}
      if (incomingByte == 255){
        x =;
      if (incomingByte == 254){
        y =;

I think what’s happening is that the receiver can’t keep up with stream coming from the remote. I’ve spent a while working on it, and my next ideas are to use a handshake (I really haven’t figured out how to do this yet) or to add a delay in the remote to slow down the stream).

If anyone can point me in the right direction, or knows where someone else has successfully done this it would be some help. I got this code from google.


You're missing a couple of

You've not said much for anyone to offer any help. Do you even have
the XBee comm link working between the 2 Arduinos? That's step #1.

I would first write the same code for both ends, and run 2 terminal
emulator programs, and simply type in characters on each end for
display on the other end. Then, add on the servo code.

Link is working. I can see the values being sent when when the receiving xbee is connected to the terminal. When it was working there was a pretty long delay between when I told it to send and when the robot moved.

I really want to know if this is a goods way of coding what I wasn't to do, or if there is a better way.

In S2 XBee networks in API mode, for single-hop transmissions, I have typically observed times of 20-30 ms between transmission and receipt of the ack.

Hmmm, I'm using an XBee 1. So I've slowed down the data rate quite a bit, but I'm still having the issue. From what I've read up on it might be a syncing issue or an overflow issue. I don't know which or how to fix it. The search continues. Thanks everyone so far for you input.