loading

This tutorial will guide you through
the process of setting up a Raspberry Pi 3 (RPi3) to auto start GPS on boot up in the Raspbian OS environment, (these instructions also work on Jessie Lite if you want to run this on a Pi Zero), and log the GPS information in a .nmea file and then convert to .kml (Keyhole Markup Language) to be viewed in most mapping software.

All of the code you will run in terminal will be in ITALICS .

For this Project you will need:

1 Raspberry Pi 3

2 Micro SD card with Raspian Jessie installed

3 USB GPS

4 Power Supply

5 HDMI Monitor

6 Mouse

7 Keyboard

8 Active Internet Connection

Step 1: Initial Setup

First thing we need to do is set up
our Raspbian preferences via the GUI or running the command. Everything from this point will be done from a terminal window in the GUI, but could be done from the command prompt if you chose not to startx) sudo raspi-config Expand the file system so we can write to the whole of the SD card. Change your RPi3’s name and default password Change your location and time zone Reboot sudo reboot

Then we need to update the RPi3

sudo apt-get upgrade

sudo apt-get update

y

Enter

Next we need to install the packages that we will use for our GPS data logger.

(GPSD is what starts our GPS unit in the background and allows it to start collecting GPS information. GPSD-Clients include GPSPIPE which allows us to use that information and save it to a .nmea file. Python-GPS is the script which allows our RPi3 to talk to the GPS unit via GPSD and GPSPipe. GPSBable is a script which converts .nmea files to .kml for use in mapping software. And finally FoxtrotGPS is software which runs well on the RPi3 and allows us to view the data on a map.

sudo apt-get install gpsd gpsd-clients python-gps foxtrotgps gpsbabel

Y

Enter

Step 2: Raspbian Jessie Systemd Service Fix

Note if you're using the Raspbian Jessie or later release
you'll need to disable a systemd (system management daemons) service that gpsd installs. This service has systemd listen on a local socket and run gpsd when clients connect to it, however it will also interfere with other gpsd instances that are manually run (like in this guide). You will need to disable the gpsd systemd service by running the following commands:

sudo systemctl stop gpsd.socket

sudo systemctl disable gpsd.socket

Should you ever want to enable the default gpsd systemd service you can run these commands to restore it (but remember the rest of the steps in this guide won't work):

sudo systemctl enable gpsd.socketsudo systemctl start gpsd.socket

After disabling the gpsd systemd service above you're ready to try running gpsd manually.

Step 3: Testing GPSD and GPSPipe

First connect your USB GPS or “GPS Breakout” via the
USBTTL cable.(Red to Vin, Black to GND, Green to RX, White to TX.)

Now run the following command to manually start gpsd and point it at the GPS on the USB serial port:

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

cgps -s

You should see output

Type the following to stop GPSD:

Ctrl+C

Next we need to edit the GPSD config file.

sudo nano /etc/default/gpsd

Set the following to match this.

START DAEMON ="true"

DEVICES="/dev/GPS0"

To save press Ctrl+X

Y

Enter

Next we need to make sure gpspipe can read the data from gpsd and the USB GPS unit.

sudo gpspipe -r

You should see output

Press Ctrl+C to stop the script

Step 4: Make Directory to Save Data

Next we need to make a directory
folder in the root directory of the RPi3’s OS to give GPSPipe a place to store the data, let’s name this directory folder “data”.

sudo mkdir /data

Now make the data directory folder readable, writeable, and executable for anything on the RPi3. (Otherwise GPSPipe wont beable to save data in there. Do this by running the following command:

sudo chmod 777 /data

Let’s test to see if GPSPipe will write to the new data directory we created.

sudo gpspipe -r -d -l -o /data/data.`date +"%Y%m%d%h%m%s"`.nmea

Navigate to your /data directory folder and you should see a file after about 10 seconds labeled something like data.160902Sep091472862456.nmea.

If you are SSHing in to your RPi3, type the following to check your /data for the newly created file.

cd /data

ls

Then Type

cd

To back out.

If so, back to terminal and type the following to stop the collection of GPS data.

sudo killall gpspipe

Now reboot

sudo reboot

Step 5: Setup to Run on Boot

Once the RPi3 finishes rebooting we
want to edit the rc.local directory, which is what allows us to tell the RPi3 what to do every time it boots, so we can tell it to start gpsd system service and have gpspipe start logging the data to our /data directory in a new file, every time the RPi3 reboots, for any reason.

Enter the following command in terminal:

sudo nano /etc/rc.local

You should see this screen.

We want to add the following, one space after “fi” and one space before “exit 0”, otherwise this may not work due to bash script formatting issues.

gpsd /dev/ttyUSB0 –F /var/run/gpsd.sock

sleep 60

sudo gpspipe -r -d -l -o /data/data.`date +"%Y%m%d%h%m%s"`.nmea

It should look like this when finished.

To Save type:

Ctrl+X

Y

Enter

Reboot.

sudo reboot

Step 6: Check to See If It Is Working.

Once the RPi3 has rebooted, navigate
to /data and after about 1 minute you should see a new file created named something like “data.160902Sep091472862456.nmea”

If you open it and scroll down to the bottom you should see the most current fix. Close the file and open it again, scroll down to the bottom and it should have added more fixes to the most current again (about 3 fixes a second on average). Once you have confirmed the RPi3 is GPS data logging on boot you can run the following command to stop it.

sudo killall gpspipe

Now that you have successfully collected GPS data in the nmea format, let’s convert it to something a little more user friendly.

We need to direct our terminal session to the directory that our files are located in, and show us the file names (to make it easier to copy and paste later, to do this run the following:

cd /data

ls

Step 7: Converting to .KML for Google Earth.

Now that we know the files name, let’s run the bash script, “GPSBable”, to convert them.

It will go something like this

(gpsbabel -i nmea -f (nmea file name) -o kml -F (new file name.kml))

gpsbabel -i nmea -f data.160902Sep091472862456.nmea -o kml -F trackdata1.kml

Enter

After a split second you should see a purple diamond with gears in it named trackdata1.kml.

You can now import this into Google maps and view your track data.

We also installed FoxtrotGPS you can run it with the command

sudo foxtrotgps

It should launch into a simple map program that shows your current location and allows you to create a track log within the software.

Step 8:

That's it! It should work. Let me know how you like it.

<p>Thanks for the tutorial!! Loved it and was super helpful in getting my students on the right track for their project!</p><p>Question: I set the pi to launch on boot up. Should it be overwriting the original data file each time, creating a new file, or creating a new data file? I'm not sure that it is actually updating though it seems the GPS is launching correctly. </p><p>My ultimate goal is to email the kml file and I wan the kml file updated each time I send the email.</p><p>Thanks!</p>
It should make a new file every time the Pi reboots, best way to test this is make sure it has GPS signal and reboot after a few minutes, then ssh in to the data directory and look. I have also had it set up to upload to Dropbox every hour, day, minute, whatever. Good luck. Anymore questions feel free to ask.
<p>Great project! </p>
<p>This is very nice. But there has to be another way to achieve the same, without the USB GPS receiver. I have a tablet and I have a route-planner program in it. I have a special Bluetooth GPS Receiver and that works. </p><p>One day I did not have my Bluetooth GPS Receiver with me, and then it worked also, I wondered why!!! It turns out to be that my tablet was paired with my telephone, I did it long ago. My tablet had no build in GPS receiver, nor was it making use of the GSM/GPRS or something telephone network by it self. My tablet was using a Bluetooth connection to my phone, and in a mysterious way this phone was giving my tablet details about the whereabouts. </p><p>I have no idea how this works. I do not know the protocols. It is rather magical. Without a GPS receiver getting the info of the GPS location. I assume that you don't get any info when the telephone is out of reach, then you are really into the wild.</p>
<p>This could work great for long road trips</p>

About This Instructable

7,208views

33favorites

More by mkbcaptain:Raspberry Pi 3 GPS Data logger 
Add instructable to: