I am using QtSerialPort to send and receive data from Arduino. I am sending more than 64 bytes (125, 220, more), I receive the data with Arduino, and trying to sending back the same data, but Arduino sending only 64 bytes in its response. Then I am thinking that the problem is with Arduino buffer. I am trying to clear the data but without result.
Here is my Arduino code:
void loop() {
if (Serial.available() > 0) {
int i = 0;
delay(500);
int size = Serial.available();
while (i < size)
buffer[i++] = Serial.read();
Serial.print(buffer);
//delay(500);
int j = 0;
while (j < size)
buffer[j++] = '\0';
//while (Serial.available()) Serial.read(); I tried it
//Serial.flush(); Also tried it, but nothing.
}
}
delay(500)
: during this delay, you are letting the internal buffer ofSerial
overflow. Instead of just wasting 500 ms, you should be copying the incoming data into your ownbuffer
array as it comes.