-1

When I look at latitude and longitude in u-center, I get very accurate coordinates. But the NMEA messages in u-center's text console, and in my Python script output in VSCode, are off by about 0.3 degrees. Both latitude and longitude.

Here's my code:

import serial

gps = serial.Serial('com5', baudrate=9600)

while True:
    ser_bytes = gps.readline()
    decoded_bytes = ser_bytes.decode("utf-8")
    data = decoded_bytes.split(",")
    if data[0] == '$GNRMC':
        lat_nmea = (data[3],data[4])
        lat_degrees = float(lat_nmea[0][0:2])
        if lat_nmea[1] == 'S':
            lat_degrees = -lat_degrees
        lat_minutes = float(lat_nmea[0][2:])
        lat = lat_degrees + (lat_minutes/60)
        lon_nmea = (data[5],data[6])
        lon_degrees = float(lon_nmea[0][:3])
        if lon_nmea[1] == 'W':
            lon_degrees = -lon_degrees
        lon_minutes = float(lon_nmea[0][3:])
        lon = lon_degrees + (lon_minutes/60)
        print("%0.8f" %lat,", " "%0.8f" %lon)

Expected Output (as seen in u-center data view):

-12.63900217 , 111.85371867

Actual Output (oddly it seems the Longitude is printing as expected, but not the Latitude):

-11.36120217 , 111.85371867

However, the NMEA messages don't match either of the above values. For example the $GNGLL message:

$GNGLL,1238.34708,N,11129.52477,W,093907.00,A,A*68

Any help would be appreciated! Thanks :)

  • Without your code and some examples (e.g. what u-blox gives you) it is nearly impossible to answer. Common error is getting wrong interpretation of coordinates (decimal as 1/100 or as minutes and seconds (so 1/60). – Giacomo Catenazzi Nov 16 '22 at 07:57
  • @GiacomoCatenazzi Edited. Hopefully it makes more sense now. Thanks – UnsolicitedEmails Nov 16 '22 at 09:53
  • I find only one error: `if lon_nmea[1] == 'W':` the logic is wrong: you should do it later, else you go W only on degree, but you take minutes on opposite direction. Same on `S`. Do it at last step. – Giacomo Catenazzi Nov 16 '22 at 10:14
  • @GiacomoCatenazzi You were right! Output is now as printing as expected. Thank you so much. – UnsolicitedEmails Nov 16 '22 at 10:43

1 Answers1

0

Thanks to @GiacomoCatenazzi in the comments, here is the code that is printing the values as expected:

import serial

gps = serial.Serial('com5', baudrate=9600)

while True:
    ser_bytes = gps.readline()
    decoded_bytes = ser_bytes.decode("utf-8")
    data = decoded_bytes.split(",")
    if data[0] == '$GNRMC':
        lat_nmea = (data[3],data[4])
        lat_degrees = float(lat_nmea[0][0:2])
        lat_minutes = float(lat_nmea[0][2:])
        lat = lat_degrees + (lat_minutes/60)
        lon_nmea = (data[5],data[6])
        lon_degrees = float(lon_nmea[0][:3])
        lon_minutes = float(lon_nmea[0][3:])
        lon = lon_degrees + (lon_minutes/60)
        if lat_nmea[1] == 'S':
            lat = -lat
        if lon_nmea[1] == 'W':
            lon = -lon
        print("%0.8f" %lat, "%0.8f" %lon)