# Adafruit Ultimate GPS HAT for Raspberry Pi

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/021/930/medium800/adafruit_products_mainpix.jpg?1419626390)

It's 10PM, do you know where your Pi is? If you had this Pi HAT, you would! This new HAT from Adafruit adds our celebrated Ultimate GPS on it, so you can add precision time and location to most Raspberry Pi boards (anything with the 40-pin GPIO “HAT” header; early Pi models with a 26-pin header are not compatible, nor are bare Compute Module boards).

Here's the low-down on the GPS module:

- -165 dBm sensitivity, 10 Hz updates, 66 channels
- Only 20mA current draw
- Built in Real Time Clock (RTC) - slot in a CR1220 backup battery for 7-years or more of timekeeping even if the Pi is off!
- PPS output on fix, by default connected to pin #4
- We have received reports that it works up to ~32Km altitude (the GPS theoretically does not have a limit until 40Km)
- Internal patch antenna which works quite well when used outdoors + u.FL connector for external active antenna for when used indoors or in locations without a clear sky view
- Fix status LED blinks to let you know when the GPS has determined the current coordinates

 **This HAT takes over the Pi's hardware UART to send/receive data to and from the GPS module**. So, if you need to use the RX/TX pins with a console cable, you cannot also use this HAT. Instead, you'll have to use a monitor and keyboard to log in, or use _ssh_ to connect over the network to your Pi.

Comes as a fully assembled GPS + PCB and an additional 2x20 GPIO header. Some light soldering is required to attach the 2x20 GPIO header to the HAT but it's fast and easy for anyone with a soldering iron and solder. [You can also swap the plain female header we have with a 'stacky' type that lets you plug in a hat or GPIO cable on top](https://www.adafruit.com/products/2223) or a [slim ultra-low-profile header.](https://www.adafruit.com/product/2243)

_Even with a low-profile header installed, the GPS module itself adds sufficient thickness that the Pi + HAT won’t fit in most close-fitting Pi cases. If full protection from the elements is required, you’ll have to improvise or find a [larger plastic enclosure](https://www.adafruit.com/product/905), perhaps with cable glands._

# Adafruit Ultimate GPS HAT for Raspberry Pi

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/021/931/medium800/adafruit_products_GPS_Board_kit_ORIG.jpg?1419627303)

This HAT is pretty simple but its worth going thru what pins are used for what!

The Ultimate GPS uses the following GPIO pins: **TXD, RXD, #4** and **EEDATA/EECLK**

# Serial Console Pins

The Raspberry Pi has only one serial port, and you do need serial to chat to a GPS so we will take over the **RXD** and **TXD** pins.

# PPS Pin

GPS's can output a 'pulse per second' for synchronizing the time. We have a breakout for this and a closed jumper that connects it to **GPIO#4** - if you do not need PPS and want to&nbsp; use #4 for something else, just cut the little connection on the PPS PCB line.

# HAT EEPROM

