Hi, I am trying to send an array of values wirelessly from one arduino to another via xbee serial comm and I’m having some issues,weird thing is the first 15 or so sets of array values I receive are in perfect order as I want them but after that I start to get some random values(all integers) and I was wondering if any one knows how to help me out.
I don’t think there’s anything wrong with my code but a different set of eyes wont hurt
p.s …the values here are just dummy data for testing and yes xbees have the same baudrate
code for sending… arduino
int x = 1100;
int y = 300;
byte z = 8;
byte d = 5;
void setup() {
Serial.begin(115200);
}
void loop() {
sendData();
// Serial.flush();
}
void sendData() // function to send data over serial.port
{
byte buf[] = {'<', 0, 0, 0, 0, 0, 0, '>'}; //bytes for data
byte len = 8; // length of bytes to send
buf[1] = (x >> 8) & 0xFF; //MSB
buf[2] = (x) & 0xFF; //LSB
buf[3] = (y >> 8) & 0xFF; //MSB
buf[4] = (y) & 0xFF; //LSB
buf[5] = z;
buf[6] = d ;
Serial.write(buf, len);
return;
}
code for receiving arduino
byte buf [7];
void setup(void)
{
Serial.begin(115200);
}
void loop(void)
{
int arr[4];
if (Serial.available() > 0){
Serial.readBytesUntil('>', buf, 7);
arr[0] = (buf[1] << 8) | buf[2] & 0xFF;
arr[1] = (buf[3] << 8) | buf[4] & 0xFF;
arr[2] = buf[5];
arr[3] = buf[6];
for (int i = 0 ; i < 4 ; i++) {
Serial.print(arr[i]);
Serial.print(" ");
Serial.println(i);
}
delay(1000);
}
}
#note … I have used code similar to this method for a “arduino to processing” communication. to send values to processing and it works fine