TinyGPS++ .speed. and .course.deg don't update as location.lng and location.lat

Hi Folks,

Using this samle code, on every loop I am able to see a new values for location.lng(), location.lat() and location.altitude.meters() but speed.kmph() and course.deg() are not updated at the same moment. Difficult to know what’s the frequency both are updated. My test was done in the car.

I want to know and be sure to update the speed and course.deg on every read. Thanks in advance

void readGPS(LocalisationGPS& Geo)
{

  while (Serial1.available() > 0)
  {
      if (gps.encode(Serial1.read()))
      {

        if (millis() - lastSerial >= SERIAL_PERIOD)
        {
          lastSerial = millis();

          if (gps.location.isValid() && gps.location.age() < MAX_GPS_AGE_MS)
          {

            Geo.longitude = String(gps.location.lng());
            Geo.latitude = String(gps.location.lat());
            Geo.altitude = String(gps.altitude.meters());
            Geo.speed = String(gps.speed.kmph());
            Geo.heading = String(gps.course.deg());
              
            Serial.print("lo:\t");Serial.println(Geo.longitude);
            Serial.print("la:\t");Serial.println(Geo.latitude);
            Serial.print("al:\t");Serial.println(Geo.altitude);
            Serial.print("sp:\t");Serial.println(Geo.speed);
            Serial.print("he:\t");Serial.println(Geo.heading);

            if (gettingFix)
            {
                gettingFix = false;
                unsigned long elapsed = millis() - startFix;
                Serial.printlnf("%lu milliseconds to get GPS fix", elapsed);
            }

          }
          else
          {
              Serial.println("no location");
              if (!gettingFix)
              {
                  gettingFix = true;
                  startFix = millis();
              }
          }
          
        }

      }
  }

}

The course data (speed and direction) is part of the GPRMC message that normally contains the location data, but the GNSS will leave it out when it’s not sure of the values. Because most inexpensive GNSS modules calculate the speed and direction via change in location data, not by an accelerometer and magnetic compass, and there can be considerable jitter in location data, especially when you can’t see a full constellation of satellites, course data is often omitted. Even when present it’s often not all that accurate in this type of GNSS. Higher precision GNSS modules that implement dead reckoning are better as they have an accelerometer as well.

3 Likes

Thanks @rickkas7.

If you have a suggestion for better GPS compatible with Boron LTE, please share it with me. Appreciate and thanks

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.