Skip to content

Instantly share code, notes, and snippets.

@mfa
Created January 31, 2019 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfa/94a9e508669508d1651d7f3e5958a5ec to your computer and use it in GitHub Desktop.
Save mfa/94a9e508669508d1651d7f3e5958a5ec to your computer and use it in GitHub Desktop.
GPS "GY-GPS6MV2" at serial of a RPi
# 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