Simple test

Ensure your device works with this simple test.

examples/ublox_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5
 6import board
 7
 8import adafruit_ublox
 9
10# Create I2C bus using the board's default I2C pins
11i2c = board.I2C()
12
13debug_ubx = False  # Set to True to print raw UBX messages to the console
14# Create the DDC (I2C) connection to the u-blox GPS module
15ddc = adafruit_ublox.UBloxDDC(i2c)
16# Create the UBX module for parsing UBX messages and configuring the GPS module
17ubx = adafruit_ublox.UBloxUBX(ddc, debug=debug_ubx)
18# Create the GPS module for parsing NMEA messages
19gps = adafruit_ublox.GPS_UBloxI2C(ddc)
20
21print("Attempting to configure NMEA output (GGA and RMC only)...")
22ubx.set_nmea_output({adafruit_ublox.NMEA_GGA, adafruit_ublox.NMEA_RMC})
23
24print("Attempting to set 1 Hz update rate...")
25ubx.set_update_rate(1)
26
27last_print = time.monotonic()
28while True:
29    gps.update()
30
31    current = time.monotonic()
32    if current - last_print >= 1.0:
33        last_print = current
34        if not gps.has_fix:
35            # Try again if we don't have a fix yet.
36            print("Waiting for fix...")
37            continue
38        print("=" * 40)
39        print(f"Lat: {gps.latitude:.6f} degrees, Lon: {gps.longitude:.6f} degrees")
40        if gps.satellites is not None:
41            print(f"# satellites: {gps.satellites}")
42        if gps.altitude_m is not None:
43            print(f"Altitude: {gps.altitude_m} meters")
44        if gps.speed_knots is not None:
45            print(f"Speed: {gps.speed_knots} knots")
46        if gps.speed_kmh is not None:
47            print(f"Speed: {gps.speed_kmh} km/h")
48        if gps.track_angle_deg is not None:
49            print(f"Track angle: {gps.track_angle_deg} degrees")
50        if gps.horizontal_dilution is not None:
51            print(f"Horizontal dilution: {gps.horizontal_dilution}")
52        if gps.height_geoid is not None:
53            print(f"Height geoid: {gps.height_geoid} meters")