【得捷电子Follow me第1期】第八帖 - 获取定位数据
[复制链接]
GPS模块时参考其他大神的帖子完成的,在室内确实是没有信号,需要把天线挪动到窗边才行。
代码如下
from machine import UART, Pin
import time
import hashlib
from micropyGPS import MicropyGPS
from machine import Pin
import time
from machine import PWM
from machine import I2C
from ssd1306 import SSD1306_I2C
import framebuf
WIDTH = 128
HEIGHT = 64
i2c = I2C(1)
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) # Init I2C using I2C0 defaults, SCL=Pin(GP9), SDA=Pin(GP8), freq=400000
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')) # Note the conversion to to chr, UART outputs ints normally
if stat:
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,30)
time_disp = my_gps.date_string('s_dmy')
oled.text(time_disp,5,50)
oled.show()
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
|