Home/Support/Support Forum/xbee pro s2b receiving random data

xbee pro s2b receiving random data

0 votes
Hello, I have a trouble with xbee s2b.

I try to receive two joystick values using only xbee placed on sparkfun regulated board (Coordinator API) and process these data on Arduino Uno connected to other xbee s2b placed on explorer board.(Router API). I configured xbees using X-CTU properly and I adjusted DIO0 and DIO1 to ADC[2] on Router Xbee. There is no problem when working with one joystick. But when I try to receive two joystick values at the same time, they are not working correctly. When I look the incoming data on serial monitor, I see;

https://lh3.googleusercontent.com/-20vjr0EchsQ/VqyZXgq84VI/AAAAAAAAA_0/WhEtoOU61vA/s1280-Ic42/Screenshot_3.jpg

My Arduino code is:

int packet[32];

void setup()
{
Serial.begin(9600);
}

void loop(){
if (Serial.available() > 0) {
if (Serial.read() == 0x7E) {
packet[0] = 0x7E; //start delimiter
packet[1] = readByte(); //MSB1
packet[2] = readByte(); //MSB2
int dataLength = (packet[1] << 8) | packet[2]; //between the length and the checksum

printPacket(dataLength+4);
Serial.println("");
}
}
delay(1000);
}
void printPacket(int k) {
for(int i=0; i < k; i++) {
Serial.print(packet, HEX);
Serial.print(" ");
delay(1000);
}
}
int readByte() {
while (true) {
if (Serial.available() > 0) {
return Serial.read();
}
}
}

What is the point I missed? Can you help me about this issue. Thank you in advance.
asked Jan 31, 2016 in ZigBee PRO Featureset (and legacy ZNet 2.5) by eypecks New to the Community (1 point)

Please log in or register to answer this question.

2 Answers

0 votes
You need to decode the specific bits used.
answered Feb 1, 2016 by mvut Veteran of the Digi Community (11,963 points)
0 votes
Yes. I am sure the code is wrong and I cannot decode the bytes I need whatever I do. I changed the code to this to see API frame completely:

void setup(){
Serial.begin(9600);
}

void loop(){
if(Serial.available() >= 23){
for(int i = 0; i < 24; i++){
Serial.print(Serial.read(),HEX);
Serial.print(",");
}
Serial.println();
}
}

The incoming bytes in the buffer;

7E,0,14,92,0,13,A2,0,40,E6,74,D1,3D,35,1,1,0,0,C,0,63,0,4F,1A

I need to take the first analog sample which consist of 0 and 63 and second analog sample which consists of 0 and 4F from the buffer. But whatever I wrote the code, I took those values (' 0,63,0,4F ') just for a while and then analog samples are getting random for example I begin to take ' 0,13,A2,0 ' ??!! I don't understend why isn't it stable.

Can you suggest a way to me to take these bytes from this array.
answered Feb 2, 2016 by eypecks New to the Community (1 point)
I would suggest looking at Digi's Python AIO adapter lib file.  It shows exactly how to do it with Python.
...