Arduino_MKR GPS Shield library bug ... findings

I did al lot of reading an some investigation about this issue.
It seems that the MKRGPS Library functions correctly, as long as it is used as shown in the examples. As soon as you don't call GPS.available() a lot of time, you probably wont get your data at all.
The Problem as far as i am concerns is, that the GPS.available() function calls the GPS.poll() function which reads exactly one character from the serial (module) and puts it in to a buffer. As soon as the buffer reaches an end of line character, it is parsed and if it contains the correct minmea sentence, the GPS Data is extracted. The it starts all over with the next line, one character at the time, whenever you call GPS.available().
When you do, what the original forum entry suggested, reading just Sereial1 and writing it to Serial, you see that a lot of data is coming on Serial1 from the module, most of it is not used:

So as long as you call available a lot of time in your code, you read all the data from the Stream and this library works. As soon as you start doing other thing, like for example talking to IoT via GPRS (MRKGSM1400) or add some delays, you probably wont call GPS.available() enough times to get the data you are looking for from the module. I don't know what happens with the Stream1 when you read less data than is written in. Probably you Program will break at some time ....

I guess the reason that this was done this way, was the intention, not to block the main program by reading all the available data form the GPS module, what is a good assumption. I don't have a good idea to do this the right way, but knowing this, might help some developers out there.

The core library for the Arduino SAMD boards platform of the MKR boards uses a receive buffer for serial data. If you don't read from it fast enough to keep up with the incoming data, then the new data is discarded once the buffer is full. The impact of that data loss would depend on how it is handled (or not handled) by the GPS library code.

1 Like