- Adafruit Feather nRF52840 Express
Adafruit Ultimate GPS (connected on TX/RX pins)
Adafruit 128x64 OLED FeatherWing (connected on I2C)
Code: Select all
'''
This test will print GPS info on the OLED screen so I can verify the fix
'''
import time
import board
import displayio
import terminalio
import busio
# can try import bitmap_label below for alternative
from adafruit_display_text import label
import adafruit_displayio_sh1107
import adafruit_gps
displayio.release_displays()
# oled_reset = board.D9
# Use for I2C
i2c = board.I2C()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
# SH1107 is vertically oriented 64x128
WIDTH = 128
HEIGHT = 64
BORDER = 2
display = adafruit_displayio_sh1107.SH1107(
display_bus, width=WIDTH, height=HEIGHT, rotation=180
)
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)
# If using I2C, we'll create an I2C interface to talk to using default pins
# i2c = board.I2C()
# Create a GPS module instance.
gps = adafruit_gps.GPS(uart, debug=False) # Use UART/pyserial
# 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) which is what you typically want.
gps.send_command(b"PMTK220,1000")
# Make the display context
splash = displayio.Group()
display.show(splash)
text1 = "WELCOME TO THE" # overly long to see where it clips
text_area1 = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8)
splash.append(text_area1)
text2 = "LITHIUM MINES HUMAN"
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF, x=8, y=20)
splash.append(text_area2)
text3 = "Time:"
text_area3 = label.Label(terminalio.FONT, text=text3, color=0xFFFFFF, x=8, y=34)
splash.append(text_area3)
text4 = "Latitude:"
text_area4 = label.Label(terminalio.FONT, text=text4, color=0xFFFFFF, x=8, y=45)
splash.append(text_area4)
text5 = "Longitude:"
text_area5 = label.Label(terminalio.FONT, text=text5, color=0xFFFFFF, x=8, y=56)
splash.append(text_area5)
last_print = time.monotonic()
counter = 0
while True:
gps.update()
# Every second print out current location details if there's a fix.
current = time.monotonic()
if current - last_print >= 1.0:
last_print = current
if not gps.has_fix:
# Try again if we don't have a fix yet.
print("Waiting for fix... {}".format(counter))
text3 = "Waiting for fix...{}".format(counter)
text_area3 = label.Label(terminalio.FONT, text=text3, color=0xFFFFFF, x=8, y=34)
splash[2] = text_area3
text4 = "Waiting for fix...{}".format(counter)
text_area4 = label.Label(terminalio.FONT, text=text4, color=0xFFFFFF, x=8, y=45)
splash[3] = text_area4
text5 = "Waiting for fix...{}".format(counter)
text_area5 = label.Label(terminalio.FONT, text=text5, color=0xFFFFFF, x=8, y=56)
splash[4] = text_area5
counter += 1
continue
# We have a fix! (gps.has_fix is true)
# Print out details about the fix like location, date, etc.
print("=" * 40) # Print a separator line.
print(
"Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
gps.timestamp_utc.tm_mday, # struct_time object that holds
gps.timestamp_utc.tm_year, # the fix time. Note you might
gps.timestamp_utc.tm_hour, # not get all data like year, day,
gps.timestamp_utc.tm_min, # month!
gps.timestamp_utc.tm_sec,
)
)
print("Latitude: {0:.6f} degrees".format(gps.latitude))
print("Longitude: {0:.6f} degrees".format(gps.longitude))
print(
"Precise Latitude: {:2.}{:2.4f} degrees".format(
gps.latitude_degrees, gps.latitude_minutes
)
)
print(
"Precise Longitude: {:2.}{:2.4f} degrees".format(
gps.longitude_degrees, gps.longitude_minutes
)
)
print("Fix quality: {}".format(gps.fix_quality))
# Some attributes beyond latitude, longitude and timestamp are optional
# and might not be present. Check if they're None before trying to use!
if gps.satellites is not None:
print("# satellites: {}".format(gps.satellites))
if gps.altitude_m is not None:
print("Altitude: {} meters".format(gps.altitude_m))
if gps.speed_knots is not None:
print("Speed: {} knots".format(gps.speed_knots))
if gps.track_angle_deg is not None:
print("Track angle: {} degrees".format(gps.track_angle_deg))
if gps.horizontal_dilution is not None:
print("Horizontal dilution: {}".format(gps.horizontal_dilution))
if gps.height_geoid is not None:
print("Height geoid: {} meters".format(gps.height_geoid))
# time
text3 = "Time: {}/{}/{} {:02}:{:02}:{:02}".format(
gps.timestamp_utc.tm_mon,
gps.timestamp_utc.tm_mday,
gps.timestamp_utc.tm_year,
gps.timestamp_utc.tm_hour,
gps.timestamp_utc.tm_min,
gps.timestamp_utc.tm_sec)
text_area3 = label.Label(terminalio.FONT, text=text3, color=0xFFFFFF, x=8, y=34)
splash[2] = text_area3
# latitude
text4 = "Latitude: {:2.}{:2.4f} degrees".format(
gps.latitude_degrees,
gps.latitude_minutes)
text_area4 = label.Label(terminalio.FONT, text=text4, color=0xFFFFFF, x=8, y=45)
splash[3] = text_area4
# longitude
text5 = "Longitude: {:2.}{:2.4f} degrees".format(
gps.longitude_degrees, gps.longitude_minutes)
text_area5 = label.Label(terminalio.FONT, text=text5, color=0xFFFFFF, x=8, y=56)
splash[4] = text_area5
Thanks for the help