This is what I had initially and not this was not the solution.bensimmo wrote: ↑Sat Sep 21, 2019 9:12 amI just check and if you stay with Google earth, it can use Decimal Degrees.
So you only need to record
msg.latitude & msg.longitude
(Same as Google maps)
You don't need to split and combine.
EDIT simple test program for you (another one, this is python3)
EDIT2, added logging to a file for ease.
Code: Select all
#!/usr/bin/python3 import pynmea2 # NMEA GNSS splitter import serial # sudo pip3 install pyserial # GPIO/USB serial read from csv import writer GNSS_PORT = "/dev/ttyACM0" #GNSS_PORT = "/dev/serial0" serialPort = serial.Serial(GNSS_PORT, 9600, timeout=1.5) with open('gpslog.csv', 'w', newline='') as f: data_writer = writer(f) data_writer.writerow([ 'latitude', 'longitude', 'altitude' ]) # data headers while True: strip = serialPort.readline() if strip.find(b'GGA') > 0: msg = pynmea2.parse(strip.decode('utf-8')) print( msg.latitude, msg.longitude, msg.altitude ) data_writer.writerow([ msg.latitude, msg.longitude, msg.altitude ])
I have to say it is fixed - and yes it was Pynmea2
Between myself an an ex-workmate we figured things out.
It would appear that pynmea2 was written by someone close to the equator, and had not anticipated someone so far from the equator might use it. this meant that a lat value increment represents something like 60% less distance here - leading to the "scaled" appearance of my coords.
We discovered that pnmea2 was doing something odd to the string as it parsed it.
The dd_to_sd function is mathematically correct, but the parsing was not.
So we decided to do the math ourselves, and amazingly it worked!
Splitting the string into an array and referencing each relevant section allowed us to do the math ourselves.
I'll be gradually phasing out pynmea2 altogether in favor of this method.
The GPS is fine, the serial interface is fine
My current "working" code, that has not been cleaned up yet is as follows:
Code: Select all
# -*- coding: utf-8 -*- Alt = "None" count = "0" uSvHr = "0" outputStr = "" import os import time import serial import pynmea2 from datetime import datetime now = datetime.now() def parseGPS(myStr): global Latitude, Longitude if myStr.find('GGA') > 0: msg = pynmea2.parse(myStr) Alt = (msg.altitude_units) time.sleep(1) if Alt == 'M': print ("GPS OK!- %s SATELITES" % (msg.num_sats)) with open("countlog.txt", "r") as radcount: count = contents =radcount.readline() print ("COUNTS PER MIN: " + count) print ("uSv/Hr " + uSvHr) with open("radlog" + now.strftime("%d-%m-%y") + ".csv", "a") as gps: if (os.stat("radlog" + now.strftime("%d-%m-%y") + ".csv").st_size == 0): #check if the file i$ print ("CSV FILE EMPTY!") print ("ADDING COLUMN NAMES") gps.write("Time,Lat,Long,Alt,Sats,Quality,CPM" + '\n') Latitude = myStr.split(",") LatNS = myStr.split(",") Longitude = myStr.split(",") LongEW = myStr.split(",") Latitude = float(Latitude) Longitude = float(Longitude) if LatNS == 'S': Latitude = Latitude * -1 if LongEW == 'W': Longitude = Longitude * -1 DD = int(float(Latitude)/100) SS = float(Latitude) - DD * 100 Latitude = DD+SS/60 DD = int(float(Longitude)/100) SS = float(Longitude) - DD * 100 Longitude = DD + SS/60 print Latitude print Longitude #Latitude = -(pynmea2.dm_to_sd(msg.lat)) #Longitude = (pynmea2.dm_to_sd(msg.lon)) gps.write(str(msg.timestamp) + "," + str(Latitude) + "," + str(Longitude) + "," + str(msg.altitude) + str(msg.altitude_units) + "," + str(msg.num_sats) + "," + str(msg.gps_qual)) gps.write(",%s" % (count) + '\n') else: print ("NO GPS FIX! - LOGGING PAUSED. %s SATELITES" % msg.num_sats) serialPort = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5) while True: parseGPS(serialPort.readline()) serialPort.flush() serialPort.close()