Tag Archives: GPS

How to save GPS data to a file using Python

Below is an example python script which will save GPS data (time, Lon, Lat, speed and sats in view) to a file.

The gpsd client libraries  will be used to get the data from GPSD. We will be using the TPV class to get time, latitude, longitude and speed.

We can get the number of satellites in view by getting the length of the satellites object.

This page shows how to get gpsd up an running on a Raspberry Pi

Every time the script is run, it will create a new file beginning with the current date and time.

In this example, I am writing in a csv format, where each GPS attribute is separated by a comma.

#! /usr/bin/python
from gps import *
import time, inspect


f = open(time.strftime("%Y%m%d-%H%M%S")+'_GSPData.csv','w')

gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)

print 'GPStime utc\t\t\tlatitude\tlongitude\tspeed\tsats in view' # '\t' = TAB to try and output the data in columns.

f.write("GPStime utc,latitude,longitude,speed,sats in view\n")

try:

    while True:
        report = gpsd.next() #
        if report['class'] == 'TPV':
            GPStime =  str(getattr(report,'time',''))
            lat = str(getattr(report,'lat',0.0))
            lon = str(getattr(report,'lon',0.0))
            speed =  str(getattr(report,'speed','nan'))
            sats = str(len(gpsd.satellites))

            print  GPStime,"\t",
            print  lat,"\t",
            print  lon,"\t",
            print  speed,"\t",
            print  sats,"\t"

            f.write(GPStime + ',' + lat +',' + lon + ',' + speed + ',' + sats + '\n')

            time.sleep(1)

except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
    print "Done.\nExiting."
    f.close()

New Products : BerryGPS and BerryGPS-IMU

We have released two new products:

BerryGPS - GPS for the Raspberry Pi

BerryGPS-IMU - GPS and IMU for the Raspberry Pi

Both GPS modules use the  M10478-A2 from Antenova, which is a high quality GPS module which is able to track 22 satellites and has an internal antenna. This means no external antenna is needed if the module has clear access to sky.  Both feature a SuperCap to store ephemeris data for up to four hours. This and many more features are included.

Raspberry Pi GPS
BerryGPS

 

 

 

Both have been specifically designed for the Raspberry Pi Zero, however they will work with any version of Raspberry Pi.

 

The BerryGPS-IMU also includes all the components found on the BerryIMU.  And is compatible with the existing code in our repository. The BerryGPS-IMU present a lot of sensors in a very, very small package.

 

 

Raspberry Pi GPS
BerryGPS-IMU

 

 

 

Raspberry Pi GPS
BerryGPS-IMU on a Raspberry Pi Zero

 

BerryGPS-IMU
BerryGPS-IMU on Raspberry Pi 2

berrygps-skull