Tag Archives: berrygps

Using u-Center to connect to the GPS on Raspberry Pi

u-Center from u-Blox is a graphical interface which can be used to monitor and configure all aspects of the GPS module on a BerryGPS-IMU or BerryGPS-GSM.

u-Center from uBlox
U-Center

 

u-Center only runs on Windows. It can connect over the network to a Raspberry Pi.  This will require us to redirect the serial interface on the Raspberry Pi to a network port using ser2net.

Pi Setup

Do an upt-get update and then install ser2net;

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install ser2net

Edit the ser2net config file and add the serial port redirect to a network port. We will use network port 6000

pi@raspberrypi ~ $ sudo nano /etc/ser2net.conf

And add this line at the bottom;

6000:raw:600:/dev/serial0:9600 NONE 1STOPBIT 8DATABITS XONXOFF LOCAL -RTSCTS

This is a breakdown of the syntax for the line above;
TCP port : connection type : timeout : serial port : serial port speed : serial options

you can now start ser2net using;

pi@raspberrypi ~ $ sudo ser2net

And you can use the below command to check if it is running by seeing if the port is open and assigned to the ser2net process;

pi@raspberrypi ~ $sudo netstat -ltnp | grep 6000

If it is running, you should see something similar to the output below;

check result of ser2net

Windows PC Setup and Connecting to the GPS module

You can download u-Center from here.

Once installed, open u-Center. You will get the default view as shown below.  No data will be shown as we are not connected to a GPS.

u-Center default view

The next step, is to create a new network connection and connect to the GPS which is connected to our Raspberry Pi. You can create a new connection under the Receiver and then Network connection menus.

u-Center connect to Raspberry Pi
In the new window, enter the IP address of the Raspberry Pi and specify port 6000. This is the port we configured in ser2net on the Raspberry Pi.
u-Center Raspberry Pi Address

This is what the default view looks like when connected and the GPS has a fix.u-Center connected

 

u-Center

Below I will list of the more useful windows/tools within u-Center.
You can also click on the images below for a larger version.

Data View
This window will show you the longitude, latitude, altitude and fix mode. It will also show the HDOP, which is the Horizontal Dilution of Precision.  Lower is better, anything below 1.0 means you have a good signal.

u-Center Data View
u-Center Data View

Ground Track
This window will show you where the satellites are as well as what time.

u-Center Ground Track
u-Center Ground Track

Skye View
Sky view is an excellent tool for analyzing the performance of antennas as well as the conditions of the satellite observation environment.

u-Center Sky View
u-Center Sky View

Deviation Map
This map shows the average of all previously measured positions.

u-Center Deviation Map
u-Center Deviation Map

Continue reading Using u-Center to connect to the GPS on Raspberry Pi

Real-time GPS tracking with a Raspberry Pi

In this guide, we will show how to do real time tracking, use a BerryGPS-GSM and initialstate.com 

Initialstate has some great tools to easily stream data from a Raspberry Pi to Initialstate.com and show this data within a dashboard using tiles.  We will send longitude,  latitude and  speed. And use a BerryGPS-GSM to get these values and upload them via 3G.

 

You will need to create an account on Initialstate.com and then grab your access key which can be found under “My Settings”

BerryGPS-GSM setup

If you are using a BerryGPS-GSM, you can follow this guide to get the GPS working and get your Pi to connect to via 3G using PPP.

The above guide also shows how to make your Pi connect to the carrier network automatically when booted. You will need this if you plan to perform remote tracking(E.g. Asset tracking).

Install required libraries

pi@raspberrypi ~ $ sudo apt-get install python-pip
pi@raspberrypi ~ $ sudo pip install pynmea2
pi@raspberrypi ~ $ sudo pip install ISStreamer

 

Main Python Script

Here we will create the main script which will stream the GPS data to Initialstate.com.
The code below creates a separate thread which is used to monitor the serial port. This is needed because we have a pause in the main loop. The pause is there to limit how much data we upload over 3G.
If we did everything in the same thread during the pause, the serial buffer would fill up (it is FIFO) and when we get the next value from the buffer, it will be old by a few seconds. This happens every loop and eventually the data will be minutes or hours behind.

The access key below is not a valid key, it is just an example. You will need to replace it with your own key.

pi@raspberrypi ~ $ nano ~/GPStracker.py

#! /usr/bin/python
from gps import *
from time import *
import threading
import datetime
from ISStreamer.Streamer import Streamer
gpsd = None  #Setup global variable 
#Setup the Initialstate stream, give it a bucket name and the access key
streamer = Streamer(bucket_name="GPS_Tracker20190713", bucket_key="GPS_Tracker20190713", access_key="ist_W4aHj0eCkMjCD8JVpp3AMsKomys8NaD")

class GPSDcollector(threading.Thread):
   def __init__(self, threadID):
      threading.Thread.__init__(self)
      self.threadID = threadID
      global gpsd #bring it in scope
      gpsd = gps(mode=WATCH_ENABLE) #Start GPSD
      self.running = True #Start running this thread
   def run(self):
      global gpsd
      while gpsdThread.running:
        gpsd.next() 
        
