Closed jomogalla closed 5 years ago
This is WAY faster. I was able to get the example file to run once every 0.01 seconds (I didn't try any faster than that) and without the code you suggested, it ran at a maximum of once every 0.08 seconds.
The only thing I'm wondering about is the GPS chip having a max refresh rate of 10Hz. Anything faster than that could produce duplicate data.
_uart.readline() blocks because it waits for the \r that terminates the NMEA sentence. Check for in_waiting >= 64 means that you wait for the buffer to fill up and the next byte received would overflow the internal buffer of the UART (which is 64 bytes. Correct?). That requires that you check it at least once per millisecond if running with 9600 because that's the time needed to receive one byte. I assume that it's also possible that the end of a sentence is in the uart buffer and you won't read it until the next sentence starts (happens if sentences are longer than 64 bytes).
A better approach is to use read(nbytes=in_waiting) if in_waiting > 0 and collect the incoming bytes in your own buffer. This way you only need to check every 64 ms to avoid an UART overflow.
By read() are you referring to self._uart.read() or something else?
yes, _uart.read()
Feel free to look at MSube/CircuitPython_GPS_NMEA, the update() function in msube_gps.py is doing this.
ok cool - yeah we didnt have in_waiting
before!
I was trying to call update() in the adafruit_gps.py module and it would take quite a while, blocking my program from continuing until
_uart.readline()
returned.By adding a check to make sure the number of bytes in the input buffer was at least 64, the module doesn't seem to block while waiting for bytes in the buffer.