Go Down

Topic: Better way to code XBee remote control for robot. (Read 1 time) previous topic - next topic

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:
Code: [Select]
void printData(){
  Serial.write(255);
  Serial.write(lSpeed2Mega);
  Serial.write(254);
  Serial.write(rSpeed2Mega);
}


and this is the code read by the receiver.
Code: [Select]
  while (!Serial1.available()) {}
      if (incomingByte == 255){
        x = Serial1.read();
      }
      if (incomingByte == 254){
        y = Serial1.read();
    }
  }


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.

Thanks.

dxw00d

You're missing a couple of Serial1.read()s.

oric_dan

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.

Jack Christensen

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.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

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.

Go Up