-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps.py
27 lines (26 loc) · 778 Bytes
/
gps.py
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
#gps sensor
#for use with the seeed grove gps sensor (SIM28 based)
#uses UART (serial) 9600 8-N-1
import mraa
def getLocation():
u = mraa.Uart(0)
u.setBaudRate(9600)
GPSData = [0,0,0]
while(True):
if(u.dataAvailable()):
buff = u.readStr(256)
if buff.find("GPGGA") != -1: #this is the easiest to parse
smallerbuff = buff[buff.find("GPGGA"): buff.find("\n")]
splitbuff = smallerbuff.strip().split(",")
#print(splitbuff)
latnmea = splitbuff[2]
latdir = splitbuff[3]
lonnmea = splitbuff[4]
londir = splitbuff[5]
lat = float(latnmea[0:2]) + float(latnmea[2:])/60
lon = float(lonnmea[0:3]) + float(lonnmea[3:])/60
if londir == "W":
lon = lon * -1
alt = float(splitbuff[9])
GPSData = [lat,lon,alt]
return GPSData