Innacurate NMEA messages

114 Views Asked by At

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 :)

1

There are 1 best solutions below

0
UnsolicitedEmails On

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)