EZ-0048

From 52Pi Wiki
Jump to navigation Jump to search

USB-Port-GPS Module

Description

Gps4.jpg
  • Support Raspberry Pi model A, B, A+, B+, Zero, 2, 3 with its' L80-R GPS chip inside.
  • Communicates satellite with UART or USB.
  • CP2102 as USB to UART Bridge chip, stable and faster.
  • The L80-R with 66 search channels and 22 simultaneous tracking channels,it acquires and tracks satellites in the shortest time at Outdoor.

Attention This module is fit for outdoor operation. please put the Antana in the open air.


Compatibility List

  • Compatibility
Platform USB-Port-GPS Module Notes
Raspberry Pi 4 Model B
Raspberry Pi 3 Model B Plus
Raspberry Pi zero
Raspberry Pi zero W
Raspberry Pi 3 Model B
Raspberry Pi 2 Model B
Raspberry Pi Model B+

Feature

  • -165 dBm sensitivity, 1Hz (Default), up to 5Hz, 66 channels
  • At least 100mA current draw to startup.
  • PPS output can be used to coordinate time with satellite.
  • Internal patch antenna which works quite well when used outdoors SMA connector for external active antenna for when used indoors
  • Fix status LED blinks to let you know when the GPS has determined the current coordinates
  • EASY™, advanced AGPS technology without external memory
  • Support time service application which can be achieved by PPS sync NMEA feature
  • Built-in LNA for better sensitivity
  • RTC battery-compatible
  • 1x8 male headers, USB micro Interface
  • includes CP2102 Module Serial Converter USB 2.0 To TTL UART

Documentations

Hardware Design For Quectel L80-R


Parameters

Type value
Satellites 66 acquisition channels,

22 tracking channels

Work Voltage 4.5-5.5V
Weight 4.35g
Maximum Current 100mA MAX
Work Temperature -40~+85℃
scale 16.6x26x18.6(mm)
GPS L80-R
Patch Antenna Size 15.0 x 15.0 x 4.0mm
Position Accuracy <2.5M CEP
Velocity Accuracy <1.0m/s
Warm/cold start without ESEY <35s
Warm/cold start with ESEY <15s
Acquisition sensitivity -148dBm
Tracking sensitivity -165dBm
Update rate 1Hz (Default)

up to 5Hz

Baud Rate 4800~115200 bps

9600bps default

Protocols NMEA 0183
Mount Cable 1*8 Stacking Header

USB micro data cable

Gps-schama.png



Presentation

Gps2.jpg
Gps3.jpg
Gps4.jpg

Package includes:

  • 1x USB-Port-GPS(L80-R) module
  • 1x USB data wire

How to wire it up

Uart Style:

Because of the Serial port issue of Raspberry Pi 3, Model B, it may cause unexpected problem, we suggest that you do not connect GPS module with Raspberry Pi directly with GPIO Pins.

  • 1.You need a USB-to-TTL cable to connect GPS module and Raspberry Pi ,and you can wire it up like this chart:
GPS module Wire color
VCC Red wire
GND Black wire
TXD Green wire
RXD White wire
Gpsrpi.jpg
Gpsside.jpg
GPSconnect.jpg


  • 2.Power on Raspberry Pi and login, open a terminal and type following commands if you use raspberry Pi in desktop environment.

USB Style:

  • Just use a microUSB cable connect Raspberry Pi USB port with GPS module and power on Raspberry Pi.
Gps1.jpg



How to use it

1. After power on and login to system. you can open a terminal and typing following command to install packages for GPS module.
sudo apt-get update && sudo apt-get -y install gpsd gpsd-clients python-gps
2.Start the gpsd service and control it.
Enable it: sudo systemctl enable gpsd.socket
Start it: sudo systemctl start gpsd.socket
Restart it: sudo systemctl restart gpsd.socket
Check status: sudo systemctl status gpsd.socket

4.Modify the configuration file of gpsd in /etc/default/gpsd
Modify the "DEVICE" parameter according to the name of serial port in /dev folder.
It is usually named "/dev/ttyUSB0" if you connect it to Raspberry Pi via USB cable.
You can use "nano" or "vim.tiny" editor to finish it.

Gpsconfig4.jpg


Restart service:
sudo systemctl restart gpsd.socket
Finally, use this command to get information from GPS module.
sudo cgps -s
5. The GPS status will be like this:

Gpsresult.png



Example Code in C for Client

  • Using following code can be get GPS infomation from gpsd progress from local port 2947 via libgps library.
  • GPS client HOWTO
  • CODE name gps.c:
#include <gps.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>

int main() {
int rc;
struct timeval tv;

struct gps_data_t gps_data;
if ((rc = gps_open("localhost", "2947", &gps_data)) == -1) {
    printf("code: %d, reason: %s\n", rc, gps_errstr(rc));
    return EXIT_FAILURE;
}
gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);

while (1) {
    /* wait for 2 seconds to receive data */
    if (gps_waiting (&gps_data, 2000000)) {
        /* read data */
        if ((rc = gps_read(&gps_data)) == -1) {
            printf("error occured reading gps data. code: %d, reason: %s\n", rc, gps_errstr(rc));
        } else {
            /* Display data from the GPS receiver. */
            if ((gps_data.status == STATUS_FIX) && 
                (gps_data.fix.mode == MODE_2D || gps_data.fix.mode == MODE_3D) &&
                !isnan(gps_data.fix.latitude) && 
                !isnan(gps_data.fix.longitude)) {
                    //gettimeofday(&tv, NULL); EDIT: tv.tv_sec isn't actually the timestamp!
                    printf("latitude: %f, longitude: %f, speed: %f, timestamp: %lf\n", gps_data.fix.latitude, gps_data.fix.longitude, gps_data.fix.speed, gps_data.fix.time); //EDIT: Replaced tv.tv_sec with gps_data.fix.time
            } else {
                printf("no GPS data available\n");
            }
        }
    }

    sleep(3);
}

/* When you are done... */
gps_stream(&gps_data, WATCH_DISABLE, NULL);
gps_close (&gps_data);

return EXIT_SUCCESS;
}
  • Complie and run it.
gcc -o gps gps.c -lm -lgps
sudo ./gps

Addictional solution for GPS client

  • Using python with a GPS receiver on a Raspberry Pi
  • Comment

Here are three examples of how to use python to get GPS data from a GPS receiver attached to a Raspberry Pi.

Using GPSD client libraries
Manually parsing NMEA sentences
Using  pynmea2 to parse NMEA sentences
GPSD client libraries

The gpsd client libraries are based on JSON. The JSON objects have a "class" attribute (E.g. TPV, SKY, DEVICE.etc...) which can be used to filter on different information.
Refer to: [ http://www.catb.org/gpsd/gpsd_json.html | gpsd_json ]

  • This guide shows how to get gpsd up an running on a Raspberry Pi.
  • The example python script below filters on the TPV class, which is the Time Position Velocity report and then prints out the relevant information.
#! /usr/bin/python
from gps import *
import time
   
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) 
print 'latitude\tlongitude\ttime utc\t\t\taltitude\tepv\tept\tspeed\tclimb' # '\t' = TAB to try and output the data in columns.
  
try:
    while True:
        report = gpsd.next() #
	    if report['class'] == 'TPV':
                print  getattr(report,'lat',0.0),"\t",
                print  getattr(report,'lon',0.0),"\t",
                print getattr(report,'time',''),"\t",
                print  getattr(report,'alt','nan'),"\t\t",
                print  getattr(report,'epv','nan'),"\t",
                print  getattr(report,'ept','nan'),"\t",
                print  getattr(report,'speed','nan'),"\t",
                print getattr(report,'climb','nan'),"\t"
                time.sleep(1) 
