import serial gpsPort = "/dev/ttyACM0" gpsSerial = serial.Serial(gpsPort, baudrate = 9600, timeout = 0.5) def parseGPS(data): gps = data try: if gps[2:8] == "$GNGGA": gps = gps.split(",") timeHour = (int(gps[1][0:2]) - 4) % 24 timeMin = int(gps[1][2:4]) timeSec = int(gps[1][4:6]) print("Time: " + str(timeHour) + ":" + str(timeMin) + ":" + str(timeSec)) latDeg = int(gps[2][0:2]) latMin = int(gps[2][2:4]) latSec = float(gps[2][5:9]) * (3/500) latNS = gps[3] print("Latitude: " + str(latDeg) + "°" + str(latMin) + "'" + str(latSec) + '" ' + latNS) longDeg = int(gps[4][0:3]) longMin = int(gps[4][3:5]) longSec = float(gps[4][6:10]) * (3/500) longEW = gps[5] print("Longitude: " + str(longDeg) + "°" + str(longMin) + "'" + str(longSec) + '" ' + longEW) alt = float(gps[9]) print("Altitude: " + str(alt) + " m") sat = int(gps[7]) print("Satellites: " + str(sat)) if gps[2:8] == "$GNRMC": gps = gps.split(",") speed = float(gps[7]) * 1.852 print("Speed: " + str(speed) + " km/h") head = float(gps[8]) print("Heading: " + str(head)) else: gps = "" except Exception as error: print(error) return gps while True: print(parseGPS(gpsSerial.readline()))