Not able to get GPS data with Raspberry Pi 3 and Quectel EC21 modem

Hi,

I’m trying to get GPS values from an AutoPi motherboard with Quectel EC21 modem. I’m running with a RPI 3 B+, fresh Raspbian install (without autoPi software):

**pi@raspberrypi:~ $ lsusb**
Bus 001 Device 116: ID 2c7c:0121
Bus 001 Device 004: ID 0000:0000
Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

**pi@raspberrypi:~ $ ls /dev/ttyU***
/dev/ttyUSB0  /dev/ttyUSB1  /dev/ttyUSB2  /dev/ttyUSB3

 **sudo nano /etc/udev/rules.d/2c7c\:0121.rules**
ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb", KERNELS=="1-1.2.3", RUN+="/bin/sh -c 'echo 1 > /sys/bus/usb/devices/1-1.2.3/bConfigurationValue'"


**dmesg**
[125402.340745] usb 1-1.2.3: USB disconnect, device number 85
[125402.341390] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
[125402.341477] option 1-1.2.3:1.0: device disconnected
[125402.342182] option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
[125402.342283] option 1-1.2.3:1.1: device disconnected
[125402.342956] option1 ttyUSB2: GSM modem (1-port) converter now disconnected from ttyUSB2
[125402.343048] option 1-1.2.3:1.2: device disconnected
[125402.344088] option1 ttyUSB3: GSM modem (1-port) converter now disconnected from ttyUSB3
[125402.344205] option 1-1.2.3:1.3: device disconnected
[125402.344688] qmi_wwan 1-1.2.3:1.4 wwan0: unregister 'qmi_wwan' usb-3f980000.usb-1.2.3, WWAN/QMI device
[125416.015951] usb 1-1.2.3: new high-speed USB device number 86 using dwc_otg
[125416.156003] usb 1-1.2.3: New USB device found, idVendor=2c7c, idProduct=0121
[125416.156017] usb 1-1.2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[125416.156027] usb 1-1.2.3: Product: Android
[125416.156035] usb 1-1.2.3: Manufacturer: Android
[125416.156486] usb 1-1.2.3: rejected 1 configuration due to insufficient available bus power
[125416.156497] usb 1-1.2.3: no configuration chosen from 1 choice
[125416.156506] usb 1-1.2.3: No support over 100mA
[125416.188210] usb 1-1.2.3: new config #1 exceeds power limit by 400mA
[125416.189835] option 1-1.2.3:1.0: GSM modem (1-port) converter detected
[125416.190516] usb 1-1.2.3: GSM modem (1-port) converter now attached to ttyUSB0
[125416.192352] option 1-1.2.3:1.1: GSM modem (1-port) converter detected
[125416.192979] usb 1-1.2.3: GSM modem (1-port) converter now attached to ttyUSB1
[125416.194830] option 1-1.2.3:1.2: GSM modem (1-port) converter detected
[125416.195466] usb 1-1.2.3: GSM modem (1-port) converter now attached to ttyUSB2
[125416.196693] option 1-1.2.3:1.3: GSM modem (1-port) converter detected
[125416.197053] usb 1-1.2.3: GSM modem (1-port) converter now attached to ttyUSB3
[125416.198387] qmi_wwan 1-1.2.3:1.4: cdc-wdm0: USB WDM device
[125416.199843] qmi_wwan 1-1.2.3:1.4 wwan0: register 'qmi_wwan' at usb-3f980000.usb-1.2.3, WWAN/QMI device, fa:45:03:3e:6f:34

With minicom I’m able to connect to ttyUSB2, 115200 18N, this is what I get (I tried on ttyUSB3 too):

AT
OK
AT+QGPS?
+QGPS: 1

OK
AT+QGPS=1
+CME ERROR: 504
AT+QGPS=0
+CME ERROR: 501

If I open a minicom on ttyUSB1 9600 18N, I don’t get any data…

Following these tutorials (not exactly the same modem but near)


http://www.embeddedpi.com/documentation/3g-4g-modems/quecetel-modem-gps-setup

