Integrating Ultimate GPS with 128x64 OLED screen

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
johnkoenig375
 
Posts: 21
Joined: Sat Jul 02, 2022 2:12 pm

Integrating Ultimate GPS with 128x64 OLED screen

Post by johnkoenig375 »

Hi, I am trying to get the Adafruit Ultimate GPS (https://learn.adafruit.com/adafruit-ultimate-gps) to get a fix. Here is the boards that I'm using to try to get this to work:
  • Adafruit Feather nRF52840 Express
    Adafruit Ultimate GPS (connected on TX/RX pins)
    Adafruit 128x64 OLED FeatherWing (connected on I2C)
I want to get the time/lat/long to print out to the screen so I can see that it actually has a fix when I take it outside. This is the code I'm using

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

I'm looking for any info that might be a reason why I can't get it to achieve a fix. I am also not using an external antenna (I'm not sure if that is required)

Thanks for the help

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by adafruit_support_carter »

Initial fixes can take some time - many minutes. And can be very dependent on clear view of the sky.

However, getting a fix only requires power. The FIX indicator LED should blink once per second while it is trying to get a fix. Then only once every 15 seconds when it has a fix. Try just leaving it powered in a location with good view of the sky and see if it can get a fix based on the FIX indicator.

User avatar
johnkoenig375
 
Posts: 21
Joined: Sat Jul 02, 2022 2:12 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by johnkoenig375 »

Ok I'll try, I only gave it about 30 seconds because it was about to rain when I tested it. Is there any specific antenna that would make it more responsive?

User avatar
johnkoenig375
 
Posts: 21
Joined: Sat Jul 02, 2022 2:12 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by johnkoenig375 »

Update - Hi I bought the external GPS antenna and I did testing with an open sky and I still can't get a fix. Is there anything else that could be preventing me from getting a GPS fix?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by adafruit_support_carter »

Sometimes it can be power related. How are you powering the setup?

User avatar
johnkoenig375
 
Posts: 21
Joined: Sat Jul 02, 2022 2:12 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by johnkoenig375 »

So the GPS shows up on I2C scan and the red led is blinking. I am powering it on a battery (which is running all the boards) because I can't get it outside without the battery because my computer is inside. Could you explain more about how the power situation could prevent a fix?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by adafruit_support_carter »

It's just that some people have swapped power cables and/or power supplies and gotten it to work. May be related to overall power capacity of power supply being used.

How long did you leave it outside to try and obtain a lock for the recent test?

User avatar
johnkoenig375
 
Posts: 21
Joined: Sat Jul 02, 2022 2:12 pm

Re: Integrating Ultimate GPS with 128x64 OLED screen

Post by johnkoenig375 »

I was outside for 20 minutes I believe. I'll try some different batteries etc

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”