Skip to content

Instantly share code, notes, and snippets.

@pixelatedpic
Created July 26, 2018 09:50
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 pixelatedpic/4993ad76a4dbf1ec359afe2a86aa691c to your computer and use it in GitHub Desktop.
Save pixelatedpic/4993ad76a4dbf1ec359afe2a86aa691c to your computer and use it in GitHub Desktop.
Raspberry PI interfaced GPS
import serial
from time import sleep
gpsport = serial.Serial("/dev/ttyAMA0",bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0)
#gpsport.flush()
#sleep(5)
while True:
# sleep(.5)
# gpsport.flush()
raw = gpsport.readline()
# print(raw)
if raw != 0xff:
rxgps = raw.decode('utf-8')[:-1]
else:
rxgps = ""
# rxgps = gpsport.readline().decode('utf-8')[:-1]
#rxgps = gpsport.readline()
#line = .decode('utf-8')[:-1]
data = rxgps.split(',')
#print(data[1])
# print(rxgps)
if data[0] == "$GPGGA":
print(rxgps)
# print(data[1])
UTCtime = data[1]
Latitude = data[2]
Longitude = data[4]
SAT = data[7]
FIX = data[6]
print("UTC: " + UTCtime)
print("SAT: " + SAT)
print("FIX: " + FIX)
print("LAT: " + Latitude)
print("LON: " + Longitude)
gpsport.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment