Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ADAFRUIT GPS Library incorrect parsing with Ultimate GPS v3
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ADAFRUIT GPS Library incorrect parsing with Ultimate GPS v3

by eierschale65 on Mon Jul 13, 2020 1:21 pm

Hello,

I habe a problem with the Adafruit GPS Library using Arduino and the Ultimate GPS Breakout v3.

After parsing the nmea sentence, the output of GPS.latitude does not make sense, as a "0" is occasionally inserted before the decimal point.

First, the code, I'm using: (You will notice, that I use the example code oft Adafruit GPS library "GPS_SoftwareSerial_Parsing" with only minor changes)

Code: Select all | TOGGLE FULL SIZE
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// Connect the GPS TX (transmit) pin to Digital 8
// Connect the GPS RX (receive) pin to Digital 7

// you can change the pin numbers to match your wiring:
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true

void setup()
{

  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
  delay(5000);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);

  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time

  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  //GPS.sendCommand(PGCMD_ANTENNA);

  delay(1000);
  // Ask for firmware version
  //mySerial.println(PMTK_Q_RELEASE);
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if ((c) && (GPSECHO))
    Serial.write(c);

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer

//    Serial.print("\nTime: ");
//    if (GPS.hour < 10) { Serial.print('0'); }
//    Serial.print(GPS.hour, DEC); Serial.print(':');
//    if (GPS.minute < 10) { Serial.print('0'); }
//    Serial.print(GPS.minute, DEC); Serial.print(':');
//    if (GPS.seconds < 10) { Serial.print('0'); }
//    Serial.print(GPS.seconds, DEC); Serial.print('.');
//    if (GPS.milliseconds < 10) {
//      Serial.print("00");
//    } else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
//      Serial.print("0");
//    }
//    Serial.println(GPS.milliseconds);
//    Serial.print("Date: ");
//    Serial.print(GPS.day, DEC); Serial.print('/');
//    Serial.print(GPS.month, DEC); Serial.print("/20");
//    Serial.println(GPS.year, DEC);
//    Serial.print("Fix: "); Serial.print((int)GPS.fix);
//    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
//      Serial.print(", ");
//      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
//
//      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
//      Serial.print("Angle: "); Serial.println(GPS.angle);
//      Serial.print("Altitude: "); Serial.println(GPS.altitude);
//      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
    }
  }
}


This ist the output, I get on serial monitor (Note, that I manually "X.X"ed the longitude data for privacy reasons. This data ist otherwise correct):
Code: Select all | TOGGLE FULL SIZE
...
 Location: 49240.4960N
$GPGGA,160814.000,4924.4954,N,0X.X,E,1,07,1.26,269.1,M,47.8,M,,*60
$GPRMC,160814.000,A,4924.4954,N,0X.X,E,0.13,326.62,130720,,,A*61
$GPGGA,160815.000,4924.4954,N,0X.X,E,1,07,1.26,269.1,M,47.8,M,,*62
$GPRMC,160815.000,A,4924.4954,N,0X.X,E,0.22,350.82,130720,,,A*6E

 Location: 4924.4956N
$GPGGA,160816.000,4924.4955,N,0X.X,E,1,07,1.39,269.1,M,47.8,M,,*6E
$GPRMC,160816.000,A,4924.4955,N,0X.X,E,0.38,355.58,130720,,,A*65
$GPGGA,160817.000,4924.4957,N,0X.X,E,1,07,1.39,269.1,M,47.8,M,,*6D
$GPRMC,160817.000,A,4924.4957,N,0X.X,E,0.49,354.85,130720,,,A*61

 Location: 49240.4960N
$GPGGA,160818.000,4924.4958,N,0X.X,E,1,07,1.39,269.1,M,47.8,M,,*6D
$GPRMC,160818.000,A,4924.4958,N,0X.X,E,0.66,359.42,130720,,,A*6A
$GPGGA,160819.000,4924.4973,N,0X.X,E,1,07,1.39,269.5,M,47.8,M,,*60
$GPRMC,160819.000,A,4924.4973,N,0X.X,E,0.78,357.25,130720,,,A*63
...


You can see, that the nmea sentences are always correct, but the parsed latitude is approxmately in 90% of the cases wrong.

Other info of my setup:
Arduino: Pro Mini ATMega328P, 3.3V
Arduino SW Version: 1.8.12
Adafruit GPS Library Version: 1.5.0
GPS Module: Ultimate GPS Breakout v3

Im using the sofwareserial, because the hardwareserial is intended to be occupied by another application.
Things I already tried:
- restart device and GPS module
- changing NMEA output to RMCONLY or to GGAONLY
- changing update frequency to 5HZ or to 100_MILIHERTZ
- changing serial baudrate to 9600

