Here's an example. Needs a pi camera, a USB GPS, 4 leds and 2 buttons.
Note it simply logs the NMEA data, you'll need to decode it if needed.
Pressing BOTH buttons will shutdown the PI.
Code: Select all
#!/usr/bin/python3
import serial
import os, sys
import RPi.GPIO as GPIO
import time
import datetime
import re
import pygame
from pygame.locals import *
import shutil
from decimal import *
getcontext().prec = 8
pygame.init()
gps_period = 10 # time ,in seconds, between logged gps data
# select leds and buttons
gps_led1 = 16 # gps fix (flashes if no fix, ON if fixed) (led, with resistor, between physical gpio pin 16 and gnd)
gps_led2 = 18 # gps valid data, flashes with valid data (led, with resistor, between physical gpio pin 18 and gnd)
track_led = 22 # ON = track logging enabled, pulses OFF when writing to log. (led, with resistor, between physical gpio pin 22 and gnd)
photo_led = 24 # photo being taken (led, with resistor, between physical gpio pin 24 and gnd)
track_button = 40 # press for tracking ON/OFF (button between physical gpio pin 40 and gnd)
photo_button = 36 # press to take a photo (button between physical gpio pin 36 and gnd)
# ALL leds ON means no gps found on USB0 or 1 at start.
# Pressing BOTH buttons will shutdown the Pi
# picture and log directories
pic_dir = "/home/pi/Pictures/" # will create a daily sub-directory based on date eg. /home/pi/Pictures/200715
log_dir = "/home/pi/Documents/" # will create a daily sub-directory based on date eg. /home/pi/Documents/200715
# setup GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(track_button,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(photo_button,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(gps_led1,GPIO.OUT)
GPIO.output(gps_led1,GPIO.LOW)
GPIO.setup(gps_led2,GPIO.OUT)
GPIO.output(gps_led2,GPIO.LOW)
GPIO.setup(track_led,GPIO.OUT)
GPIO.output(track_led,GPIO.LOW)
GPIO.setup(photo_led,GPIO.OUT)
GPIO.output(photo_led,GPIO.LOW)
# set variables
gpsfound = 2
fix = 0
track = 0
start = time.time()
gps_data = ""
gps_text = ""
gps_date = ""
gps_time = ""
if os.path.exists('/dev/ttyUSB0') == True:
gpsfound = 0
ser = serial.Serial('/dev/ttyUSB0',4800,timeout = 10)
elif os.path.exists('/dev/ttyUSB1') == True:
gpsfound = 1
ser = serial.Serial('/dev/ttyUSB1',4800,timeout = 10)
if gpsfound == 2:
GPIO.output(gps_led1,GPIO.HIGH)
GPIO.output(gps_led2,GPIO.HIGH)
GPIO.output(track_led,GPIO.HIGH)
GPIO.output(photo_led,GPIO.HIGH)
while True:
# take a photo
if GPIO.input(photo_button) == 0 and GPIO.input(track_button) == 1:
GPIO.output(photo_led,GPIO.HIGH)
if gps_date == "" or gps_time == "":
now = datetime.datetime.now()
timestamp = now.strftime("%y%m%d%H%M%S")
timestamp_dir = pic_dir + now.strftime("%y%m%d") + "/"
else:
timestamp = gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + gps_time
timestamp_dir = pic_dir + gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + "/"
if not os.path.exists(timestamp_dir ):
os.system('mkdir ' + timestamp_dir)
imagefile = "/run/shm/" + timestamp + ".jpg"
path = "raspistill -n -t 2000 -o " + imagefile
os.system(path)
# add gps_data to photo if GPS locked
if gps_text != "" and fix > 0:
image = pygame.image.load(imagefile)
width,height = image.get_size()
windowSurfaceObj = pygame.display.set_mode((width,height), 0, 24)
catSurfaceObj = image
windowSurfaceObj.blit(catSurfaceObj, (0, 0))
fontObj = pygame.font.Font('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', 50)
msgSurfaceObj = fontObj.render(gps_text, False, (255,255,255))
msgRectobj = msgSurfaceObj.get_rect()
msgRectobj.topleft = (0,height - 50)
windowSurfaceObj.blit(msgSurfaceObj, msgRectobj)
pygame.display.update()
pygame.image.save(windowSurfaceObj,timestamp_dir + timestamp + ".jpg")
pygame.display.quit()
else:
shutil.copy(imagefile,timestamp_dir + timestamp + ".jpg")
GPIO.output(photo_led,GPIO.LOW)
# switch tracking to log ON/OFF
if GPIO.input(track_button) == 0 and GPIO.input(photo_button) == 1:
if track == 0:
track = 1
GPIO.output(track_led,GPIO.HIGH)
else:
track = 0
GPIO.output(track_led,GPIO.LOW)
time.sleep(0.5)
if GPIO.input(track_button) == 0 and GPIO.input(photo_button) == 0:
GPIO.output(gps_led1,GPIO.LOW)
GPIO.output(gps_led2,GPIO.LOW)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
os.system("sudo shutdown -h now")
# read gps data
if gpsfound < 2:
try:
gps_data = ser.readline()
#print (gps_data)
if sys.version_info[0] == 3:
gps_data = gps_data.decode("utf-8","ignore")
except OSError:
try:
fix = 0
gps_text = ""
if os.path.exists('/dev/ttyUSB0') == True:
gpsfound = 0
ser = serial.Serial('/dev/ttyUSB0',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
elif os.path.exists('/dev/ttyUSB1') == True:
gpsfound = 1
ser = serial.Serial('/dev/ttyUSB1',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
except OSError:
pass
else:
try:
fix = 0
gps_text = ""
if os.path.exists('/dev/ttyUSB0') == True:
gpsfound = 0
ser = serial.Serial('/dev/ttyUSB0',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
elif os.path.exists('/dev/ttyUSB1') == True:
gpsfound = 1
ser = serial.Serial('/dev/ttyUSB1',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
except OSError:
pass
if fix < 1:
GPIO.output(gps_led1,GPIO.HIGH)
time.sleep(0.25)
GPIO.output(gps_led1,GPIO.LOW)
time.sleep(0.25)
if os.path.exists('/dev/ttyUSB0') == False and os.path.exists('/dev/ttyUSB1') == False:
GPIO.output(gps_led2,GPIO.HIGH)
GPIO.output(track_led,GPIO.HIGH)
GPIO.output(photo_led,GPIO.HIGH)
# check checksum
if gps_data[0:1] == "$":
GPIO.output(gps_led2,GPIO.LOW)
gps_data = gps_data.rstrip('\n')
cksum = gps_data[len(gps_data) - 3:]
chksumdata = re.sub("(\n|\r\n)","", gps_data[gps_data.find("$")+1:gps_data.find("*")])
csum = 0
for c in chksumdata:
csum ^= ord(c)
if hex(csum) == hex(int(cksum, 16)):
# check for GPGGA sentences
if gps_data[1:6] == "GPGGA":
fix = 0
gps_data2 = gps_data
gps1 = gps_data.split(',',12)
if len(gps_data) > 68 and (gps1[3] == "N" or gps1[3] == "S"):
fix = int(gps1[6])
if fix > 0:
GPIO.output(gps_led1,GPIO.HIGH)
GPIO.output(gps_led2,GPIO.HIGH)
lat1 = int(gps1[2][0:2])
lat2 = float(gps1[2]) - (lat1*100)
lat = lat1 + lat2/60
lon1 = int(gps1[4][0:3])
lon2 = float(gps1[4]) - (lon1*100)
lon = lon1 + lon2/60
gps_time = gps1[1][0:6]
gps_text = "Location: "+str(lat)[0:9]+" "+gps1[3]+" "+str(lon)[0:9]+" "+gps1[5]+" Time: "+gps_time[0:2]+":"+gps_time[2:4]+":"+gps_time[4:6]+" Date: "+gps_date[4:6]+"/"+ gps_date[2:4]+"/"+ gps_date[0:2]
# log data if enabled
if track == 1 and time.time() - start > gps_period:
start = time.time()
GPIO.output(track_led,GPIO.LOW)
time.sleep(0.2)
if gps_date == "" or gps_time == "":
now = datetime.datetime.now()
timestamp = now.strftime("%y%m%d%H%M%S")
timestamp_dir = log_dir + now.strftime("%y%m%d") + "/"
else:
timestamp = gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + gps_time
timestamp_dir = log_dir + gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + "/"
if not os.path.exists(timestamp_dir):
os.system('mkdir ' + timestamp_dir)
with open(timestamp_dir + "log.txt", "a") as file:
file.write(gps_data)
GPIO.output(track_led,GPIO.HIGH)
time.sleep(0.2)
if fix > 0 and gps_text != "":
if gps_data[1:6] == "GPRMC":
gps2 = gps_data.split(',',12)
gps_date = gps2[9]
Code: Select all
#!/usr/bin/python3
import serial
import os, sys
import RPi.GPIO as GPIO
import time
import datetime
import re
import pygame
from pygame.locals import *
import shutil
from decimal import *
getcontext().prec = 8
pygame.init()
# set gps data track logging period
gps_period = 10 # time ,in seconds
# select leds and buttons
gps_led1 = 16 # gps fix (flashes if no fix, ON if fixed) (led, with resistor, between physical gpio pin 16 and gnd)
gps_led2 = 18 # gps valid data, flashes with valid data (led, with resistor, between physical gpio pin 18 and gnd)
track_led = 22 # ON = track logging enabled, pulses OFF when writing to log. (led, with resistor, between physical gpio pin 22 and gnd)
photo_led = 24 # photo being taken (led, with resistor, between physical gpio pin 24 and gnd)
track_button = 40 # press for tracking ON/OFF (button between physical gpio pin 40 and gnd)
photo_button = 36 # press to take a photo (button between physical gpio pin 36 and gnd)
# ALL leds ON means no gps found on USB0 or 1.
# Pressing BOTH buttons will shutdown the Pi.
# set screen resolution
scr_width = 720
scr_height = 480
# set Pi to gps (UTC) time
settime = 0 # set to 1 to set Pi time when gps fixes
# picture and log directories
pic_dir = "/home/pi/Pictures/" # will create a daily sub-directory based on date eg. /home/pi/Pictures/200715
log_dir = "/home/pi/Documents/" # will create a daily sub-directory based on date eg. /home/pi/Documents/200715
# setup GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(track_button,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(photo_button,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(gps_led1,GPIO.OUT)
GPIO.output(gps_led1,GPIO.LOW)
GPIO.setup(gps_led2,GPIO.OUT)
GPIO.output(gps_led2,GPIO.LOW)
GPIO.setup(track_led,GPIO.OUT)
GPIO.output(track_led,GPIO.LOW)
GPIO.setup(photo_led,GPIO.OUT)
GPIO.output(photo_led,GPIO.LOW)
# set variables
gpsfound = 2
fix = 0
track = 0
start = time.time()
gps_data = ""
gps_text = ""
gps_date = ""
gps_time = ""
gps_speed = ""
gps_angle = ""
gps_3Dfix = ""
gps_alt = ""
gps_alt2 = ""
lat = 0
lon = 0
gps1 = [0,0,0,0,0,0,0,0,0,0,0,0]
if os.path.exists('/dev/ttyUSB0') == True:
gpsfound = 0
ser = serial.Serial('/dev/ttyUSB0',4800,timeout = 10)
elif os.path.exists('/dev/ttyUSB1') == True:
gpsfound = 1
ser = serial.Serial('/dev/ttyUSB1',4800,timeout = 10)
if gpsfound == 2:
GPIO.output(gps_led1,GPIO.HIGH)
GPIO.output(gps_led2,GPIO.HIGH)
GPIO.output(track_led,GPIO.HIGH)
GPIO.output(photo_led,GPIO.HIGH)
global greyColor, redColor, greenColor, blueColor, dgryColor, lgryColor, blackColor, whiteColor, purpleColor, yellowColor
bredColor = pygame.Color(255, 0, 0)
lgryColor = pygame.Color(192, 192, 192)
blackColor = pygame.Color( 0, 0, 0)
whiteColor = pygame.Color(200, 200, 200)
greyColor = pygame.Color(128, 128, 128)
dgryColor = pygame.Color( 64, 64, 64)
greenColor = pygame.Color( 0, 255, 0)
purpleColor = pygame.Color(255, 0, 255)
yellowColor = pygame.Color(255, 255, 0)
blueColor = pygame.Color( 0, 0, 255)
redColor = pygame.Color(200, 0, 0)
def text(row,fColor,top,upd,msg,fsize,bcolor):
colors = [dgryColor, greenColor, yellowColor, redColor, greenColor, blueColor, whiteColor, greyColor, blackColor, purpleColor]
Color = colors[fColor]
bColor = colors[bcolor]
bx = 0
by = row * 22
if os.path.exists ('/usr/share/fonts/truetype/freefont/FreeSerif.ttf'):
fontObj = pygame.font.Font('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', int(fsize))
else:
fontObj = pygame.font.Font(None, int(fsize))
msgSurfaceObj = fontObj.render(msg, False, Color)
msgRectobj = msgSurfaceObj.get_rect()
if top == 0:
pygame.draw.rect(windowSurfaceObj,bColor,Rect(bx+1,by+1,70,22))
msgRectobj.topleft = (bx + 5, by + 2)
else:
pygame.draw.rect(windowSurfaceObj,bColor,Rect(bx+70,by+1,100,22))
msgRectobj.topleft = (bx + 70, by + 2)
windowSurfaceObj.blit(msgSurfaceObj, msgRectobj)
if upd == 1:
pygame.display.update(bx, by, 190, 40)
windowSurfaceObj = pygame.display.set_mode((scr_width,scr_height), pygame.NOFRAME, 24)
text(1,2,0,1,"Fix Q",18,7)
while True:
# take a photo
if GPIO.input(photo_button) == 0 and GPIO.input(track_button) == 1:
GPIO.output(photo_led,GPIO.HIGH)
if gps_date == "" or gps_time == "":
now = datetime.datetime.now()
timestamp = now.strftime("%y%m%d%H%M%S")
timestamp_dir = pic_dir + now.strftime("%y%m%d") + "/"
else:
timestamp = gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + gps_time
timestamp_dir = pic_dir + gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + "/"
if not os.path.exists(timestamp_dir ):
os.system('mkdir ' + timestamp_dir)
imagefile = "/run/shm/" + timestamp + ".jpg"
path = "raspistill -t 2000 -o " + imagefile + " -p 0,0," + str(scr_width) + "," + str(scr_height)
os.system(path)
# add gps_text to photo if GPS locked
if gps_text != "" and fix > 0:
image = pygame.image.load(imagefile)
width,height = image.get_size()
windowSurfaceObj = pygame.display.set_mode((width,height), 0, 24)
catSurfaceObj = image
windowSurfaceObj.blit(catSurfaceObj, (0, 0))
fontObj = pygame.font.Font('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', 70)
msgSurfaceObj = fontObj.render(gps_text, False, (255,255,255))
msgRectobj = msgSurfaceObj.get_rect()
msgRectobj.topleft = (0,height - 70)
windowSurfaceObj.blit(msgSurfaceObj, msgRectobj)
pygame.display.update()
pygame.image.save(windowSurfaceObj,timestamp_dir + timestamp + ".jpg")
pygame.display.quit()
image = pygame.image.load(timestamp_dir + timestamp + ".jpg")
image = pygame.transform.scale(image, (scr_width,scr_height))
windowSurfaceObj = pygame.display.set_mode((scr_width,scr_height), pygame.NOFRAME, 24)
catSurfaceObj = image
windowSurfaceObj.blit(catSurfaceObj, (0, 0))
pygame.display.update()
else:
image = pygame.image.load(imagefile)
image = pygame.transform.scale(image, (scr_width,scr_height))
windowSurfaceObj = pygame.display.set_mode((scr_width,scr_height), 0, 24)
catSurfaceObj = image
windowSurfaceObj.blit(catSurfaceObj, (0, 0))
pygame.display.update()
shutil.copy(imagefile,timestamp_dir + timestamp + ".jpg")
# confirm saved by flashing photo_led twice
if os.path.exists(timestamp_dir + timestamp + ".jpg"):
GPIO.output(photo_led,GPIO.LOW)
time.sleep(0.1)
GPIO.output(photo_led,GPIO.HIGH)
time.sleep(0.1)
GPIO.output(photo_led,GPIO.LOW)
time.sleep(0.1)
GPIO.output(photo_led,GPIO.HIGH)
time.sleep(0.1)
GPIO.output(photo_led,GPIO.LOW)
# switch tracking to log ON/OFF (can only be switched on if gps fixed)
if GPIO.input(track_button) == 0 and GPIO.input(photo_button) == 1 and fix > 0:
if track == 0:
track = 1
GPIO.output(track_led,GPIO.HIGH)
else:
track = 0
GPIO.output(track_led,GPIO.LOW)
time.sleep(0.5)
# press BOTH buttons to shutdown Pi
if GPIO.input(track_button) == 0 and GPIO.input(photo_button) == 0:
GPIO.output(gps_led1,GPIO.LOW)
GPIO.output(gps_led2,GPIO.LOW)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
os.system("sudo shutdown -h now")
# read gps data
if gpsfound < 2:
try:
gps_data = ser.readline()
#print (gps_data)
if sys.version_info[0] == 3:
gps_data = gps_data.decode("utf-8","ignore")
except OSError:
try:
fix = 0
gps_text = ""
if os.path.exists('/dev/ttyUSB0') == True:
gpsfound = 0
ser = serial.Serial('/dev/ttyUSB0',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
elif os.path.exists('/dev/ttyUSB1') == True:
gpsfound = 1
ser = serial.Serial('/dev/ttyUSB1',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
except OSError:
pass
else:
try:
fix = 0
gps_text = ""
if os.path.exists('/dev/ttyUSB0') == True:
gpsfound = 0
ser = serial.Serial('/dev/ttyUSB0',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
elif os.path.exists('/dev/ttyUSB1') == True:
gpsfound = 1
ser = serial.Serial('/dev/ttyUSB1',4800,timeout = 10)
GPIO.output(track_led,GPIO.LOW)
GPIO.output(photo_led,GPIO.LOW)
except OSError:
pass
if fix < 1:
GPIO.output(gps_led1,GPIO.HIGH)
time.sleep(0.25)
GPIO.output(gps_led1,GPIO.LOW)
time.sleep(0.25)
if os.path.exists('/dev/ttyUSB0') == False and os.path.exists('/dev/ttyUSB1') == False:
GPIO.output(gps_led2,GPIO.HIGH)
GPIO.output(track_led,GPIO.HIGH)
GPIO.output(photo_led,GPIO.HIGH)
if settime == 1 and gps_date != "" and gps_date !="":
path = "sudo date -s '" + "20" + gps_date[4:6] + "-" + gps_date[2:4] + "-" + gps_date[0:2] + " " + gps_time[0:2] + ":" + gps_time[2:4] + ":" + gps_time[4:6] + "'"
os.system (path)
settime = 0
# check checksum
if gps_data[0:1] == "$":
GPIO.output(gps_led2,GPIO.LOW)
gps_data = gps_data.rstrip('\n')
cksum = gps_data[len(gps_data) - 3:]
chksumdata = re.sub("(\n|\r\n)","", gps_data[gps_data.find("$")+1:gps_data.find("*")])
csum = 0
for c in chksumdata:
csum ^= ord(c)
if hex(csum) == hex(int(cksum, 16)):
# check for GPGGA sentences
if gps_data[1:6] == "GPGGA":
fix = 0
gps_data2 = gps_data
gps1 = gps_data.split(',',12)
if len(gps_data) > 68 and (gps1[3] == "N" or gps1[3] == "S"):
fix = int(gps1[6])
if fix > 0:
GPIO.output(gps_led1,GPIO.HIGH)
GPIO.output(gps_led2,GPIO.HIGH)
lat1 = int(gps1[2][0:2])
lat2 = float(gps1[2]) - (lat1*100)
lat = lat1 + lat2/60
lon1 = int(gps1[4][0:3])
lon2 = float(gps1[4]) - (lon1*100)
lon = lon1 + lon2/60
gps_time = gps1[1][0:6]
gps_text = "Location: "+str(lat)[0:9]+" "+gps1[3]+" "+str(lon)[0:9]+" "+gps1[5]+" Time: "+gps_time[0:2]+":"+gps_time[2:4]+":"+gps_time[4:6]+" Date: "+gps_date[4:6]+"/"+ gps_date[2:4]+"/"+ gps_date[0:2]
gps_alt = gps1[9]
gps_alt2 = gps1[10]
# log data if enabled
if track == 1 and time.time() - start > gps_period:
start = time.time()
GPIO.output(track_led,GPIO.LOW)
time.sleep(0.2)
if gps_date == "" or gps_time == "":
now = datetime.datetime.now()
timestamp = now.strftime("%y%m%d%H%M%S")
timestamp_dir = log_dir + now.strftime("%y%m%d") + "/"
else:
timestamp = gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + gps_time
timestamp_dir = log_dir + gps_date[4:6] + gps_date[2:4] + gps_date[0:2] + "/"
if not os.path.exists(timestamp_dir):
os.system('mkdir ' + timestamp_dir)
with open(timestamp_dir + "log.txt", "a") as file:
file.write(gps_data)
GPIO.output(track_led,GPIO.HIGH)
time.sleep(0.2)
text(1,2,0,1,"Fix Q",18,7)
text(1,fix,1,1,str(fix),18,7)
if gps_date !="" and gps_time !="" and gps1[3] != 0:
text(3,2,0,1,"Lat",18,7)
text(3,fix,1,1,str(lat)[0:9] + gps1[3],18,7)
text(4,2,0,1,"Lon",18,7)
text(4,fix,1,1,str(lon)[0:9] + gps1[5],18,7)
text(5,2,0,1,"Time",18,7)
text(5,fix,1,1,gps_time[0:2]+":"+gps_time[2:4]+":"+gps_time[4:6],18,7)
text(6,2,0,1,"Date",18,7)
text(6,fix,1,1,gps_date[4:6]+"/"+ gps_date[2:4]+"/"+ gps_date[0:2],18,7)
text(1,2,0,1,"Fix Q",18,7)
text(1,fix,1,1,str(fix),18,7)
text(7,2,0,1,"Speed",18,7)
text(7,fix,1,1,str(gps_speed),18,7)
text(8,2,0,1,"Angle",18,7)
text(8,fix,1,1,str(gps_angle),18,7)
text(9,2,0,1,"Altitude",18,7)
text(9,fix,1,1,str(gps_alt)+str(gps_alt2),18,7)
text(2,2,0,1,"3D Fix",18,7)
text(2,fix,1,1,str(gps_3Dfix)+"D",18,7)
if fix > 0 and gps_text != "":
if gps_data[1:6] == "GPRMC":
gps2 = gps_data.split(',',12)
gps_date = gps2[9]
gps_speed = gps2[7]
gps_angle = gps2[8]
if fix > 0:
if gps_data[1:6] == "GPGSA":
gps_3Dfix = gps_data[9:10]