except (KeyboardInterrupt, SystemExit):      #when you press ctrl+c
    print "Done.\nExiting."
  • This python script filters on the SKY class and prints out satellite information.
#! /usr/bin/python

from gps import *
import time
import os
   
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) 
  
try:
    while True:
        report = gpsd.next() #
            if report['class'] == 'SKY':
                os.system('clear')
                print ' Satellites (total of', len(gpsd.satellites) , ' in view)'
		for i in gpsd.satellites:
                    print 't', i

		
                print '\n\n'
		print 'PRN = PRN ID of the satellite. 1-63 are GNSS satellites, 64-96 are GLONASS satellites, 100-164 are SBAS satellites'
		print 'E = Elevation in degrees'
		print 'As = Azimuth, degrees from true north'
		print 'ss = Signal stength in dB'
		print 'used = Used in current solution?'

            time.sleep(1) 
except (KeyboardInterrupt, SystemExit):         #when you press ctrl+c
    print "Done.\nExiting."
  • BerryGPS Raspberry Pi GPS
  • Manually parsing NMEA sentences

The python script below shows how to access GPS data by connecting directly to the serial interface.
It filters on $GPRMC NMEA sentences and then splits the well know attributes into different variables.

import serial
port = "/dev/serial0"

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

        print "time : %s, latitude : %s(%s), longitude : %s(%s), speed : %s, True Course : %s, Date : %s" %  (time,lat,dirLat,lon,dirLon,speed,trCourse,date)

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 "Receiving GPS data"
ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)
while True:
   data = ser.readline()
   parseGPS(data)
  • Using pynmea2 to parse NMEA sentences

The python script below shows how to access GPS data by connecting directly to the serial interface.
It filters on $GPGGA NMEA sentences and then uses pynmea2 to parse the data.
Pynmea2 can be installed with:

pi@raspberrypi ~ $ pip install pynmea2

import serial
import pynmea2

port = "/dev/serial0"

def parseGPS(str):
    if str.find('GGA') > 0:
        msg = pynmea2.parse(str)
        print "Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s -- Satellites: %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units,msg.num_sats)

serialPort = serial.Serial(port, baudrate = 9600, timeout = 0.5)
while True:
    str = serialPort.readline()
    parseGPS(str)

Trouble Shooting

If you can not get the information mentioned before. You can use this command to check if serial is working properly. cat /dev/ttyUSB0 it works fine if you see this picture:

Usboutput.png



FAQ

  • Question: I use L80-R GPS module. I choose to connect the GPS to the raspberry using a USB port. I followed these steps:
pi@raspberrypi ~ $ sudo cat /dev/ttyUSB0  
$GPRMC,144034.00,V,,,,,,,090315,,,N*75
$GPVTG,,,,,,,,,N*30
$GPGGA,144034.00,,,,,0,00,99.99,,,,,,*60
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,01,15,,,25*7B

sudo apt-get update
sudo apt-get install gpsd gpsd-clients
sudo dpkg-reconfigure gpsd   
start gpsd automatically: yes
Should gpsd handle attached USB receivers automatically: yes
Device the GPS receiver is attached to: <leave blank>
Options to gpsd: -n /dev/ttyUSB0
gpsd control socket path: <use default>

sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock
cgps -s

What should I do for NO FIX problem?

    • Answer: You can modify /etc/defalut/gpsd file and make sure you input the right arguments as following picture:
    • Gpsconfig.png


  • Question: Can I use it in my car as a GPS receiver ?
    • Answer: please see this manual and try lcdgps command.
lcdgps
       A client that passes gpsd data to lcdproc, turning your car computer into a very expensive and 
       nearly feature-free GPS receiver. Currently assumes a 4x40 LCD and writes data formatted to fit
       that size screen. Also displays 4- or 6-character Maidenhead grid square output.

  • Question: What is the difference between L80 and L80-R?
 Answer: L80-R does not support automatic antenna detection.