Obviously none of that helped (the error remained).
Maybe I am overlooking something, but I really don't know how that error is happening. It must be while parsing the nmea sentence (Maybe in Adafruit_GPS::parseCoord in NMEA_pars.cpp?)
Do you have an idea, how I can solve that problem, without writing a nmea sentence parser myself?
I appreciate any ideas.

eierschale65
 
Posts: 4
Joined: Mon Jul 13, 2020 11:27 am

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by adafruit_support_carter on Wed Jul 15, 2020 1:29 pm

Just to make sure we follow the issue, you're expecting to see something like 1.23 and instead are seeing 01.23?

adafruit_support_carter
 
Posts: 16944
Joined: Tue Nov 29, 2016 2:45 pm

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by eierschale65 on Thu Jul 16, 2020 7:36 am

No, I am expeting 1,23 but I get 10,23

See monitor output: 4924.4956 ist what I want, but many times I get 49240.4956

eierschale65
 
Posts: 4
Joined: Mon Jul 13, 2020 11:27 am

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by adafruit_support_carter on Thu Jul 16, 2020 12:06 pm

OK, see that now. Thanks for clarifying.

Try using the sketch below to see if you can recreate the issue. You can try this with your actual NMEA sentences including the full location. Just paste it in to the #define at the top. If you want to change anything manually in the sentence, you'll need to recompute the checksum at the end. The URL links to a checksum calculator.

For now, just let us know if you can recreate it. No need to give actual location.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_GPS.h>

// Constructor for no communications, just data storage
Adafruit_GPS GPS;

// checksum calculator: https://nmeachecksum.eqth.net/
#define SENTENCE "$GPGGA,160814.000,4924.4954,N,08151.6838,E,1,07,1.26,269.1,M,47.8,M,,*6C"

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("GPS Parser Test");
 
  if (GPS.parse(SENTENCE)) {
    Serial.println(GPS.latitude);
    Serial.println(GPS.longitude);
    // add any other parameters of interest
  } else {
    Serial.println("Parser Error.");
  }

}

void loop() {
}

adafruit_support_carter
 
Posts: 16944
Joined: Tue Nov 29, 2016 2:45 pm

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by eierschale65 on Tue Jul 21, 2020 8:26 am

Thanks for your reply and suggestion.

with the code you provided, I can not really recreate the mistake. However when I put the if-statement into the loop, it still appears.
strangely it wil now insert a 1 instead of 0. And I also notice that the error occures always on the second print.

the used code:
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_GPS.h>

// Constructor for no communications, just data storage
Adafruit_GPS GPS;

// checksum calculator: https://nmeachecksum.eqth.net/
#define SENTENCE "$GPGGA,160814.000,4924.4954,N,08151.6838,E,1,07,1.26,269.1,M,47.8,M,,*6C"

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("GPS Parser Test");
 
 

}

void loop() {
  if (GPS.parse(SENTENCE)) {
    Serial.println(GPS.latitude);
    Serial.println(GPS.longitude);
    // add any other parameters of interest
  } else {
    Serial.println("Parser Error.");
  }
  delay(1000);
}


the output (I reuploaded the code several times):
Code: Select all | TOGGLE FULL SIZE
GPS Parser Test
4924.50
8151.68
49241.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
GPS Parser Test
4924.50
8151.68
49241.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
GPS Parser Test
4924.50
8151.68
49241.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
4924.50
8151.68
49241.50
8151.68
4924.50


I will investigate the regularity of the error and also play around with disabling Interrupts, just in case.

eierschale65
 
Posts: 4
Joined: Mon Jul 13, 2020 11:27 am

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by eierschale65 on Tue Jul 21, 2020 10:19 am

Ok i finally found out, what the problem was.

Apparently there was an issue with the Adafruit GPS library, but it got fixed in version 1.5.1

as far as I see it, a string buffer was not terminated correctly, which caused this srange error (in my case even with an arduino uno).
So updating the library resulted in correct parsing.

Thank you very much for your help anyway.

eierschale65
 
Posts: 4
Joined: Mon Jul 13, 2020 11:27 am

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by adafruit_support_carter on Tue Jul 21, 2020 10:39 am

Yah, something's up. Issue opened:
https://github.com/adafruit/Adafruit_GPS/issues/126

adafruit_support_carter
 
Posts: 16944
Joined: Tue Nov 29, 2016 2:45 pm

Re: ADAFRUIT GPS Library incorrect parsing with Ultimate GPS

by adafruit_support_carter on Tue Jul 21, 2020 11:04 am

Try updating to latest library release :)

adafruit_support_carter
 
Posts: 16944
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.