Skip to content

Commit 399a7cb

Browse files
author
Melissa LeBlanc-Williams
authored
Merge pull request #20 from dherrada/master
Modified README to help people use floats. Also changed uart timeout on example files.
2 parents 5ffed45 + 0facb5a commit 399a7cb

6 files changed

+64
-7
lines changed

README.rst

+59-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,64 @@ This is easily achieved by downloading
3131
Usage Example
3232
=============
3333

34-
See examples/simple.py for a demonstration of parsing and printing GPS location.
34+
See examples/gps_simpletest.py for a demonstration of parsing and printing GPS location.
35+
36+
Important:
37+
Feather boards and many other circuitpython boards will round to two decimal places like this:
38+
39+
.. code-block:: python
40+
41+
>>> float('1234.5678')
42+
1234.57
43+
44+
This isn't ideal for gps data as this lowers the accuracty from 0.1m to 11m.
45+
46+
This can be fixed by using string formatting when the gps data is outputted.
47+
48+
An implementation of this can be found in examples/gps_simpletest.py
49+
50+
.. code-block:: python
51+
52+
import time
53+
import board
54+
import busio
55+
56+
import adafruit_gps
57+
58+
RX = board.RX
59+
TX = board.TX
60+
61+
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
62+
63+
gps = adafruit_gps.GPS(uart, debug=False)
64+
65+
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
66+
67+
gps.send_command(b'PMTK220,1000')
68+
69+
last_print = time.monotonic()
70+
while True:
71+
72+
gps.update()
73+
74+
current = time.monotonic()
75+
if current - last_print >= 1.0:
76+
last_print = current
77+
if not gps.has_fix:
78+
print('Waiting for fix...')
79+
continue
80+
print('=' * 40) # Print a separator line.
81+
print('Latitude: {0:.6f} degrees'.format(gps.latitude))
82+
print('Longitude: {0:.6f} degrees'.format(gps.longitude))
83+
84+
85+
These two lines are the lines that actually solve the issue:
86+
87+
.. code-block:: python
88+
89+
print('Latitude: {0:.6f} degrees'.format(gps.latitude))
90+
print('Longitude: {0:.6f} degrees'.format(gps.longitude))
91+
3592
3693
Contributing
3794
============
@@ -85,4 +142,4 @@ Now, once you have the virtual environment activated:
85142
86143
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
87144
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
88-
locally verify it will pass.
145+
locally verify it will pass.

examples/gps_computer_datalogging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Create a serial connection for the GPS connection using default speed and
1818
# a slightly higher timeout (GPS modules typically update once a second).
1919
# Update the serial port name to match the serial connection for the GPS!
20-
uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3000)
20+
uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=30)
2121

2222
# Main loop just reads data from the GPS module and writes it back out to
2323
# the output file while also printing to serial output.

examples/gps_datalogging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
# Create a serial connection for the GPS connection using default speed and
4242
# a slightly higher timeout (GPS modules typically update once a second).
43-
uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)
43+
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
4444

4545
# Main loop just reads data from the GPS module and writes it back out to
4646
# the output file while also printing to serial output.

examples/gps_echotest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Create a serial connection for the GPS connection using default speed and
1818
# a slightly higher timeout (GPS modules typically update once a second).
19-
uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)
19+
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
2020

2121
# for a computer, use the pyserial library for uart access
2222
#import serial

examples/gps_simpletest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Create a serial connection for the GPS connection using default speed and
1818
# a slightly higher timeout (GPS modules typically update once a second).
19-
uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)
19+
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
2020

2121
# for a computer, use the pyserial library for uart access
2222
#import serial

examples/gps_time_source.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import rtc
99
import adafruit_gps
1010

11-
uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=3000)
11+
uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=30)
1212

1313
gps = adafruit_gps.GPS(uart, debug=False)
1414
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')

0 commit comments

Comments
 (0)