Losing Checksum Bytes on GPS

arduinogpsserial

I am losing the last bytes into the checksum on my gps unit found here http://www.adafruit.com/products/746. If I comment all lines out except for line 2, then all the bytes are recieved correctly. Is there a way to finish receiving the checksum bytes?

if (mySerial.available()) {
//      Serial.print((char)mySerial.read());
  char c1 = (char)mySerial.read();
  if (c1 == '$') {
    char a = (char)mySerial.read();
    delay(10);
    char b = (char)mySerial.read();
    delay(10);
    char c = (char)mySerial.read();
    delay(10);
    char d = (char)mySerial.read();
    delay(10);
    char e = (char)mySerial.read();
    delay(10);
//        Serial.print(a);
//         Serial.print(b);
//          Serial.print(c);
//           Serial.print(d);
//            Serial.print(e);
    if((a=='G') && (b=='P') && (c=='G') && (d=='G') && (e=='A')) {
//          Serial.println("Match");
    Serial.print(c1);
    Serial.print(a);
     Serial.print(b);
      Serial.print(c);
       Serial.print(d);
        Serial.print(e);
      for(int i = 0; i <= 69; i++) {

          into[i] = (char)mySerial.read();
//              delay(100);

      }
      for(int j = 0; j <= 69; j++) {
         Serial.print(into[j]); 
      }
      Serial.println("-");
    }
  }

}

Best Answer

Among other problems GPS NMEA sentences aren't normally fixed length, for example the sentence you posted in a comment with the missing checksum is:

$GPGGA,001837.000,4228.2583,N,09042.0065,W,1,9,0.96,245.2,M,-34.0,,M083,N,

If 10 instead of 9 satellites were in view that would become:

$GPGGA,001837.000,4228.2583,N,09042.0065,W,1,10,0.96,245.2,M,-34.0,,M083,N,

And the same will apply when your altitude becomes higher. This one doesn't appear to do so but some GPS receivers also drop trailing zeroes in decimal numbers so any sort of code that relies on a fixed length won't be reliable or portable. Also you are assuming the first character received is '$' which is normally the case but means your code won't recover from even a brief communications error.

The delays also shouldn't be necessary and at the moment printing the results is probably causing incoming characters to drop. You might be best to take a look around and find some existing code / projects that parse GPS sentences for a start and examine how they work.