Datasheet

Notice some of the attributes like altitude_m are checked to be None before reading. This is a smart check to put in
your code too because those attributes are sometimes not sent by a GPS module. If an attribute isn't sent by the
module it will be given a None/null value and attempting to print or read it in Python will fail. The core attributes
of latitude, longitude, and timestamp are usually always available (if you're using the example as-is) but they might not
be if you turn off those outputs with a custom NMEA command!
That's all there is to reading GPS location with CircuitPython code!
Datalogging Example
Another handy task with GPS is logging all the raw output of the GPS module to a file. This is useful if you're importing
the GPS data into a tool like Google Earth which can process raw NMEA sentences. You can perform this datalogging
very easily with CircuitPython.
To store data you'll need to choose one of two options:
Wire up a SD card holder to your board's SPI bus, or use a board with SD card holder built-in like the Feather M0
Adalogger. This is the recommended approach as it gives you a lot of space to store data and you can easily
copy the data to your computer from the card.
Store data in your board's internal filesystem. This requires a little more setup but allows you to save to a file on
the internal filesystem of your CircuitPython board, right next to where code and other data files live. This is more
limited because depending on your board you might only have a few kilobytes or megabytes of space available
and GPS sentences will quickly add up (easily filling multiple megabytes within a few hours of logging).
if not gps.has_fix:
# Try again if we don't have a fix yet.
print('Waiting for fix...')
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: {} degrees'.format(gps.latitude))
print('Longitude: {} degrees'.format(gps.longitude))
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.track_angle_deg 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:
© Adafruit Industries https://learn.adafruit.com/adafruit-ultimate-gps Page 23 of 40