You can always just read that raw data, but its much nicer if you can have some Linux software prettify it. We'll try out gpsd which is a GPS-handling Daemon (background-helper)
Installing a GPS Daemon (gpsd)
The first step is installing some software on your Raspberry Pi that understands the serial data that your GPS module is providing via /dev/serial0.
Thankfully other people have already done all the hard work for you of properly parsing the raw GPS data, and we can use (amongst other options) a nice little package named 'gpsd', which essentially acts as a layer between your applications and the actual GPS hardware, gracefully handling parsing errors, and providing a common, well-defined interfaces to any GPS module.
To install gpsd, make sure your Pi has an Internet connection and run the following commands from the console:
sudo apt-get update sudo apt-get install gpsd gpsd-clients
And install the software as it prompts you to do.
systemd service fix
Recent Raspberry Pi OS releases (“Jessie” or later) require disabling a 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). One must 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.socket sudo systemctl start gpsd.socket
Try out 'gpsd'
After installing gpsd and disabling the gpsd systemd service as mentioned above you're ready to start using gpsd yourself.
Start gpsd and direct it to use HW UART. Simply entering the following command:
sudo gpsd /dev/serial0 -F /var/run/gpsd.sock
... which will point the gps daemon to our GPS device on the /dev/serial0 port.
Try running gpsmon to get a live-streaming update of GPS data!
or cgps which gives a less detailed, but still quite nice output
cgps -s
sudo gpsd /dev/serial0 -F /var/run/gpsd.sock
More info!
You can use gpsd to help you read data into other programming languages like C and Python using a variety of existins libraries
The following tutorials may be useful to you if you want to dig into this a bit further, and do something a bit more advanced with your GPS data:
- GETTING GPS TO WORK ON A RASPBERRY PI.
- GPSD Client How-To ... including examples in C, C++ and Python
- The official GPSD project pages
- A nice writeup of using GPSd with python using threads to make it faster
- Great forum post on how to setup time synchronization with a Raspberry Pi and the PPS output of the GPS HAT.
- Another good write-up on how to configure a Pi to use GPS and the PPS output for time synchronization. Note that this guide uses GPIO18 for the PPS signal but the HAT uses GPIO4.
Doing something fun with GPS and tracking data? Be sure to post about it in the Adafruit forums so everyone else can get inspired by it!
Text editor powered by tinymce.