TinyGPSPlus: isUpdated()-qustion

In a sketch I have this:

if (gps.date.isUpdated()) {
    utcYear = gps.date.year();
    utcMonth = gps.date.month();
    utcDay = gps.date.day();
  }

What exactly is meant by "updated"?

Approximately how often can I expect such an update to happen?

Is it important to test the condition - gps.date.isUpdated() - before I use gps.date.month() and the others?

Described in the TinyGPS++ documentation: Validity, Update status, and Age section.

From the documentation;

" Similarly, isUpdated() indicates whether the object’s value has been updated (not necessarily changed) since the last time you queried it."

Hello,

The example code below gives me the correct position:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 7, TXPin = 8;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup() {
  Serial.begin(115200);
  ss.begin(GPSBaud);
}

void loop() {
  // This sketch displays information every time a new sentence is correctly encoded.

  while (ss.available() > 0) {
    gps.encode(ss.read());
    if (gps.location.isUpdated()) {
      Serial.print(gps.location.lat(), 6);
      Serial.print(", ");
      Serial.println(gps.location.lng(), 6);
    }
  }
}

However, if I insert this:

  while (!gps.location.isValid()) {
    Serial.println("Waiting");
    delay(5000);
  }

right after void loop() {

it keeps printing "Waiting" even though I a few seconds earlier saw it deliver correct position consistently. When I comment the inserted while{} back out, the correct position resumes.

It doesn't make sense to me. I would expect the while{} to make no change (as long as the gps-lock is unchanged).

What is going on? What do I miss?

Is this what your code looks like:

void loop() {
  while (!gps.location.isValid()) {
    Serial.println("Waiting");
    delay(5000);
  }

  while (ss.available() > 0) {
    gps.encode(ss.read());
    if (gps.location.isUpdated()) {
      Serial.print(gps.location.lat(), 6);
      Serial.print(", ");
      Serial.println(gps.location.lng(), 6);
    }
  }
}

If so, then you will never get out of the while() loop. Initially gps.location.isValid() will be false, because TinyGPS has not received any valid GPS data. You are not feeding data from the SoftwareSerial port into TinyGPS within this while() loop, so there is nothing that will ever change isValid() to true.

@nfoldager ,

Your two or more topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Thanks for merging my posts. I'm sorry to be an inconvenience. Of course, I do not want to abuse the efforts of volunteers.

I wouldn't have asked two questions if I thought they were the same. However, it can be difficult to assess when you, as a newbie, do not have enough insight into the subject. That is why you ask.

The first question was about what exactly Updated means; technically. In response, I simply received a reference to the documentation, which I had already read, but did not fully understand. The second question was about a while() whose behavior I did not understand.

It's hard being a newbie.

@david_2018

Thank you for your kind reply.

Yes, that was the code. A small experiment that should help me get safe data. But that While() was driving me crazy. I hadn't understood the nature of serial input in a program, so that's a fine point you make.

Would you mind modifying the small code sample to show proper usage of these functions?

The delay(5000) ensures that location will never be valid, because the program is executing delay() and therefore, not reading the GPS unit.

You really need to read the documentation again, and maybe again, until it starts to sink in. If there is something that you do not understand in the docs, you can ask a focused question on this forum.

For example, the docs state this Hint: don’t use delay() in your sketch.

The bit I quoted was;

" Similarly, isUpdated() indicates whether the object’s value has been updated (not necessarily changed) since the last time you queried it."

So if your code reads the Latitude, in order to print it or do a calculation, the TinyGPSplus library code will set a flag, lets assume its to 0. The next time encode() actually decodes the latitude from the characters read from the GPS, then it checks the flag, sees its 0 and sets it to 1. When you do an isUpdated() the library code knows the latitude has been read from the GPS since you last used it.

But help yourself, if you had read the documentation as above, and did not understand it, then say so. Its very common for posters on here not to read even basic documentation, so a first response to such a question is often a link to the documentation.

Depends on what exactly you are trying to achive, can you say ?

Maybe try this;

void loop()
{

  while (ss.available() > 0)
  {
    gps.encode(ss.read());
    if (gps.location.isUpdated())
    {
      Serial.print(gps.location.lat(), 6);
      Serial.print(", ");
      Serial.println(gps.location.lng(), 6);
    }
  }
}

OK. Now I got it.

Thank you very much.