|
| 1 | +# SPDX-FileCopyrightText: 2024 |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +import time |
| 5 | +import board |
| 6 | +from adafruit_display_text.label import Label |
| 7 | +from displayio import Group |
| 8 | +from terminalio import FONT |
| 9 | + |
| 10 | +import adafruit_gps |
| 11 | + |
| 12 | +# import busio |
| 13 | +# uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10) |
| 14 | +i2c = board.I2C() # uses board.SCL and board.SDA |
| 15 | +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector |
| 16 | + |
| 17 | +# Create a GPS module instance. |
| 18 | +# gps = adafruit_gps.GPS(uart, debug=False) # Use UART |
| 19 | +gps = adafruit_gps.GPS_GtopI2C(i2c, debug=False) # Use I2C interface |
| 20 | + |
| 21 | +# Turn on the basic GGA and RMC info (what you typically want) |
| 22 | +gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") |
| 23 | + |
| 24 | +# Set update rate to once a second 1hz (what you typically want) |
| 25 | +gps.send_command(b"PMTK220,1000") |
| 26 | + |
| 27 | + |
| 28 | +# Example written for boards with built-in displays |
| 29 | +display = board.DISPLAY |
| 30 | + |
| 31 | +# Create a main_group to hold anything we want to show on the display. |
| 32 | +main_group = Group() |
| 33 | + |
| 34 | +# Create a Label to show the readings. If you have a very small |
| 35 | +# display you may need to change to scale=1. |
| 36 | +display_output_label = Label(FONT, text="", scale=2) |
| 37 | + |
| 38 | +# Place the label near the top left corner with anchored positioning |
| 39 | +display_output_label.anchor_point = (0, 0) |
| 40 | +display_output_label.anchored_position = (4, 4) |
| 41 | + |
| 42 | +# Add the label to the main_group |
| 43 | +main_group.append(display_output_label) |
| 44 | + |
| 45 | +# Set the main_group as the root_group of the display |
| 46 | +display.root_group = main_group |
| 47 | + |
| 48 | + |
| 49 | +last_print = time.monotonic() |
| 50 | + |
| 51 | +# Begin main loop |
| 52 | +while True: |
| 53 | + gps.update() |
| 54 | + |
| 55 | + current = time.monotonic() |
| 56 | + # Update display data every second |
| 57 | + if current - last_print >= 1.0: |
| 58 | + last_print = current |
| 59 | + if not gps.has_fix: |
| 60 | + # Try again if we don't have a fix yet. |
| 61 | + display_output_label.text = "Waiting for fix..." |
| 62 | + continue |
| 63 | + # We have a fix! (gps.has_fix is true) |
| 64 | + t = gps.timestamp_utc |
| 65 | + |
| 66 | + # Update the label.text property to change the text on the display |
| 67 | + display_output_label.text = f"Timestamp (UTC): \ |
| 68 | + \n{t.tm_mday}/{t.tm_mon}/{t.tm_year} {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}\ |
| 69 | + \nLat: {gps.latitude:.6f}\ |
| 70 | + \nLong: {gps.longitude:.6f}" |
0 commit comments