Skip to content

Commit 72abd3d

Browse files
committed
reasonable formatting on lat/long, convert all strings to bytes, add pyserial example
1 parent a53559b commit 72abd3d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

examples/gps_simpletest.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
# a slightly higher timeout (GPS modules typically update once a second).
1919
uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)
2020

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+
2125
# Create a GPS module instance.
22-
gps = adafruit_gps.GPS(uart)
26+
gps = adafruit_gps.GPS(uart, debug=False)
2327

2428
# Initialize the GPS module by changing what data it sends and at what rate.
2529
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
@@ -28,22 +32,22 @@
2832
# https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf
2933

3034
# Turn on the basic GGA and RMC info (what you typically want)
31-
gps.send_command('PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
35+
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
3236
# Turn on just minimum info (RMC only, location):
33-
#gps.send_command('PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
37+
#gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
3438
# Turn off everything:
35-
#gps.send_command('PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
39+
#gps.send_command(b'PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
3640
# Tuen on everything (not all of it is parsed!)
37-
#gps.send_command('PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
41+
#gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
3842

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

4852
# Main loop runs forever printing the location, etc. every second.
4953
last_print = time.monotonic()
@@ -71,8 +75,8 @@
7175
gps.timestamp_utc.tm_hour, # not get all data like year, day,
7276
gps.timestamp_utc.tm_min, # month!
7377
gps.timestamp_utc.tm_sec))
74-
print('Latitude: {} degrees'.format(gps.latitude))
75-
print('Longitude: {} degrees'.format(gps.longitude))
78+
print('Latitude: {0:.6f} degrees'.format(gps.latitude))
79+
print('Longitude: {0:.6f} degrees'.format(gps.longitude))
7680
print('Fix quality: {}'.format(gps.fix_quality))
7781
# Some attributes beyond latitude, longitude and timestamp are optional
7882
# and might not be present. Check if they're None before trying to use!

0 commit comments

Comments
 (0)