Pages: [1]   Go Down
Author Topic: Better way to code XBee remote control for robot.  (Read 1128 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

and this is the code read by the receiver.
Code:
  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.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: