Hi,
I am using the TinyGPS library and it is wonderful, but I would like a way to find out whether or not it has a fix and I can’t seem to find any way to do this.
Any help would be greatly appreciated!
Hi,
I am using the TinyGPS library and it is wonderful, but I would like a way to find out whether or not it has a fix and I can’t seem to find any way to do this.
Any help would be greatly appreciated!
I think you will need to read the input from the led status pin (which tells if you have a fix) and interpret from there…
A quick search and poking at the library doesn’t show the possibility via software. Happy to hear if there’s a way to do it though!
There is no way to detect a fix unless you’ll have it.
Any GPS is firing right away NMEA-sentences (common, TinyGPS uses it.), whether or not there is a fix.
I had even a chip with a broken antenna, no content, but a bunch of empty sentences. They look like $Gxxx,.
Valid messages, but void content.
The questions boils down to this: When did you get a fix.
First indication is a valid timestamp. Usually you get it with the first satellite in view. Second indicator is the count of satellites, anything lower than 4 does not provide an initial first fix, but you know, it might be coming.
Third is of course a fix with 4 or more satellites in view.
So you have to wait.
Another problem might be, if the antenna looses contact and the position is not updated. You have to check the time-intervall since the last fix.
What led do you mean? My GPS -receiver has none.
If you look at the 2nd photo, the pads are there but not soldered…
I see that the raw output of the GPS actually tells you whether it’s locked or not
$GPGGA, 161229.487, 3723.24756, N, 12158.34162, W, 1, 07, 1.0, 9.0, M, , , ,0000*18
The value 1 between “W” and “07” is the position fix indicator.
From the datasheet:
Value Description
0 Fix not available or invalid
1 GPS SPS Mode,fix valid
2 Differential GPS,SPS Mode,fix valid
3 GPS PPS Mode,fix valid
You will looking at any non “0” value to indicate that there’s a valid fix…
So with this knowledge… you probably need to modify the TinyGPS library to check that field
Not sure if it works but the author gave this example:
http://arduiniana.org/libraries/tinygps/
float flat, flon;
unsigned long fix_age; // returns +- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
if (fix_age == TinyGPS::GPS_INVALID_AGE)
Serial.println("No fix detected");
else if (fix_age > 5000)
Serial.println("Warning: possible stale data!");
else
Serial.println("Data is current.");
Thank you, I did not notice that.
The example the author does provide is actually a better suggestion than mine, given his constant “GPS_INVALID_AGE”.
I would not tinker with the library here. NMEA is a beast on its own.
The value of 5 seconds is a point for discussions here, maybe somehow elevate and differentiate it even more. It depends on.
The encode(char c) method itself lets you know if it has a fix. My code looks something like this:
// parse GPS data
isValidGPS = false;
if (gps.encode(c))
isValidGPS = true;
Just a side note:
If you can use an expression in an if()
statement, you can just use it for a boolean assignment too.
isValdiGPS = gps.encode(c); // the worst case add a cast like (boolaen)gps.encode(c)
But since this is the declaration of encode()
bool encode(char c); // process one character received from GPS
casting won’t be required
There’s an easy to digest write up on getting a fix and what the fix age means here: TinyGPS