|
8 | 8 | import adafruit_gps
|
9 | 9 |
|
10 | 10 |
|
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. |
14 | 11 | RX = board.RX
|
15 | 12 | TX = board.TX
|
16 | 13 |
|
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). |
19 | 14 | uart = busio.UART(TX, RX, baudrate=9600, timeout=30)
|
20 | 15 |
|
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. |
26 | 16 | gps = adafruit_gps.GPS(uart, debug=False)
|
27 | 17 |
|
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) |
35 | 18 | gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
36 | 19 | # Turn on just minimum info (RMC only, location):
|
37 | 20 | #gps.send_command(b'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
|
40 | 23 | # Tuen on everything (not all of it is parsed!)
|
41 | 24 | #gps.send_command(b'PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
42 | 25 |
|
43 |
| -# Set update rate to once a second (1hz) which is what you typically want. |
44 | 26 | 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') |
51 | 27 |
|
52 |
| -# Main loop runs forever printing the location, etc. every second. |
53 | 28 | last_print = time.monotonic()
|
54 | 29 | while True:
|
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. |
| 30 | + a = gps.update() |
61 | 31 | current = time.monotonic()
|
62 | 32 | if current - last_print >= 1.0:
|
63 | 33 | last_print = current
|
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)) |
| 34 | + print(a) |
0 commit comments