-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgps_util.py
More file actions
34 lines (30 loc) · 894 Bytes
/
Copy pathgps_util.py
File metadata and controls
34 lines (30 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Parse NMEA packets from a UBlox M10 GPS module hooked up to a Bit Pirate.
from bitpirate import BitPirateWifi
import time
import os
import pynmea2 # pip install pynmea2
from uart_connect_helper import connect_uart
# Connect to the Bit Pirate
bp = BitPirateWifi("192.168.0.57")
bp.start()
connect_uart(bp, tx_pin=43, rx_pin=44, baudrate=115200, bits=8, parity="N", stop=1, inverted=False)
# Start UART read mode
bp.send("read")
bp.wait()
bp.clear_echoes(2)
print("GPS from UART started")
try:
while True:
lines = bp.receive(skip=0)
if lines:
for line in lines:
try:
msg = pynmea2.parse(line + "\n")
print(repr(msg))
except pynmea2.ParseError as e:
pass
except KeyboardInterrupt:
print("\nStopping GPS read...")
finally:
# Close the connection
bp.stop()