Skip to content

Commit b5c5752

Browse files
committed
Reverted simpletest
1 parent 9d4beb8 commit b5c5752

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

examples/gps_simpletest.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@
88
import adafruit_gps
99

1010

11+
# Define RX and TX pins for the board's serial port connected to the GPS.
12+
# These are the defaults you should use for the GPS FeatherWing.
13+
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
1114
RX = board.RX
1215
TX = board.TX
1316

17+
# Create a serial connection for the GPS connection using default speed and
18+
# a slightly higher timeout (GPS modules typically update once a second).
1419
uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
1520

21+
# for a computer, use the pyserial library for uart access
22+
#import serial
23+
#uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3000)
24+
25+
# Create a GPS module instance.
1626
gps = adafruit_gps.GPS(uart, debug=False)
1727

28+
# Initialize the GPS module by changing what data it sends and at what rate.
29+
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
30+
# PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust
31+
# the GPS module behavior:
32+
# https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf
33+
34+
# Turn on the basic GGA and RMC info (what you typically want)
1835
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
1936
# Turn on just minimum info (RMC only, location):
2037
#gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
@@ -23,12 +40,55 @@
2340
# Tuen on everything (not all of it is parsed!)
2441
#gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
2542

43+
# Set update rate to once a second (1hz) which is what you typically want.
2644
gps.send_command(b'PMTK220,1000')
45+
# Or decrease to once every two seconds by doubling the millisecond value.
46+
# Be sure to also increase your UART timeout above!
47+
#gps.send_command(b'PMTK220,2000')
48+
# You can also speed up the rate, but don't go too fast or else you can lose
49+
# data during parsing. This would be twice a second (2hz, 500ms delay):
50+
#gps.send_command(b'PMTK220,500')
2751

52+
# Main loop runs forever printing the location, etc. every second.
2853
last_print = time.monotonic()
2954
while True:
30-
a = gps.update()
55+
# Make sure to call gps.update() every loop iteration and at least twice
56+
# as fast as data comes from the GPS unit (usually every second).
57+
# This returns a bool that's true if it parsed new data (you can ignore it
58+
# though if you don't care and instead look at the has_fix property).
59+
gps.update()
60+
# Every second print out current location details if there's a fix.
3161
current = time.monotonic()
3262
if current - last_print >= 1.0:
3363
last_print = current
34-
print(a)
64+
if not gps.has_fix:
65+
# Try again if we don't have a fix yet.
66+
print('Waiting for fix...')
67+
continue
68+
# We have a fix! (gps.has_fix is true)
69+
# Print out details about the fix like location, date, etc.
70+
print('=' * 40) # Print a separator line.
71+
print('Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}'.format(
72+
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
73+
gps.timestamp_utc.tm_mday, # struct_time object that holds
74+
gps.timestamp_utc.tm_year, # the fix time. Note you might
75+
gps.timestamp_utc.tm_hour, # not get all data like year, day,
76+
gps.timestamp_utc.tm_min, # month!
77+
gps.timestamp_utc.tm_sec))
78+
print('Latitude: {0:.6f} degrees'.format(gps.latitude))
79+
print('Longitude: {0:.6f} degrees'.format(gps.longitude))
80+
print('Fix quality: {}'.format(gps.fix_quality))
81+
# Some attributes beyond latitude, longitude and timestamp are optional
82+
# and might not be present. Check if they're None before trying to use!
83+
if gps.satellites is not None:
84+
print('# satellites: {}'.format(gps.satellites))
85+
if gps.altitude_m is not None:
86+
print('Altitude: {} meters'.format(gps.altitude_m))
87+
if gps.speed_knots is not None:
88+
print('Speed: {} knots'.format(gps.speed_knots))
89+
if gps.track_angle_deg is not None:
90+
print('Track angle: {} degrees'.format(gps.track_angle_deg))
91+
if gps.horizontal_dilution is not None:
92+
print('Horizontal dilution: {}'.format(gps.horizontal_dilution))
93+
if gps.height_geoid is not None:
94+
print('Height geo ID: {} meters'.format(gps.height_geoid))

0 commit comments

Comments
 (0)