【得捷电子Follow me第1期】任务4:实现定位功能
[复制链接]
本帖最后由 doudoubaba 于 2023-6-26 23:21 编辑
下载,并导入micropyGPS库
代码:
from machine import UART, Pin
from micropyGPS import MicropyGPS
import time
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
time.sleep(0.1)
rxData = bytes()
my_gps = MicropyGPS()
while True:
if uart0.any():
stat = my_gps.update(uart0.read(1).decode("ascii"))
if stat:
print("Latitude:", my_gps.latitude_string()) #读取经度、纬度信息
print("Longitude:", my_gps.longitude_string())
print("Speed:",my_gps.speed_string("kph"),"or",my_gps.speed_string("mph"),"or", my_gps.speed_string("knot"),) #读取速度信息
print("Date (Long Format):", my_gps.date_string("long")) #读取时间信息
print("Date (Short D/M/Y Format):", my_gps.date_string("s_dmy"))
print("timestamp (Short [H,M,S] Format):", my_gps.timestamp)
stat = None
运行结果:
|