# Adafruit GPS Hat in Windows IoT Core

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/035/170/medium800/raspberry_pi_GPS_Hat.jpg?1472496259)

Location, location, location... &nbsp;What could be more important? &nbsp;And now your Raspberry Pi can help keep you centered&nbsp;with the Adafruit Ultimate GPS Hat and Windows IoT Core!

In this guide, we'll take you through setting up and running our GPS Demo IoT application.&nbsp;

Works on&nbsp;Pi Model A+ or B+, Pi 2, and Pi 3.

(New to Windows IoT Core? Check out our [Getting started with Windows IoT Core](../../../getting-started-with-windows-iot-on-raspberry-pi)&nbsp;series of tutorials!)

# Adafruit GPS Hat in Windows IoT Core

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/035/171/medium800/raspberry_pi_gps_assembly.jpg?1472497957)

The Hat comes with the GPS assembled onto the HAT circuit board. There's also&nbsp;a 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.&nbsp;[You can also swap the plain female header we provide&nbsp;with a 'stacky' type that lets you plug in a hat or GPIO cable on top](https://www.adafruit.com/products/2223),&nbsp;or you can use a&nbsp;[slim ultra-low-profile header.](https://www.adafruit.com/product/2243)

You'll also want to add a 12mm CR1220 coin cell as a backup for the GPS. &nbsp;This will allow the GPS to acquire satellites faster on startup, and it will preserve your settings if the Hat is disconnected from power.&nbsp;It will also let you use the real-time-clock capability of the GPS HAT. **To make air-shipping eaiser, the&nbsp;HAT does not come with a coin battery! [Y](https://www.adafruit.com/product/380)**[ou can pick one up locally or order one from us.](https://www.adafruit.com/product/380)

Solder the 2x20 header into the matching 2x20 rows of holes on the Hat, then plug the Hat into your Pi. &nbsp;That's it! You're ready to go&nbsp;- no preliminary software or hardware setup&nbsp;necessary!

# Adafruit GPS Hat in Windows IoT Core

## GPSDemoApp

To get started, download the GPSDemo solution from github and save it in your favorite Windows IoT project folder.

