Atomic GPS Base

这是 ATOM GPS Base 的驱动程序库,用于从 GPS 模块获取数据。

支持以下产品:

ATOM GPS

ATOM GPS Base

UIFLOW2 应用示例:

获取 GPS 数据

在UiFlow2 中打开 atoms3_gps_example.m5f2 项目。

本示例获取 ATOM GPS Base 的 GPS 数据并将其显示在串口监视器中。

UiFlow2 代码块:

example.png

示例输出:

None

MicroPython 应用示例:

获取 GPS 数据

本示例获取 ATOM GPS Base 的 GPS 数据并将其显示在串口监视器中。

MicroPython 代码块:

 1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from base import ATOMGPSBase
 9import time
10
11
12title0 = None
13base_gps = None
14
15
16def setup():
17    global title0, base_gps
18
19    M5.begin()
20    title0 = Widgets.Title("GPS Base", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
21
22    base_gps = ATOMGPSBase(2, port=(5, 6))
23    base_gps.set_time_zone(0)
24
25
26def loop():
27    global title0, base_gps
28    M5.update()
29    print(base_gps.get_gps_time())
30    print(base_gps.get_gps_date())
31    print(base_gps.get_gps_date_time())
32    print(base_gps.get_timestamp())
33    print(base_gps.get_latitude())
34    print(base_gps.get_longitude())
35    print(base_gps.get_altitude())
36    print(base_gps.get_satellite_num())
37    print(base_gps.get_pos_quality())
38    print(base_gps.get_corse_over_ground())
39    print(base_gps.get_speed_over_ground())
40    time.sleep(1)
41
42
43if __name__ == "__main__":
44    try:
45        setup()
46        while True:
47            loop()
48    except (Exception, KeyboardInterrupt) as e:
49        try:
50            from utility import print_error_msg
51
52            print_error_msg(e)
53        except ImportError:
54            print("please update to latest firmware")

示例输出:

None

API参考

ATOMGPSBase

class base.atom_gps.ATOMGPSBase(id=1, port=None, debug=False)

基类:object

创建 ATOMGPSBase 对象。

参数:
  • id (int) – UART ID 号可使用 0, 1, 2, 默认使用2。

  • port (list | tuple) – 包含 TX 和 RX 引脚编号的列表或元组。

  • debug (bool) – 是否启用调试模式, 默认为不开启。

UiFlow2 代码块:

init.png

MicroPython 代码块:

from machine import UART
from base import ATOMGPSBase

gps = ATOMGPSBase(id=1, port=(16, 17))
get_antenna_state()

获取当前的天线状态。

返回:

当前的天线状态。

返回类型:

str

UiFlow2 代码块:

get_antenna_state.png

MicroPython 代码块:

gps.get_antenna_state()
get_gps_time()

获取当前 GPS 时间。

返回:

以 [时、分、秒] 字符串列表形式显示的 GPS 时间。

返回类型:

list[str]

UiFlow2 代码块:

get_gps_time.png

MicroPython 代码块:

gps.get_gps_time()
get_gps_date()

获取当前的 GPS 日期。

返回:

以字符串 [日、月、年] 列表形式显示的 GPS 日期。

返回类型:

list[str]

UiFlow2 代码块:

get_gps_date.png

MicroPython 代码块:

gps.get_gps_date()
get_gps_date_time()

获取当前 GPS 日期和时间。

返回:

GPS 日期和时间的字符串列表 [年、月、日、时、分、秒]。

返回类型:

list[str]

UiFlow2 代码块:

get_gps_date_time.png

MicroPython 代码块:

gps.get_gps_date_time()
get_timestamp()

获取当前 GPS 时间的时间戳。

返回:

代表当前 GPS 时间的时间戳。

返回类型:

int | float

UiFlow2 代码块:

get_timestamp.png

MicroPython 代码块:

gps.get_timestamp()
get_latitude()

取当前的海拔高度”

返回:

当前的海拔高度。

返回类型:

str

UiFlow2 代码块:

get_latitude.png

MicroPython 代码块:

gps.get_latitude()
get_longitude()

获取当前纬度。

返回:

获取当前纬度。

返回类型:

str

UiFlow2 代码块:

get_longitude.png

MicroPython 代码块:

gps.get_longitude()
get_altitude()

获取当前的海拔高度。

返回:

获取当前的海拔高度。

返回类型:

str

UiFlow2 代码块:

get_altitude.png

MicroPython 代码块:

gps.get_altitude()
get_satellite_num()

获取用于定位的卫星数量。

返回:

卫星数量。

返回类型:

str

UiFlow2 代码块:

get_satellite_num.png

MicroPython 代码块:

gps.get_satellite_num()
get_pos_quality()

获取 GPS 定位质量。

返回:

位置质量指标。

返回类型:

str

UiFlow2 代码块:

get_pos_quality.png

MicroPython 代码块:

gps.get_pos_quality()
get_corse_over_ground()

获取当前相对地面真航向。

返回:

相对地面真航向。

返回类型:

str

UiFlow2 代码块:

get_corse_over_ground.png

MicroPython 代码块:

gps.get_corse_over_ground()
get_speed_over_ground()

获取获取地面速度。

返回:

对地面速度,单位为节。

返回类型:

str

UiFlow2 代码块:

get_speed_over_ground.png

MicroPython 代码块:

gps.get_speed_over_ground()
set_time_zone(value)

设置 GPS 时间的时区偏移。

参数:

value (int) – 要设置的时区偏移值。

返回类型:

None

UiFlow2 代码块:

set_time_zone.png

MicroPython 代码块:

gps.set_time_zone(8)
get_time_zone()

获取当前时区偏移。

返回:

当前时区偏移。

返回类型:

int

UiFlow2 代码块:

get_time_zone.png

MicroPython 代码块:

gps.get_time_zone()
deinit()

取消 GPS 设备的初始化,停止正在运行的任务并释放资源。

UiFlow2 代码块:

deinit.png

MicroPython 代码块:

gps.deinit()
返回类型:

None