piguy1978
Posts: 1
Joined: Thu Nov 01, 2018 8:33 pm

Neo-6M GPS module: problems parsing data

Thu Nov 01, 2018 8:54 pm

I am able to log the NMEA sentences using

Code: Select all

sudo cat /dev/ttyAMA0
I can't get my data to log using my Python script. It starts to log and then throws the following error:

Code: Select all

Traceback (most recent call last):
  File "Exemplary.py", line 36, in <module>
    if ser.in_waiting:
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 456, in in_waiting
    s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
IOError: [Errno 5] Input/output error
I am new to Python. I decided to use Python because there was already some examples. Below is my code...

Code: Select all

# Serial4.py

import serial
import time

port = "/dev/ttyAMA0"

def parseGPS(data):
#    print "raw:", data
    if data[0:6] == "$GPGGA":
        s = data.split(",")
        if s[7] == '0':
            print "no satellite data available"
            return        
        time = s[1][0:2] + ":" + s[1][2:4] + ":" + s[1][4:6]
        lat = decode(s[2])
        dirLat = s[3]
        lon = decode(s[4])
        dirLon = s[5]
        sat = s[7]
        print "Time(UTC): %s-- Latitude: %s(%s)-- Longitude:%s(%s)--(%s satellites)" %(time, lat, dirLat, lon, dirLon, sat) 

def decode(coord):
    # DDDMM.MMMMM -> DD deg MM.MMMMM min
    v = coord.split(".")
    head = v[0]
    tail =  v[1]
    deg = head[0:-2]
    min = head[-2:]
    return deg + " deg " + min + "." + tail + " min"

ser = serial.Serial(port, baudrate = 9600, timeout = None)
while True:
    time.sleep(.2)
    if ser.in_waiting:
        data = ser.readline()
        parseGPS(data)


Return to “Automation, sensing and robotics”