|
18 | 18 | # a slightly higher timeout (GPS modules typically update once a second).
|
19 | 19 | uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)
|
20 | 20 |
|
| 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 | + |
21 | 25 | # Create a GPS module instance.
|
22 |
| -gps = adafruit_gps.GPS(uart) |
| 26 | +gps = adafruit_gps.GPS(uart, debug=False) |
23 | 27 |
|
24 | 28 | # Initialize the GPS module by changing what data it sends and at what rate.
|
25 | 29 | # These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
|
|
28 | 32 | # https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf
|
29 | 33 |
|
30 | 34 | # 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') |
32 | 36 | # 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') |
34 | 38 | # 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') |
36 | 40 | # 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') |
38 | 42 |
|
39 | 43 | # 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') |
41 | 45 | # Or decrease to once every two seconds by doubling the millisecond value.
|
42 | 46 | # Be sure to also increase your UART timeout above!
|
43 |
| -#gps.send_command('PMTK220,2000') |
| 47 | +#gps.send_command(b'PMTK220,2000') |
44 | 48 | # You can also speed up the rate, but don't go too fast or else you can lose
|
45 | 49 | # 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') |
47 | 51 |
|
48 | 52 | # Main loop runs forever printing the location, etc. every second.
|
49 | 53 | last_print = time.monotonic()
|
|
71 | 75 | gps.timestamp_utc.tm_hour, # not get all data like year, day,
|
72 | 76 | gps.timestamp_utc.tm_min, # month!
|
73 | 77 | 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)) |
76 | 80 | print('Fix quality: {}'.format(gps.fix_quality))
|
77 | 81 | # Some attributes beyond latitude, longitude and timestamp are optional
|
78 | 82 | # and might not be present. Check if they're None before trying to use!
|
|
0 commit comments