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

  • 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 '21 at 12:55
  • https://raspberrypi.stackexchange.com/questions/113992/rpi3b-python-controlling-multiple-sim800-sim900-sim7600-modules/114038#114038 – tlfong01 Jan 22 '21 at 12:56
  • 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 – Newbie_dude Jan 22 '21 at 15:29
  • 1
    I tried USB 1-4, TTYS0 and TTYAMA0 – Newbie_dude Jan 22 '21 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 '21 at 01:17
  • Anyway, I had a quick google on pynmea2 and summarize the following: pynmea2 1.15.0 pip install pynmea2 https://pypi.org/project/pynmea2/ (1) The author of this package has not provided a project description (2) pynmea2 is compatible with Python 2.7 and Python 3.4+ (3) pip install pynmea2 – tlfong01 Jan 23 '21 at 01:24
  • I feel uncomfortable because (1) no project description means the guy is too lazy to even gave one or two lines brief description, (2) Sure Rpi4B Thonny python 3.7.3 can run? (3) ***"pip install" instead of "pip3 install" might cause unrecoverable mess***. Are you using Rpi2 wheezy python 3.5.3? – tlfong01 Jan 23 '21 at 01:29
  • Thank you for your feedback so far. I reverted to 9k6bd8n1 and removed pynmea2. I now simply print the results of ser.read. I'm starting to think I did something wrong with the physical setup. jumpers, pins, usb ports. what does your working setup look like? I attached a new picture of mine – Newbie_dude Jan 23 '21 at 12:46
  • Ah, my video referred above has two pictures showing that I am using a USB to UART cable, and the jumper setting. Because I am testing two SIM7600's at the same time, after checking out each of them work with Rpi on board serial, I no longer use the 40pin connector and use the USB to serial cable. More or less like this. I forgot the exact details. :) – tlfong01 Jan 23 '21 at 13:47
  • One more thing. I did not look too closely at your photos. You might see that I am using the USB to serial connector, but you are not using it. You are using the micro USB connector only for power, that is a different thing. – tlfong01 Jan 23 '21 at 14:55
  • I first suspected that your GPS library might have a problem, but might be your SIM7600 built in GPS module also have a problem. I remember I mentioned that the 7600 built in GPS is not very good, also documentation is bad. I actually cheat by learning GPS using external GPS modules, NEO-8M and others. These are some Q&A you might find usefule for reference: (1) https://electronics.stackexchange.com/questions/519711/gps-taking-long-time-to-fix-out-in-the-open/519716#519716 (2) https://raspberrypi.stackexchange.com/questions/113057/how-can-rpi-listen-to-a-gps-module – tlfong01 Jan 23 '21 at 14:59

0 Answers0