0

enter image description hereI'm not able to receive GPS data.

The jumpers are placed in the top position (A)

AT commands return the following:

>>> ser = serial.Serial("/dev/ttyUSB2",115200)

>>> ser.write(('AT+CGPS=1,1'+  '\r\n' ).encode())
13
>>> 
>>> ser.write(('AT+CGPS?'+  '\r\n' ).encode())
10
>>> ser.write(('AT+CGPSINFO'+  '\r\n' ).encode())
13

python code ####################################### '''

import RPi.GPIO as GPIO

import serial
import time
import pynmea2

ser_send = serial.Serial('/dev/ttyUSB2',115200,timeout=1)
ser_receive = serial.Serial('/dev/ttyUSB1',115200,timeout=1)
ser_S0 = serial.Serial('/dev/ttyS0',115200,timeout=1)

def parseGPS(string):
    if 'GGA' in string:
        msg = pynmea2.parse(string)
        print(str(msg))
        print("Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units))
    else:
        print(f' doesnt contain GGA: {string}')

def check_conn(conn):
    return conn.name, conn.is_open

def send_at(command,expected_result,timeout):
    name, state = check_conn(ser_send)
    print(f'{name} is {state}')
    
    rec_buff = ''
    if state:

        ser_send.write((command+'\r\n').encode())
        time.sleep(timeout)
        if ser_send.inWaiting():    #something was received in the buffer
            time.sleep(0.01 )
            rec_buff = ser_send.read(ser_send.inWaiting())   # read the buffer
        if rec_buff != '':
            if expected_result not in rec_buff.decode():
                print(command + ' ERROR')
                print(command + ' returned:\t' + rec_buff.decode())
                return False
            else:
                print(f'---------- response from AT command: {rec_buff.decode()}')
                return True
        else:
            print('GPS is not ready, returned nothing')
            return False

def get_gps_position():
    rec_null = True
    answer = False
    gps_started = False
    print('Start GPS session...')
    while not gps_started:
     
        rec_buff = ''
        send_at('AT+CGPS=1,1','OK',1)
        time.sleep(2)
        gps_status= send_at('AT+CGPS','OK',1)
        if gps_status:
            gps_started = True
    while 1:
        answer = send_at('AT+CGPSINFO','+CGPSINFO: ',1)
        #readings = list()
        print('######################## USB1  ')
        while ser_receive.inWaiting() >0:
            readings = ser_receive.readline().decode()
            parseGPS(readings)
            #readings.append(ser_receive.readline())
        # testing another port
        print('######################## S0  ')
        while ser_S0.inWaiting() >0:
                        readings = ser_S0.readline().decode()
                        parseGPS(readings)

        if answer:
            answer = False
            rec_buff = ser_send.read(ser_send.inWaiting()).decode()
            if ',,,,,,' in rec_buff:
                print('GPS is not ready')
                #rec_null = False
                print(f'{ser_receive.name} received {readings}')

                time.sleep(2)
            else:
                print(f'{ser_receive.name} received {readings}')
                time.sleep(2)
        else:
            print('error %d'%answer)
            rec_buff = ''
            send_at('AT+CGPS=0','OK',1)
            return False
        time.sleep(1.5)

'''

#######################################

All I see is this:

/dev/ttyUSB2 is True AT+CGPS ERROR AT+CGPS returned: AT+CGPS ERROR

enter image description here

11
  • I forgot what jumpers A, B, C are for. A can be on or off, so for B, or C. So there are many many combinations. Have you read the friendly manual or just blindly trial and error? You seem to be using USB2, But have tried USB1, TTYS0.1 etc? Have you tried loop back test? .
    – tlfong01
    Jan 22, 2021 at 12:55
  • 1
    Hi, Now I'm getting further but still no data: /dev/ttyUSB2 is True check if b'+CGPSINFO: ' in b'AT+CGPSINFO\r\r\n+CGPSINFO: ,,,,,,,,\r\n\r\nOK\r\n' ---------- response from AT command: AT+CGPSINFO +CGPSINFO: ,,,,,,,, OK end of response ######################## USB1 doesnt contain GGA: $GNGNS,,,,,,NNN,,,,,,*1D doesnt contain GGA: $GPVTG,,T,,M,,N,,K,N*2C doesnt contain GGA: $GPGSA,A,1,,,,,,,,,,,,,,,*1E doesnt contain GGA: $GNGSA,A,1,,,,,,,,,,,,,,,*00 doesnt contain GGA: $BDGSA,A,1,,,,,,,,,,,,,,,*0F Jan 22, 2021 at 15:29
  • 1
    I tried USB 1-4, TTYS0 and TTYAMA0 Jan 22, 2021 at 15:31
  • Ah if you send "AT" and receive "OK", that means you have passed the URAT loopback test. You have no luck on all 6 USB 1-4, TTYS0 and TTYAMA0 ports, then I would suggest to disconnect/uncomment all six port and focus on just one USB1. My demo 7600 post has a debugged program is plug and play (copy, past, and run) with sample output. My demo program use the very basic serial library. I forgot what is pynmea2. Perhaps you can give me a link of the package or tutorial, to refresh my memory. I forgot to suggest use default 9k6bd8n1, and disable autobaud which I heard is buggy.
    – tlfong01
    Jan 23, 2021 at 1:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.