if __name__ == '__main__':
  gpsdThread = GPSDcollector(1) # create a thread to collect data
  try:
    gpsdThread.start() # start it up
    while True:
        print 'GPS ' , gpsd.utc,'--> CPU time->',datetime.datetime.now().time() ,
        if (gpsd.fix.longitude<>0) and (gpsd.fix.longitude<>'nan'): #Only upload data if it is valid
          streamer.log("Location", "{lat},{lon}".format(lat=gpsd.fix.latitude,lon=gpsd.fix.longitude))
          streamer.log("speed",gpsd.fix.speed)
        print '  lat    ' , gpsd.fix.latitude,
        print '  lon   ' , gpsd.fix.longitude,
        print '  speed ', gpsd.fix.speed
        sleep(5)
  except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
    print "\nKilling Thread..."
    gpsdThread.running = False
    gpsdThread.join() # wait for the thread to finish what it's doing
  print "Done.\nExiting."
  

 

Start the script automatically on boot

If you are doing remote monitoring, you would want the script to run on boot. To do this, we will create a small script which will start the main python program.

pi@raspberrypi ~ $ nano ~/GPStrackerStart.sh

copy in the below lines;

#!/bin/bash
sleep 15
python /home/pi/GPStracker.py &

The pause above is there to give the Pi time to boot and connect via PPP.

Make the script executable;

pi@raspberrypi ~ $ chmod +x ~/GPStrackerStart.sh

We will use cron to start the script every time the Pi boots;

pi@raspberrypi ~ $ crontab -e

Add the below line to the bottom

@reboot /home/pi/GPStrackerStart.sh &

Other Guides and Tutorials for BerryGPS-GSM

Get a GPS fix in seconds using assisted GPS on a Raspberry Pi with a BerryGPS-GSM

Typically, a GPS module can take a few minutes to get  Time To First Fix(TTFF), or even longer if you are in  built up areas(+20mins).  This is because the Almanac needs to be downloaded from  satellites before a GPS fix can be acquired and only a small portion of the Almanac is sent in each GPS update.

Assisted GPS speeds this up significantly by  downloading  ephemeris, almanac, accurate time and satellite status over the network, resulting in faster TTTF, in a few seconds. This is very similar how to GPS works on a smartphone.

The BerryGPS-GSM supports assisted GPS. The below video shows a comparison between assisted and normal GPS.

  • Assisted GPS takes 19secs to get a fix
  • Normal GPS takes 8min 22Sec to get a fix

 

How does the BerryGPS-GSM do this?

The two main components on the BerryGPS-GSM are;

The SARA-U201 can be configured to download GPS assist data and then pass this over the the GPS module. These two components speak to each other via i2c.

This assist data is downloaded by the SARA-U201 modem (not the Pi), therefore the modem needs to create an internal PDP (Packet Data Protocol) connection.

Once the PDP connection is made, the SARA-U201 will reach out to uBlox AssitNow servers and download the latest assist data. A valid token is needed to perform this, all BerryGPS-GSM have had this token pre-configured.

Continue reading Get a GPS fix in seconds using assisted GPS on a Raspberry Pi with a BerryGPS-GSM

New Product: BerryGPS-GSM – Global 3G/2G cellular modem with GPS + SIM

We have released a new product:

BerryGPS-GSM – Global 3G/2G cellular modem with GPS + SIM

This is an all in one module which can provide location tracking and GSM services such as data, text and SMS to your project. It comes in the same form factor as a Raspberry Pi Zero, which makes it nice and compact when used with a Raspberry Pi Zero.

 

 

The two main components that make this board great are;

  • uBlox CAM-M8 GPS module (Same GPS found on BerryGPS-IMU)
  • uBlox SARA-U201 GSM for GSM connectivity, which has global coverage.

Both of these modules working together results in obtaining a GPS fix in secs, using Assisted GPS.

 

BerryGPS-IMU used by Plastic Monkeys in CanSat competition

Along with other sponsors, we are happy to congratulate Plastic Monkeys team for placing 3rd  (out of over 70 teams taking part) in the CanSats in Europe Polish Competition.

A CanSat is a type of sounding rocket payload used to teach space technology. It is similar to the technology used in miniaturized satellites.

In CanSat competitions, the payload is required to fit inside the volume of a typical soda can (66mm diameter and 115mm height).

A BerryGPS-IMU was used to provide location tracking for this project.

 

 

Using python with a GPS receiver on a Raspberry Pi

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

  1. Using GPSD client libraries
  2. Manually parsing NMEA sentences
  3. 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.

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)

Why does it take so long to get a GPS fix?

Have you ever wondered why it sometimes takes your GPS module 10-20 minutes to get a GPS fix?   This post will explain why.

 

Each satellite sends a message every 30 seconds.  This message consists of two main components;

  • Ephemeris data, used to calculate the position of each satellite in orbit
  • Almanac , which is information about  the time and status of the entire satellite constellation.

Only a small portion of the Almanac is included in a GPS message. It takes 25 messages (12.5 minutes) to get the full Almanac. The full Almanac is needed before a GPS fix can be obtained.  This is Time To First Fix (TTFF).

