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