Hi,
So I have a bot with an Arduino Nano and an Arduino Mega. The Nano sends some data to the Mega using 3 Serial.println() statements at a time for 3 long values respectively based on sensor data at regular intervals. I want to read these sets of 3 values in the Mega into an array for the long integers. I tried the following code:
long data[3];
while (Serial3.available() == 0) {
data[0] = 0;
data[1] = 0;
data[2] = 0;
}
if (Serial3.available() >= 3) {
for (int i=0; i<3; i++) {
data[i] = Serial3.read();
}
Serial3.flush();
}
When I then write the values in data[] to the serial monitor to check them, I don't get the correct values. Any help to solve this is appreciated.