Skip to content

Update adafruit_gps.py #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jomogalla
Copy link
Contributor

@jomogalla jomogalla commented Mar 19, 2019

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.

@makermelissa makermelissa requested a review from a team March 19, 2019 05:39
@evaherrada
Copy link
Collaborator

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.

@evaherrada
Copy link
Collaborator

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.

@MSube
Copy link

MSube commented May 8, 2019

_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.

@evaherrada
Copy link
Collaborator

By read() are you referring to self._uart.read() or something else?

@MSube
Copy link

MSube commented May 8, 2019

yes, _uart.read()

@MSube
Copy link

MSube commented May 8, 2019

Feel free to look at MSube/CircuitPython_GPS_NMEA, the update() function in msube_gps.py is doing this.

@ladyada
Copy link
Member

ladyada commented May 9, 2019

ok cool - yeah we didnt have in_waiting before!

@ladyada ladyada merged commit 70db3f9 into adafruit:master May 9, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 13, 2019
Updating https://github.com/adafruit/Adafruit_CircuitPython_CCS811 to 1.1.5 from 1.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_CCS811#29 from mitchellhenke/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Crickit to 2.1.5 from 2.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_Crickit#16 from caternuson/example_update

Updating https://github.com/adafruit/Adafruit_CircuitPython_GPS to 3.2.4 from 3.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#17 from jomogalla/checking-input-buffer-before-reading
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#24 from dherrada/docs
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#21 from dherrada/master
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#23 from dherrada/docs

Updating https://github.com/adafruit/Adafruit_CircuitPython_INA219 to 3.2.0 from 3.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_INA219#9 from barbudor/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_LPS35HW to 1.1.0 from 1.0.0:
  > added low pressure threshold

Updating https://github.com/adafruit/Adafruit_CircuitPython_Seesaw to 1.4.1 from 1.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#28 from makermelissa/master
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#29 from robotics-masters/wallarug/robohatmm1

Updating https://github.com/adafruit/Adafruit_CircuitPython_SGP30 to 2.0.2 from 2.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_SGP30#15 from djmbritt/patch-1
siddacious added a commit that referenced this pull request May 16, 2019
 Changed code from PR #17 from 64 bytes to 32 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants