Hello,
I have a problem in transferring data through from my xbees.
Here's the issue described as much in detail as I can.
I have two Xbees: 1 setup as Coordinator AT and another one as Router AT.
One of them is connected to a teensy and another uses the Sparkfun Xbee explorer breakout (irrelevant to my problem)
I created this sample code just to see if data transfer would happen properly.
int rpmCounter = 1000;
int speedCounter = 10;
int gps = 1;
int gear = 0;
int throttle = 50;
int testPin = 13;
void setup()
{
Serial1.begin(9600);
pinMode(testPin, OUTPUT);
}
void loop()
{
Serial1.print(rpmCounter);
Serial1.print(",");
Serial1.print(speedCounter);
Serial1.print(",");
Serial1.print(gps);
Serial1.print(",");
Serial1.print(gear);
Serial1.print(",");
Serial1.println( throttle);
digitalWrite(testPin, HIGH);
delay(150);
rpmCounter += 500;
speedCounter += 10;
delay(5);
gear += 1;
throttle += 4;
if (rpmCounter > 14200)
rpmCounter = 1000;
if (speedCounter > 85)
speedCounter = 10;
if (gear > 6)
gear = 1;
if (throttle > 99)
throttle = 50;
digitalWrite(testPin, LOW);
delay(50);
}
This creates a line of output that looks like (xxxx,xx,x,x) i.e. a CSV.
The Xbee sends this fine. When I use a normal XCTU terminal to receive it I can see it fine in the
xxxx,xx,x,x
xxxx,xx,x,x
xxxx,xx,x,x
xxxx,xx,x,x
format which is right.
As you can see this is some sort of vehicle telemetry system. So I have a c# file that collects this xxxx,xx,x,x string. Splits it up into different mini strings (using string.split(',') ) and displays them in appropriate locations.
This should work fine in theory.
When I tried running it, I saw that one xbee sends data fine, the second xbee is receiving it and it fine. Theoretically, the first xxxx should go to the RPM display label and the next xx to speed label and so forth. The only issue is when I'm running it I can see numbers change but they are all over the place. Sometimes speed gets displayed in the gps label and gear in the rpm label etc.
So I checked what the input was coming in and found that while the XCTU terminal would format it appropriately to show
xxxx,xx,x,x
xxxx,xx,x,x
they werent coming in that way. Data was coming in weird. So I captured the input data and this is what I saw. (See attached images)
How do I ensure that the same size data comes in every time so when the function splits it its the right order.