504: session ongoing -> what does it mean ?

I also took a look in the autoPiCore code, maybe I mess something?

In addition, I was able to use the modem in ppp mode and use it as data connection with a sim card.
Do I need to put a sim card for GPS too ?

Any support will be appreciate!
Thanks,
Nicolas

try running this python script:

from time import sleep
import serial

portwrite = "/dev/ttyUSB2"
port = "/dev/ttyUSB1"

def parseGPS(data):
    print "raw:", data #prints raw data
    if data[0:6] == "$GPRMC":
        sdata = data.split(",")
        if sdata[2] == 'V':
            print "no satellite data available"
            return
        print "-----Parsing GPRMC-----"
        time = sdata[1][0:2] + ":" + sdata[1][2:4] + ":" + sdata[1][4:6]
        lat = decode(sdata[3]) #latitude
        dirLat = sdata[4]      #latitude direction N/S
        lon = decode(sdata[5]) #longitute
        dirLon = sdata[6]      #longitude direction E/W
        speed = sdata[7]       #Speed in knots
        trCourse = sdata[8]    #True course
        date = sdata[9][0:2] + "/" + sdata[9][2:4] + "/" + sdata[9][4:6]
                           #date
        variation = sdata[10]  #variation
        degreeChecksum = sdata[11]
        dc = degreeChecksum.split("*")
        degree = dc[0]        #degree
        checksum = dc[1]      #checksum
        print "time : %s, latitude : %s(%s), longitude : %s(%s), speed : %s, True Course : %s, Date : %s, Magnetic Variation : %s(%s),Checksum : %s "%    (time,lat,dirLat,lon,dirLon,speed,trCourse,date,variation,degree,checksum)
    else:
        print "Printed data is ",data[0:6]
def decode(coord):
    #Converts DDDMM.MMMMM -> DD deg MM.MMMMM min
    x = coord.split(".")
    head = x[0]
    tail = x[1]
    deg = head[0:-2]
    min = head[-2:]
    return deg + " deg " + min + "." + tail + " min"

print "Connecting port"
serw = serial.Serial(portwrite, baudrate = 115200, timeout = 1)
serw.write('AT+QGPS=1\r')
serw.close()
sleep(0.5)

print "Receiving GPS data"
ser = serial.Serial(port, baudrate = 115200, timeout = 0.5)
while True:
   data = ser.readline()
   parseGPS(data)

From what i have found so far, it’s hard to find a GPS fix when using this indoors.

Source: https://sixfab.com/gps-tracker-with-3g-4glte-shield/

I’m having the same problem as decribes by Nicolas. There is nothing being written on the /dev/ttyUSB1 port. Even though GPS is enabled. Even without a fix there should be at least some empty NMEA messages (thats at least what I get from other gps serial dongles that I’m working with).

Hi,

It’s a bit old but this is what I’ve done to be able to receive data from GPS in the RPi terminal:

first terminal:
sudo minicom -D /dev/ttyUSB2
AT+QGPS?
AT+QGPSEND
AT+QGPS?
AT+QGPS=1
AT+QGPSCFG=“outport”,“usbnmea”

second terminal:
sudo picocom -b 9600 /dev/ttyUSB1

GPS AT Command on USB2 and GPS data on USB1

Hi,

Nicolas, i am able to get GPS data in RPI Terminal but I’m not able to get it working in Python. After ran SixFab code and i got this errors.

Traceback (most recent call last):
 File "/home/pi/Desktop/I2C_CE/gpstest.py", line 43, in <module>
serw.write('AT+QGPS=1\r')
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 518, in write
d = to_bytes(data)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 63, in to_bytes
raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: 'AT+QGPS=1\r.

Is there any workaround to solve this?

The sixfab code doesn’t work with Python 3, you might just be able to do python2 thescript.py from your terminal to get it working

You need to modify the code slightly to work with python3. All you need to do is encode to bytes when sending like this serw.write(b’AT+QGPS=1\r’) and when you receive the data you need to decode it like this data=data.decode(‘utf-8’). This will get rid of your unicode string error.

1 Like