From 49526418f71c109e0c5e162b27c40f14af45e67b Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 7 May 2019 13:09:01 -0400 Subject: [PATCH 1/5] Added tips on using floats to README --- README.rst | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index a437320..612d142 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,54 @@ This is easily achieved by downloading Usage Example ============= -See examples/simple.py for a demonstration of parsing and printing GPS location. +See examples/gps_simpletest.py for a demonstration of parsing and printing GPS location. + +Important: +Feather boards and many other circuitpython boards will round to two decimal places like this: + +.. code-block:: python + + >>> float('1234.5678') + 1234.57 + +This isn't ideal for gps data as this lowers the accuracty from 0.1m to 11m. + +This can be fixed by using string formatting when the gps data is outputted. + +An implementation of this can be found in examples/gps_simpletest.py + +.. code-block:: python + + import time + import board + import busio + + import adafruit_gps + + RX = board.RX + TX = board.TX + + uart = busio.UART(TX, RX, baudrate=9600, timeout=3000) + + gps = adafruit_gps.GPS(uart, debug=False) + + gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') + + gps.send_command(b'PMTK220,1000') + + while True: + + gps.update() + + current = time.monotonic() + if current - last_print >= 1.0: + last_print = current + if not gps.has_fix: + print('Waiting for fix...') + continue + print('=' * 40) # Print a separator line. + print('Latitude: {0:.6f} degrees'.format(gps.latitude)) + print('Longitude: {0:.6f} degrees'.format(gps.longitude)) Contributing ============ @@ -85,4 +132,4 @@ Now, once you have the virtual environment activated: This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to -locally verify it will pass. \ No newline at end of file +locally verify it will pass. From 0a6828cb6411696a9a92572afcae5247607bb2cf Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 7 May 2019 13:18:42 -0400 Subject: [PATCH 2/5] Fixed example code --- README.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 612d142..170f104 100644 --- a/README.rst +++ b/README.rst @@ -58,7 +58,7 @@ An implementation of this can be found in examples/gps_simpletest.py RX = board.RX TX = board.TX - uart = busio.UART(TX, RX, baudrate=9600, timeout=3000) + uart = busio.UART(TX, RX, baudrate=9600, timeout=30) gps = adafruit_gps.GPS(uart, debug=False) @@ -66,10 +66,11 @@ An implementation of this can be found in examples/gps_simpletest.py gps.send_command(b'PMTK220,1000') + last_print = time.monotonic() while True: - + gps.update() - + current = time.monotonic() if current - last_print >= 1.0: last_print = current From 35ff3b0f123400bdb882446ca6e6150efb1bd8dc Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 7 May 2019 13:24:32 -0400 Subject: [PATCH 3/5] Changed uart timeout to 30s instead of 3000ms since busio.UART now uses seconds --- examples/gps_computer_datalogging.py | 2 +- examples/gps_datalogging.py | 2 +- examples/gps_echotest.py | 2 +- examples/gps_simpletest.py | 2 +- examples/gps_time_source.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gps_computer_datalogging.py b/examples/gps_computer_datalogging.py index 0e32132..a3fd8c9 100644 --- a/examples/gps_computer_datalogging.py +++ b/examples/gps_computer_datalogging.py @@ -17,7 +17,7 @@ # Create a serial connection for the GPS connection using default speed and # a slightly higher timeout (GPS modules typically update once a second). # Update the serial port name to match the serial connection for the GPS! -uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3000) +uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=30) # Main loop just reads data from the GPS module and writes it back out to # the output file while also printing to serial output. diff --git a/examples/gps_datalogging.py b/examples/gps_datalogging.py index 324b4c3..7ffb8be 100644 --- a/examples/gps_datalogging.py +++ b/examples/gps_datalogging.py @@ -40,7 +40,7 @@ # Create a serial connection for the GPS connection using default speed and # a slightly higher timeout (GPS modules typically update once a second). -uart = busio.UART(TX, RX, baudrate=9600, timeout=3000) +uart = busio.UART(TX, RX, baudrate=9600, timeout=30) # Main loop just reads data from the GPS module and writes it back out to # the output file while also printing to serial output. diff --git a/examples/gps_echotest.py b/examples/gps_echotest.py index 450e6e7..e97a42e 100644 --- a/examples/gps_echotest.py +++ b/examples/gps_echotest.py @@ -16,7 +16,7 @@ # Create a serial connection for the GPS connection using default speed and # a slightly higher timeout (GPS modules typically update once a second). -uart = busio.UART(TX, RX, baudrate=9600, timeout=3000) +uart = busio.UART(TX, RX, baudrate=9600, timeout=30) # for a computer, use the pyserial library for uart access #import serial diff --git a/examples/gps_simpletest.py b/examples/gps_simpletest.py index a475acf..c5d33cf 100644 --- a/examples/gps_simpletest.py +++ b/examples/gps_simpletest.py @@ -16,7 +16,7 @@ # Create a serial connection for the GPS connection using default speed and # a slightly higher timeout (GPS modules typically update once a second). -uart = busio.UART(TX, RX, baudrate=9600, timeout=3000) +uart = busio.UART(TX, RX, baudrate=9600, timeout=30) # for a computer, use the pyserial library for uart access #import serial diff --git a/examples/gps_time_source.py b/examples/gps_time_source.py index f23aa37..9dd3bc1 100644 --- a/examples/gps_time_source.py +++ b/examples/gps_time_source.py @@ -8,7 +8,7 @@ import rtc import adafruit_gps -uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=3000) +uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=30) gps = adafruit_gps.GPS(uart, debug=False) gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0') From f10e6698a9669f6fd532ebdf529ea8011b6c9325 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 7 May 2019 13:46:23 -0400 Subject: [PATCH 4/5] Added another code snippet make the fix more obvious --- README.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.rst b/README.rst index 170f104..f9f83a0 100644 --- a/README.rst +++ b/README.rst @@ -81,6 +81,14 @@ An implementation of this can be found in examples/gps_simpletest.py print('Latitude: {0:.6f} degrees'.format(gps.latitude)) print('Longitude: {0:.6f} degrees'.format(gps.longitude)) + +These two lines are the lines that actually solve the issue: +.. code-block:: python + + print('Latitude: {0:.6f} degrees'.format(gps.latitude)) + print('Longitude: {0:.6f} degrees'.format(gps.longitude)) + + Contributing ============ From 0facb5a3801f24ef8c8c014cffc5b6be9e9efd6b Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Tue, 7 May 2019 13:49:13 -0400 Subject: [PATCH 5/5] Same as previous commit: Added another code snippet make the fix more obvious --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index f9f83a0..09cacf7 100644 --- a/README.rst +++ b/README.rst @@ -83,6 +83,7 @@ An implementation of this can be found in examples/gps_simpletest.py These two lines are the lines that actually solve the issue: + .. code-block:: python print('Latitude: {0:.6f} degrees'.format(gps.latitude))