EEDATA/EECLK are connected to a 24C32 EEPROM that contains the name and maker of this HAT (it's not used by the Pi Kernel just yet)

# Adafruit Ultimate GPS HAT for Raspberry Pi

## Pi GPS Setup

**[Don't forget to also read our Ultimate GPS tutorial which has a lot of information about this GPS module and datasheets/example code that you will find handy!](http://learn.adafruit.com/adafruit-ultimate-gps "Link: http://learn.adafruit.com/adafruit-ultimate-gps")**

Warning: 

# Set up the Pi to release the console pins

Start by logging into your Pi using a monitor/keyboard or via **ssh**

To disable the login shell and serial output quickly use the following command-line approach or if you prefer the multi-step graphical menu. Either way you need to do a reboot after.&nbsp;

```terminal
sudo raspi-config nonint do_serial_cons 1
sudo reboot
```

Run **sudo raspi-config** to configure the system, and select **Interfacing Options**.

![adafruit_products_gps-setup-1.png](https://cdn-learn.adafruit.com/assets/assets/000/112/903/medium640/adafruit_products_gps-setup-1.png?1657143590)

Select **Serial Port.**

![adafruit_products_gps-setup-2.png](https://cdn-learn.adafruit.com/assets/assets/000/112/904/medium640/adafruit_products_gps-setup-2.png?1657143774)

When asked about a login shell, select **No**.

![adafruit_products_gps-setup-3.png](https://cdn-learn.adafruit.com/assets/assets/000/112/905/medium640/adafruit_products_gps-setup-3.png?1657144021)

Then select **Yes** to keep the serial port hardware enabled.

The system will confirm your choices: login shell disabled, interface enabled. Select **OK**.

![adafruit_products_gps-setup-4.png](https://cdn-learn.adafruit.com/assets/assets/000/112/906/medium640/adafruit_products_gps-setup-4.png?1657144068)

![adafruit_products_gps-setup-4b.png](https://cdn-learn.adafruit.com/assets/assets/000/112/907/medium640/adafruit_products_gps-setup-4b.png?1657144331)

Thats it! You’ll be back at the main menu. Press the tab key a couple times to select **Finish** , and select **No** when asked to reboot the system.

![adafruit_products_gps-setup-5a.png](https://cdn-learn.adafruit.com/assets/assets/000/112/908/medium640/adafruit_products_gps-setup-5a.png?1657144398)

![adafruit_products_gps-setup-5b.png](https://cdn-learn.adafruit.com/assets/assets/000/112/910/medium640/adafruit_products_gps-setup-5b.png?1657148966)

Instead, we’ll shut down the Pi to install hardware…

Run **sudo shutdown -h now** for a safe and orderly system shutdown. Wait 15 seconds or so before removing power, or watch for the status LED to stop blinking.

Plug in the GPS HAT to the Pi’s GPIO header and re-connect power to the system. Log in and you can proceed with testing the GPS!

# Adafruit Ultimate GPS HAT for Raspberry Pi

## Basic Test

We can get started by testing the GPS right at the command line.

Before you start, you'll want to make sure the GPS modules has a 'fix' - that means it has received enough data from satellites to determinet he location.

You can quickly determine fix status by looking at the Red LED on the GPS Hat:

- Blinking on and off once every other second - NO FIX
- Blinking once per 10 seconds or so - HAS FIX

You may need to put the Pi near a window or attach an external antenna. Once it has a fix, continue!

Info: The Pi 5 uses /dev/ttyAMA0

# Serial test

Lets stat by just reading the 'raw' data from the GPS on the command line. Run:

```auto
stty -F /dev/serial0 raw 9600 cs8 clocal -cstopb
```

To set **/dev/serial0** (the serial port used by the GPS HAT) to raw data ( **raw** ) 9600 baud ( **9600** ) 8-bits ( **cs8** ) no modem control ( **clocal** ) and 1 stop bit (- **cstopb** )

It's pretty picky so please use those settings and not noodle with them too much unless you're sure!

Now run:

```auto
cat /dev/serial0
```

To read raw data directly from the GPS HAT

You should see something like this!

![](https://cdn-learn.adafruit.com/assets/assets/000/021/933/medium800/adafruit_products_catAMA0.png?1419630198)

This is the raw GPS "NMEA sentence" output from the GPS module. There are a few different kinds of NMEA sentences, the most common ones people use are the&nbsp; **$GPRMC** &nbsp;( **G** lobal&nbsp; **P** ositioning&nbsp; **R** ecommended **M** inimum&nbsp; **C** oordinates or something like that) and the&nbsp; **$GPGGA** &nbsp;sentences. These two provide the time, date, latitude, longitude, altitude, estimated land speed, and fix type. Fix type indicates whether the GPS has locked onto the satellite data and received enough data to determine the location (2D fix) or location+altitude (3D fix).

[For more details about NMEA sentences and what data they contain, check out this site](http://www.gpsinformation.org/dale/nmea.htm)

If your data looks like this, with a lot of commas, with no data in between them. That's because this module is does not have a 'fix'.&nbsp; **DONT FORGET** To get a fix, we need to put the module or antenna outside or have it able to see the sky!

![](https://cdn-learn.adafruit.com/assets/assets/000/021/934/medium800/adafruit_products_catnofix.png?1419630363)

Danger: 

OK lets look at a good NMEA sentence with 'fix'

Something that starts with $GPRMC like:

```auto
$GPRMC,194509.000,A,4042.6142,N,07400.4168,W,2.03,221.11,160412,,,A*77 
```

This line is called the RMC (Recommended Minimum) sentence and has pretty much all of the most useful data. Each chunk of data is separated by a comma.

The first part&nbsp; **194509.000** &nbsp;is the current time **GMT** (Greenwich Mean Time). The first two numbers **&nbsp;19&nbsp;** indicate the hour (1900h, otherwise known as 7pm) the next two are the minute, the next two are the seconds and finally the milliseconds. So the time when this screenshot was taken is 7:45 pm and 9 seconds. The GPS does not know what time zone you are in, or about "daylight savings" so you will have to do the calculation to turn GMT into your timezone

The second part is the 'status code', if it is a&nbsp; **V** &nbsp;that means the data is&nbsp; **V** oid (invalid). If it is an&nbsp; **A** &nbsp;that means its&nbsp; **A** ctive (the GPS could get a lock/fix)

The next 4 pieces of data are the geolocation data. According to the GPS, my location is **&nbsp;4042.6142,N**** &nbsp;**(Latitude 40 degrees, 42.6142 decimal minutes North) &&nbsp;**07400.4168,W**. (Longitude 74 degrees, 0.4168 decimal minutes West) To look at this location in Google maps, type&nbsp;**+40° 42.6142', -74° 00.4168'**&nbsp;into the&nbsp;[google maps search box](http://maps.google.com/)&nbsp;. Unfortunately gmaps requires you to use +/- instead of NSWE notation. N and E are positive, S and W are negative.

Danger: 

The next data is the ground speed in knots. We're going&nbsp; **2.03** &nbsp;knots

After that is the tracking angle, this is meant to approximate what 'compass' direction we're heading at based on our past travel

The one after that is&nbsp; **160412** &nbsp;which is the current date (this sentence was first 'grabbed' on 16th of April, 2012).

Finally there is the&nbsp; **\*XX** &nbsp;data which is used as a data transfer checksum

Once you get a fix using your GPS module, verify your location with google maps (or some other mapping software). Remember that GPS is often only accurate to 5-10 meters and worse if you're indoors or surrounded by tall buildings.

# Adafruit Ultimate GPS HAT for Raspberry Pi

## Use 'gpsd'

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:

```auto
sudo apt-get update
sudo apt-get install gpsd gpsd-clients
```

And install the software as it prompts you to do.

## Configure gpsd
Modify the system-wide GPSD config file to support your serial port.

```terminal
sudo nano /etc/default/gpsd
```

A Pi 5 would use:

```auto
DEVICES="/dev/ttyAMA0"
```

All other models of Pi would have a config file that looks like the following:

```auto
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/serial0"

# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"

# Automatically hot add/remove USB GPS devices via gpsdctl
USBAUTO="true"
```

After updating the configuration file reboot to verify gpsd correctly starts on its own and you can run the following gps related utilities:

&nbsp;

- gpsmon
- cgps
- ppstest

&nbsp;

```terminal
sudo reboot
```

```terminal
cgps
```

![cgps](https://cdn-learn.adafruit.com/assets/assets/000/137/907/medium800/adafruit_products_cgps.png?1750357725 cgps)

```terminal
gpsmon
```

![gpsmon](https://cdn-learn.adafruit.com/assets/assets/000/137/908/medium800/adafruit_products_gpsmon.png?1750357733 gpsmon)

# Enable PPS

PPS uses GPIO pin 4 on the GPS HAT and can work with the same setup using the GPS breakout. You do need to modify the kernel config.txt to support this setup. This means a reboot will be needed after updating the config.txt.

```terminal
nano /boot/firmware/config.txt
# add this to the end of the file
dtoverlay=pps-gpio,gpiopin=4
```

```auto
pi@pi5:~ $ sudo ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
source 0 - assert 1750357430.000213158, sequence: 13817 - clear  0.000000000, sequence: 0
source 0 - assert 1750357431.000212074, sequence: 13818 - clear  0.000000000, sequence: 0
source 0 - assert 1750357432.000212376, sequence: 13819 - clear  0.000000000, sequence: 0
source 0 - assert 1750357433.000212085, sequence: 13820 - clear  0.000000000, sequence: 0
```

Danger: 

# More info!

You can use **gpsd** to help&nbsp; 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](http://blog.retep.org/2012/06/18/getting-gps-to-work-on-a-raspberry-pi/ "Link: http://blog.retep.org/2012/06/18/getting-gps-to-work-on-a-raspberry-pi/").
- [GPSD Client How-To](http://www.catb.org/gpsd/client-howto.html "Link: http://gpsd.berlios.de/client-howto.html") ... including examples in C, C++ and Python
- The official [GPSD project pages](http://catb.org/gpsd/)
- [A nice writeup of using GPSd with python using threads to make it faster](http://www.danmandle.com/blog/getting-gpsd-to-work-with-python/)
- [Great forum post on how to setup time synchronization with a Raspberry Pi and the PPS output of the GPS HAT.](https://forums.adafruit.com/viewtopic.php?f=50&t=70133&start=60#p359668)
- [Another good write-up on how to configure a Pi to use GPS&nbsp;and the PPS output for time synchronization.](http://www.satsignal.eu/ntp/Raspberry_Time%20-%20Broadband%20Ham%20Net.pdf)&nbsp; 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](http://forums.adafruit.com/) so everyone else can get inspired by it!

# Adafruit Ultimate GPS HAT for Raspberry Pi

## External Antenna

![](https://cdn-learn.adafruit.com/assets/assets/000/021/932/medium800/adafruit_products_GPS_Board_top_demo_01_ORIG.jpg?1419628838)

All Ultimate GPS modules have a built in patch antenna - this antenna provides -165 dBm sensitivity and is perfect for many projects. However, if you want to place your project in a box, it might not be possible to have the antenna pointing up, or it might be in a metal shield, or you may need more sensitivity. In these cases, [you may want to use an external active antenna.](https://www.adafruit.com/products/960)  
  
[Active antennas draw current, so they do provide more gain but at a power cost. Check the antenna datasheet for exactly how much current they draw - its usually around 10-20mA.](https://www.adafruit.com/products/960 "Link: https://www.adafruit.com/products/960")  
  
Most GPS antennas use SMA connectors, which are popular and easy to use. However, an SMA connector would be fairly big on the GPS breakout so we went with a uFL connector - which is lightweight, small and easy to manufacture. If you don't need an external antenna it wont add significant weight or space but [its easy to attach a uFL-\>SMA adapter cable](http://www.adafruit.com/products/851). Then connect the GPS antenna to the cable.  
  
The Ultimate GPS will automagically detect an external active antenna is attached and 'switch over' - you do not need to send any commands  
  
There is an output sentence that will tell you the status of the antenna. **$PGTOP,11,x** where **x** is the status number. If **x** is **3** that means it is using the external antenna. If **x** is **2** it's using the internal antenna and if **x** is **1** there was an antenna short or problem.  
  
On newer shields & modules, you'll need to tell the firmware you want to have this report output, you can do that by sending it the command **$PGCMD,33,1\*6C**

# Adafruit Ultimate GPS HAT for Raspberry Pi

## Battery Backup

The GPS has a built in real time clock, which can keep track of time even when it power is lost and it doesn't have a fix yet. It can also help reduce fix times, if you expect to have a flakey power connection (say you're using solar or similar). To use the RTC, we need to insert a battery. There is holder on the HAT for a&nbsp; **CR1220** &nbsp;sized battery holder. We provide the holder but the battery is not included. You can use any 12mm coin cell - these are popular and we also carry them in the Adafruit shop.

![](https://cdn-learn.adafruit.com/assets/assets/000/021/935/medium800/adafruit_products_coinholder.jpg?1419630715)

Remember, the GPS does not know what time zone you are in (even though it knows your location, there is no easy way to determine time zone without a massive lookup table) so all date/time data is in UTC (aka. Greenwich Mean Time)

The Pi’s system clock can be synchronized from the GPS if no network time server is reachable, but this gets pretty technical and is beyond the scope of this guide. [Here’s a tutorial elsewhere that might help](https://austinsnerdythings.com/2021/04/19/microsecond-accurate-ntp-with-a-raspberry-pi-and-pps-gps/)…scroll down to section 4, since the GPS hardware is a bit different, just need the software steps.

# Adafruit Ultimate GPS HAT for Raspberry Pi

## Downloads

# Files

- [MTK3329/MTK3339 command set sheet](http://www.adafruit.com/datasheets/PMTK_A11.pdf) for changing the fix data rate, baud rate, sentence outputs, etc!
- [PMTK 'complete' datasheet](http://www.adafruit.com/datasheets/PMTK%20command%20packet-Complete-C39-A01.pdf) (like the above but with even more commands)
- [Datasheet for the PA6H (MTK3339) GPS module itself](http://www.adafruit.com/datasheets/GlobalTop-FGPMMOPA6H-Datasheet-V0A.pdf)
- [Fritzing object in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library)
- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit-Ultimate-GPS-HAT-PCB)

# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/021/938/medium800/adafruit_products_schem.png?1419632501)

# Fabrication Print

Dimensions in inches

![](https://cdn-learn.adafruit.com/assets/assets/000/021/939/medium800/adafruit_products_fabprint.png?1419632531)


## Featured Products

### Adafruit Ultimate GPS HAT for Raspberry Pi A+/B+/Pi 2/3/4/Pi 5

[Adafruit Ultimate GPS HAT for Raspberry Pi A+/B+/Pi 2/3/4/Pi 5](https://www.adafruit.com/product/2324)
It's 10 PM, do you know where your Raspberry Pi is? If you had this GPS HAT, you would! This new HAT from Adafruit adds our celebrated Ultimate GPS, so you can add precision time and location to your Raspberry Pi Model Pi 3, Pi Zero, A+,&nbsp;B+, or Pi 2, 3,&nbsp;4, &...

In Stock
[Buy Now](https://www.adafruit.com/product/2324)
[Related Guides to the Product](https://learn.adafruit.com/products/2324/guides)
### GPS Antenna - External Active Antenna - 3-5V 28dB 5 Meter SMA

[GPS Antenna - External Active Antenna - 3-5V 28dB 5 Meter SMA](https://www.adafruit.com/product/960)
Give your Ultimate GPS V3 a boost with this external active antenna. This GPS antenna draws about 10mA and will give you an additional 28 dB of gain. It's got a 5 meter long cable so it will easily reach wherever you need it to. The antenna is magnetic so it will stick to the top of a car...

In Stock
[Buy Now](https://www.adafruit.com/product/960)
[Related Guides to the Product](https://learn.adafruit.com/products/960/guides)
### SMA to uFL/u.FL/IPX/IPEX RF Adapter Cable

[SMA to uFL/u.FL/IPX/IPEX RF Adapter Cable](https://www.adafruit.com/product/851)
This RF adapter cable is super handy for anyone doing RF work. Often times, small electronics save space by having a pick-and-placeable u.FL connector (also called uFL, IPEX, IPAX, IPX, MHF, and AM). But most antennas have SMA or RP-SMA connectors on them. This little cable will bridge the...

In Stock
[Buy Now](https://www.adafruit.com/product/851)
[Related Guides to the Product](https://learn.adafruit.com/products/851/guides)
### CR1220 12mm Diameter - 3V Lithium Coin Cell Battery

[CR1220 12mm Diameter - 3V Lithium Coin Cell Battery](https://www.adafruit.com/product/380)
These are the highest quality & capacity batteries, the same as shipped with the iCufflinks,&nbsp;iNecklace, Datalogging and GPS Shields, GPS HAT, etc. One battery per order (you'll want one battery per cufflink or pendant.)  
  
Brand may vary but all battery brands are verified...

Out of Stock
[Buy Now](https://www.adafruit.com/product/380)
[Related Guides to the Product](https://learn.adafruit.com/products/380/guides)

## Related Guides

- [Adafruit GPS Hat in Windows IoT Core](https://learn.adafruit.com/adafruit-gps-hat-in-windows-iot-core.md)
- [Adafruit Class Library for Windows IoT Core](https://learn.adafruit.com/adafruit-class-library-for-windows-iot-core.md)
- [Light Painting with Raspberry Pi](https://learn.adafruit.com/light-painting-with-raspberry-pi.md)
- [Flora Wearable GPS](https://learn.adafruit.com/flora-wearable-gps.md)
- [AR1100 Resistive Touch Screen Controller Guide](https://learn.adafruit.com/ar1100-resistive-touch-screen-controller-guide.md)
- [Adafruit MEMENTO Camera Board](https://learn.adafruit.com/adafruit-memento-camera-board.md)
- [Naughty or Nice Machine](https://learn.adafruit.com/naughty-or-nice-machine.md)
- [Sending Live Sensor Data to iOS with BLE](https://learn.adafruit.com/bno055-ble-ios-app.md)
- [Getting Started With Windows IoT Core on Raspberry Pi](https://learn.adafruit.com/getting-started-with-windows-iot-on-raspberry-pi.md)
- [Adafruit DRV2605L Haptic Controller Breakout](https://learn.adafruit.com/adafruit-drv2605-haptic-controller-breakout.md)
- [Adafruit Circuit Playground Tri-Color E-Ink Gizmo](https://learn.adafruit.com/adafruit-circuit-playground-tri-color-e-ink-gizmo.md)
- [Adafruit Pixel Trinkey](https://learn.adafruit.com/adafruit-pixel-trinkey.md)
- [Raspberry Pi SelfieBlock](https://learn.adafruit.com/selfieblock.md)
- [piBeacon - DIY Beacon with a Raspberry Pi](https://learn.adafruit.com/pibeacon-ibeacon-with-a-raspberry-pi.md)
- [Adafruit ESP32-S2 Feather](https://learn.adafruit.com/adafruit-esp32-s2-feather.md)
