So, inside the super loop, I am getting the data from the GPS (i used serial2 (uart2)), gps sensor sends it every 200 ms.
My question:
Does an arduino reads the data from buffer in parallel or not? I mean what if the arduino will be make another stuff when gps sends the data ? Will the these data be read or not? Sometimes I got trash or incomplete data, is the problem associate with timings ?
example of incomplete data
$GNGGA,114728.00,5018.06879,N,12730.70747,E,1,13,0.81,143.5,M,9.8,M,,*7A
Lat: 5018.06879N Long: 12730.70747E
$GNGGA,114729.00,5018.06933,N,12730.70688,E,1,13,0.81,143.7,M,9.8,M,,*74
Lat: 5018.06933N Long: 12730.70688E
$GNGGA,114729.00,5018.06933,N,12730.70688,E,1,13,0.81,143.7,M,9.8,M,,*74
Lat: 5018.06933N Long: 12730.70688E
$GNGGA,114729.00,5018.06933,N,12730.70688,E,1,13,0.81,143.7,M,9.8,M,,*74
Lat: 5018.06933N Long: 12730.70688E
18.07022,N,12730.70662,E,1,12,0.88,144.5,M,9.8,M,,*7C
Lat: Long:
18.07022,N,12730.70662,E,1,12,0.88,144.5,M,9.8,M,,*7C
Lat: Long:
$GNGGA,114732.00,5018.07070,N,12730.70651,E,1,12,0.88,144.5,M,9.8,M,,*78
Lat: 5018.07070N Long: 12730.70651E
$GNGGA,114732.00,5018.07070,N,12730.70651,E,1,12,0.88,144.5,M,9.8,M,,*78
Lat: 5018.07070N Long: 12730.70651E
$GNGGA,114733.00,5018.07096,N,12730.70637,E,1,12,0.88,143.9,M,9.8,M,,*7A
Lat: 5018.07096N Long: 12730.70637E
Example of code
void loop() {
static char buff_GGA[nmea_size];
static String GGA = "";
static size_t pos;
int counter;
static int bothStrings;
while (Serial2.available() && pos <= nmea_size) {
char c = Serial2.read();
if (c != '\n' && c != '\r') {
buff_GGA[pos++] = c;
}
if (c == '\n') {
buff_GGA[pos++] = '\0';
GGA = buff_GGA;
pos = 0;
}
if (pos >= nmea_size){ pos = 0;}
}
// $GNGGA,150550.00,5018.10764,N,12730.68759,E,1,05,7.62,150.9,M,9.8,M,,*76
if (millis() - timer >= 500) {
Serial.println(S);
coords = getCoordinates(S);
Serial.println(coords[0]);
Serial.println(coords[1]);
file = SD.open("gps.txt", FILE_WRITE);
if (file) {
file.println(GGA);
file.print("Lat: "); file.print(coords[0]); file.print('\t');
file.print("Long: "); file.println(coords[1]);
file.close();
}
timer = millis();
}
}