TTFF is a measure of the time required for a GPS receiver to acquire satellite signals and navigation data, and calculate a position solution (called a fix).

The above happens during a cold start, this is when the GPS module has been off for some time and has no data in its memory. A full Almanac download is required to get TTFF. If the GPS module has clear line of sight to all satellites, the shortest time for TTFF is 12.5 minutes.

In a warm start scenario,  the GPS module has valid Almanac data,  is close to its last position (100km or so) and knows the time  within about 20 seconds. This approximate information helps the receiver estimate the range to satellites.  The TTFF for a warm start can be as short as 30 seconds, but is usually just a couple of minutes.

A receiver that has a current almanac, ephemeris data, time and position can have a hot start. A hot start can take from 0.5 to 20 seconds for TTFF.

 

Smarts phones use Assisted GPS (aGPS), this allows them to download the Ephemeris data and Almanac over the cell network which greatly reduces the TTFF.

BerryGPS Raspberry Pi GPS

 

 

 

Raspberry Pi Embedded Cap With GPS & 10DOF

In this post we will show you how to geotag and capture the “attitude”  of photos taken with the Raspberry Pi camera and record these values within the photo itself using EXIF metadata

We used a modified (hacked?) cap to take the images in this post. The cap took photos, geo-tagged and recorded attitude as we walked around Sydney Harbour.

Components used were;

The BerryGPS-IMU was used to capture the GPS coordinates as well as “attitude”.   No external antenna was needed as the BerryGPS-IMU includes an internal antenna.

The “attitude” would include values such as pitch, roll, direction. Some of this data you can see annotate in the image below.


raspberry pi camera gps

Other programs can use some of this data to plot the image on a map and even show the direction of the camera at the time the image was taken.  A good example of this is seen in  GeoSetter

Camera attitude

 

The Cap

The cap has the BerryGPS-IMU sitting on top of the visor, with the Raspberry Pi sitting under the viso.  Some holes where made in the visor to allow connectivity between the BerryGPS-IMU and Raspberry Pi.
We also created a basic camera mount out of 3mm laser cut acrylic. M2.5 Nylon screws were used to hold everything in place.
Raspberry Pi GPS

 

Continue reading Raspberry Pi Embedded Cap With GPS & 10DOF

Navigating with Navit on the Raspberry Pi

 

Navit is an open source navigation system with GPS tracking.
It works great with a Raspberry Pi,  a GPS module and a small TFT with touch, jut like the official Raspberry Pi Display or PiScreen.

 

In this guide, we will be using;

Setting up the GPS

Navit can be installed without a GPS connected to your Raspberry Pi, but you will not be able to use the real-time turn by turn navigation. You will however be able to browse maps. If you are not going to use a GPS, you can skip to the next step.

As we are using the BerryGPS-IMU, we will be following the guide in the link below.  As most GPS modules use serial to communication, this guide can be followed for other GPS modules.

BerryGPS Setup Guide for the Raspberry Pi

 

The images below shows how we have connected the BerryGPS-IMU to the Raspberry Pi 3 whilst it is in the SmartPi Touch case.


Raspberry Pi Navit GPS

If you plan on testing this out in your car,  you need to be mindfully of where you place your BerryGPS. In my setup and I have placed it in the air vent as shown below, and BerryGPS gets a good strong signal.

Raspberry Pi GPS

If you are using an external antenna, then there is no need to worry about where your BerryGPS is placed.

Continue reading Navigating with Navit on the Raspberry Pi

GPS Data logger using a BerryGPS

This post explains how to log GPS data from a BerryGPS or a BerryGPS-IMU and then how to plot this data onto Google Maps and many other maps E.g. OpenStreet, WorldStreet, National Maps, etc..

Raspberry Pi GPS

1. Setup GPS

Follow the instructions on this page to setup your Raspberry Pi for a BerryGPS-IMU. Ensure GPSD is set to automatically start and confirm that you can see the NMEA sentences when using gpsipe;

pi@raspberrypi ~ $ gpspipe -r

 

2.  Automatically Capture Data on Boot.

We will be using gpspipe to capture the NMEA sentence from the BerryGPS and storing these into a file. The command to use is;

pi@raspberrypi ~ $ gpspipe -r -d -l -o /home/pi/`date +”%Y%m%d-%H-%M-%S”`.nmea

-r = Output raw NMEA sentences.
-d = Causes gpspipe to run as a daemon.
-l = Causes gpspipe to sleep for ten seconds before attempting to connect to gpsd.
-o = Output to file.

The date the file is created is also added to the name.

Now we need to force the above command to run at boot. This can be done by editing the rc.local file.

pi@raspberrypi ~ $ sudo nano /etc/rc.local

 

Just before the last line, which will be ‘exit 0’, paste in the below line;

gpspipe -r -d -l -o /home/pi/`date +"%Y%m%d-%H-%M-%S"`.nmea

Reboot and confirm that you can see a .nmea file in the home directory.

Continue reading GPS Data logger using a BerryGPS