Created
January 31, 2019 19:56
-
-
Save mfa/94a9e508669508d1651d7f3e5958a5ec to your computer and use it in GitHub Desktop.
GPS "GY-GPS6MV2" at serial of a RPi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3.6+ | |
import pynmea2 | |
import serial | |
s = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) | |
line = "" | |
while True: | |
try: | |
line = s.readline().decode() | |
except UnicodeDecodeError: | |
pass | |
if line.startswith("$GPGGA"): | |
msg = pynmea2.parse(line) | |
print(f'lat: {msg.latitude:2.4f} {msg.lat_dir}') | |
print(f'lon: {msg.longitude:2.4f} {msg.lon_dir}') | |
print(f'time: {msg.timestamp}') | |
print(f'num_sat: {msg.num_sats}') | |
print(f'alt: {msg.altitude}') | |
print('-' * 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment