【得捷电子Follow me第1期】任务4:实现定位功能
[复制链接]
驱动GNSS定位模块
GNSS模块使用串口通信,只需要导入machine.UART类,配置串口后就能接收到定位模块传回的数据了。
from machine import Pin, UART, I2C
from ssd1306 import SSD1306_I2C
import utime, time
#Grove Shield for Pi Pico I2C0
i2c = I2C(0, sda = Pin(8), scl = Pin(9), freq = 400000)
oled = SSD1306_I2C(128, 64, i2c)
#Grove Shield For Pi Pico UART0
gps_module = UART(0, baudrate = 9600, tx = Pin(0), rx = Pin(1))
while True:
if gps_module.any():
utime.sleep_ms(100)
bin_data = gps_module.readline()
print(bin_data)
GPS用于定位和授时。
# 在这里写上你的代码 :-)
from machine import Pin, UART, I2C
from ssd1306 import SSD1306_I2C
from micropyGPS import MicropyGPS
import utime, time
#Grove Shield for Pi Pico I2C0
i2c = I2C(0, sda = Pin(8), scl = Pin(9), freq = 400000)
oled = SSD1306_I2C(128, 64, i2c)
#Grove Shield For Pi Pico UART0
gps_module = UART(0, baudrate = 9600, tx = Pin(0), rx = Pin(1))
my_gps = MicropyGPS()
while True:
if gps_module.any():
utime.sleep_ms(100)
bin_data = gps_module.readline()
#print(bin_data)
str_bd = str(bin_data)[1:]
if str_bd[1:7] == '$GNRMC':
my_sentence = str_bd
for x in my_sentence:
my_gps.update(x)
print("my_gps.latitude", my_gps.latitude)
print("my_gps.longitude", my_gps.longitude)
print("my_gps.date", my_gps.date)
print("my_gps.timestamp", my_gps.timestamp)
|