[Download GPSDemo Solution](https://github.com/adafruit/GPSDemoApp)
On the github page, you'll see a green button labeled 'Clone or Download'. &nbsp;Click that and select 'Download Zip'. &nbsp;Extract the downloaded zip file to your projects folder.

![](https://cdn-learn.adafruit.com/assets/assets/000/035/172/medium800/raspberry_pi_CloneOrDownload.png?1472498750)

Now, open the GPSDemoApp solution file in Visual Studio (you'll need&nbsp;to use VS 2015 or later).

![](https://cdn-learn.adafruit.com/assets/assets/000/035/173/medium800/raspberry_pi_open_solution.png?1472499123)

GPSDemoApp is a _Headed_ application. That means it has a user interface (_Headless_ applications run in the background and don't have a user interface).

Our user interface is very simple, but it shows important updates&nbsp;from the GPS in real-time:

![](https://cdn-learn.adafruit.com/assets/assets/000/037/739/medium800/raspberry_pi_new_gui.jpg?1480884851)

When Visual Studio comes up with the GPSDemoApp&nbsp;solution, you'll see MainPage.xaml in Solution Explorer. This is the user interface designer file. If you click on the line that says MainPage.xaml, MainPage.xaml.cs will drop down. &nbsp;This is the C# code that goes with the user interface, and this is where the GPSDemoApp code lives.

![](https://cdn-learn.adafruit.com/assets/assets/000/035/174/medium800/raspberry_pi_gps_headed_solution.png?1472499844)

In MainPage.xaml, we've requested a Page\_Loaded event to occur when the GUI has been fully initialized. &nbsp;We'll use the Page\_Loaded event to create a new GPS object. &nbsp;We'll also set up a couple of events that will notify us&nbsp;when a new GPS NMEA sentence has been received. Finally, we'll call StartGPS to begin reading NMEA sentences from the GPS HAT.

![](https://cdn-learn.adafruit.com/assets/assets/000/035/618/medium800/raspberry_pi_Page_Loaded.png?1473278925)

StartGPS is an asynchronous task in MainPage.xaml.cs. &nbsp;We don't want to block the main UI thread (where Page\_Loaded was called from), so we'll do our GPS inisialization from a separate task.

First thing is to call the GPS library function ConnectToUart. &nbsp;The GPS Hat communicates with the Pi over the Pi's serial port. &nbsp;So, we need to attach and open that port to talk to the GPS.

Once the serial port is connected, we tell the GOS which NMEA sentences we're interested in receiving, and how often we'd like those sentences to be updated. For these operations, we call the librry functions SetSentencesReporting and SetUpdateFrequency.

Finally, we start yet another asynchronous task. &nbsp;This is the task that reads the GPS and parses the NMEA sentences for us. the startReading function takes care of that for us.

![](https://cdn-learn.adafruit.com/assets/assets/000/035/619/medium800/raspberry_pi_StartGPS.png?1473279365)

At this point, the GPS Library is reading and parsing sentences from the Hat. &nbsp;But we want to be notified when a new sentence comes in. &nbsp;That's what the events are for. &nbsp;

Each event is given&nbsp;a data structure that contains all the data parsed from the sentence. The GPS library will fire an event with each sentence received, complete with the latest data.

We set up event functions to capture those events and display the parsed GPS data on our GUI.

![](https://cdn-learn.adafruit.com/assets/assets/000/035/620/medium800/raspberry_pi_events.png?1473279690)

There's one other thing we need to do, and that's to add a reference to the AdafruitClassLibrary. &nbsp;This is a special library package containing Windows IoT Core driver software for a variety of Adafruit products.

The Adafruit Class Library contains the GPS class that we've been using here in the demo app. The GPS class takes care of reading and parsing sentence data from the GPS, and is responsible for firing the events that provide the app with sentence information.

Details on installing the Adafruit Class&nbsp;Library are on&nbsp;the next page. For details on the GPS class itself, see the [Adafruit Class Library&nbsp;documentation](../../../../adafruit-class-library-for-windows-iot-core/gps-class).

But wait .. there's _still_ one other thing. &nbsp;The GPS Hat uses Serial communications. We have to configure the app for serial capability. This is done in the Package.appxmanifest file. &nbsp;You can open the package manifest editor by double-clicking on the file in Solution Explorer. You can set all sorts of capabilities for the app in the editor.

One thing you can't set in the editor is the serial capability. For that, we have to use a regular text editor. &nbsp;Right-click on Package.appxmanifest in Solution Explorer and select 'Open With...'. &nbsp;In the popup list, select 'Source Code (Text) Editor'. The editor will open with the raw XML contents of the package manifest. Look for this section near the bottom:

```
  &lt;Capabilities&gt;
    &lt;Capability Name="internetClient" /&gt;
  &lt;/Capabilities&gt;

```

We need to add our serial capability to this \<Capabilities\> block.&nbsp;Edit the block so that it looks like this:

```
  &lt;Capabilities&gt;
    &lt;Capability Name="internetClient" /&gt;
    &lt;DeviceCapability Name="serialcommunication"&gt;
      &lt;Device Id="any"&gt;
        &lt;Function Type="name:serialPort" /&gt;
      &lt;/Device&gt;
    &lt;/DeviceCapability&gt;
  &lt;/Capabilities&gt;

```

# Adafruit GPS Hat in Windows IoT Core

## Adafruit Class Library

The Adafruit Class Library is a special library package containing Windows IoT Core driver software for a variety of Adafruit products. To use the library, you must add a reference to it in your project.&nbsp;

To add the reference to&nbsp;the Adafruit Class Library, you'll&nbsp;need to use the NuGet Package Manager, which is a standard part of Visual Studio.

To get to the Package Manager, open the Project Menu and select "Manage NuGet Packages..."

![](https://cdn-learn.adafruit.com/assets/assets/000/035/175/medium800/raspberry_pi_ManageNuGetPackages.png?1472500325)

In the Package Manager window, select "Browse", and enter "AdafruitClassLibrary" in the search box. Select the library in the list, and click the Install box on the right-hand side of the window

![](https://cdn-learn.adafruit.com/assets/assets/000/035/176/medium800/raspberry_pi_AdafruitClassLibrary.png?1472500597)

You should now see AdafruitClassLibrary under References in Solution Explorer. &nbsp;That's all there is to it!

![](https://cdn-learn.adafruit.com/assets/assets/000/035/177/medium800/raspberry_pi_ClassLibInReferences.png?1472500847)

Sources for the Class Library are available here!

&nbsp;

[AdafruitClassLibrary sources](https://github.com/adafruit/AdafruitClassLibrary)

## 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)
### Microsoft IoT Pack for Raspberry Pi 3 - w/ Raspberry Pi 3

[Microsoft IoT Pack for Raspberry Pi 3 - w/ Raspberry Pi 3](https://www.adafruit.com/product/2733)
The **Microsoft Internet&nbsp;of Things&nbsp;Pack for Raspberry Pi 3** &nbsp;is the best way to get started using Windows 10 and your Raspberry Pi as an IoT enabled device.

A collaboration between Microsoft's IoT division and Adafruit, this pack's the best way to get...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2733)
[Related Guides to the Product](https://learn.adafruit.com/products/2733/guides)
### GPIO Stacking Header for Pi A+/B+/Pi 2/Pi 3

[GPIO Stacking Header for Pi A+/B+/Pi 2/Pi 3](https://www.adafruit.com/product/2223)
Connect your own PCB to a Raspberry Pi B+ and stack on top with this normal-height female header with extra long pins. &nbsp;The female header part is about 8.5mm tall, good for small HATs that do not to clear the USB/Ethernet jacks. This header has extra long 10mm pins, compared with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2223)
[Related Guides to the Product](https://learn.adafruit.com/products/2223/guides)
### GPIO Header for Raspberry Pi HAT - 2x20 Short Female Header

[GPIO Header for Raspberry Pi HAT - 2x20 Short Female Header](https://www.adafruit.com/product/2243)
This 'shorty' 2x20 header is great for a slim connection to your Raspberry Pi model A+ or B+, it's basically the&nbsp; through-hole version of the&nbsp;[SMT GPIO Header for Raspberry Pi HAT - 2x20 Short Female Header](https://www.adafruit.com/product/2187).

<span...></span...>

In Stock
[Buy Now](https://www.adafruit.com/product/2243)
[Related Guides to the Product](https://learn.adafruit.com/products/2243/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...

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

## Related Guides

- [Adafruit Ultimate GPS HAT for Raspberry Pi](https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi.md)
- [Windows IoT Core Application Development: Headless Blinky](https://learn.adafruit.com/windows-iot-application-development-headless-application.md)
- [Windows IoT Core Application Development: Headed Blinky](https://learn.adafruit.com/windows-iot-application-development-headed-blinky.md)
- [Adafruit Class Library for Windows IoT Core](https://learn.adafruit.com/adafruit-class-library-for-windows-iot-core.md)
- [Getting Started With Windows IoT Core on Raspberry Pi](https://learn.adafruit.com/getting-started-with-windows-iot-on-raspberry-pi.md)
- [Windows IoT Core Application Management](https://learn.adafruit.com/windows-iot-application-management.md)
- [Super Simple Sunrise Lamp](https://learn.adafruit.com/super-simple-sunrise-lamp.md)
- [Adafruit's Raspberry Pi Lesson 6. Using SSH](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh.md)
- [PyPortal New New New Product Viewer](https://learn.adafruit.com/pyportal-new-new-new-product-viewer.md)
- [Kali Linux on the Raspberry Pi with the PiTFT](https://learn.adafruit.com/kali-linux-on-the-raspberry-pi-with-the-pitft.md)
- [Large Pi-based Thermometer and Clock](https://learn.adafruit.com/large-pi-based-thermometer-and-clock.md)
- [7” Portable Multitouch Raspberry Pi Tablet](https://learn.adafruit.com/7-portable-raspberry-pi-multitouch-tablet.md)
- [Internet of Things Printer for Raspberry Pi](https://learn.adafruit.com/pi-thermal-printer.md)
- [Creepy Face Tracking Portrait](https://learn.adafruit.com/creepy-face-tracking-portrait.md)
- [PyPortal Event Countdown Clock](https://learn.adafruit.com/pyportal-event-countdown-clock.md)
