【得捷电子Follow me第1期】任务4:实现定位功能
[复制链接]
定位解析使用了大佬的库
from machine import Pin, I2C, UART
i2c1 = I2C(1,sda=Pin(6), scl=Pin(7))
from ssd1306 import SSD1306_I2C
oled = SSD1306_I2C(128, 64, i2c1)
import time
oled.fill(0)
oled.text('GPS', 0, 0)
oled.show()
time.sleep(1.0)
import hashlib
from micropyGPS import MicropyGPS
my_gps = MicropyGPS(local_offset=8)
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
while True:
if uart0.any()>0:
# print(uart0.read(1))
state = my_gps.update(uart0.read(1).decode('utf-8'))
if state:
state = None
oled.fill(0)
lat_disp = my_gps.latitude_string()
oled.text(lat_disp,5,10)
lon_disp = my_gps.longitude_string()
oled.text(lon_disp,5,20)
date_disp = my_gps.date_string('s_mdy')
oled.text(date_disp,5,30)
time_disp = str(my_gps.timestamp[0]) +':'+str(my_gps.timestamp[1])+':'+str(my_gps.timestamp[2])
oled.text(time_disp,5,40)
oled.show()
已经可以看到获取到的时间了,不过因为在房间的缘故,定位信息获取的比较慢,还得在窗户边;
不过在室外应该就能很容易获取位置信息了
|