From d43cdabb32fd774403d99c4a45aeeadea8c5542b Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Thu, 3 Oct 2024 17:09:17 +0200 Subject: [PATCH] Add displayio example --- examples/gps_displayio_simpletest.py | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 examples/gps_displayio_simpletest.py diff --git a/examples/gps_displayio_simpletest.py b/examples/gps_displayio_simpletest.py new file mode 100644 index 0000000..07480ae --- /dev/null +++ b/examples/gps_displayio_simpletest.py @@ -0,0 +1,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}"