Quantcast
Channel: SparkFun Tutorials
Viewing all articles
Browse latest Browse all 1123

GPS Logger Shield Hookup Guide

$
0
0

GPS Logger Shield Hookup Guide a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t468

Introduction

The SparkFun GPS Logger Shield equips your Arduino with access to a GPS module, µSD memory card socket, and all of the other peripherals you’ll need to turn your Arduino into a position-tracking, speed-monitoring, altitude-observing wonder logger.

GPS Logger Shield

The shield is based around a GP3906-TLP GPS Module– a 66-channel GPS receiver featuring a MediaTek MT3339 architecture and an up to 10Hz update rate. The GPS module will stream constant position updates over a simple serial UART, which you can then log to a µSD card and/or use for other position or time-tracking purposes.

Everything on the shield is highly configurable: A switch allows you to select the GPS module’s UART interface between either hardware or software ports, the µSD card operates over a hardware SPI port, which should be compatible with most Arduino layouts, and extra prototyping space should allow you to add those last, few components you need to complete your project.

Covered In This Tutorial

This tutorial aims to document all things GPS Logger Shield related, including both the hardware and software required to get it up-and-running. It’s split into the following sections:

  • Hardware Overview– An overview of the schematic, layout, and features of the SparkFun GPS Logger Shield.
  • Hardware Setup– Tip for assembling the GPS Logger Shield to best match your project needs.
  • Example Arduino Sketches
    • GPS Serial Passthrough– A simple sketch you can use to verify functionality of your GPS Logger Shield, and get an idea of what kind of data the GP3906 GPS module produces.
    • TinyGPS++ Serial Streaming– Using the TinyGPS++ Arduino library to parse the GPS module’s NMEA strings into latitude, longitude, altitude, speed, and more.
    • µSD Card GPS Loging– Finally, we’ll plug the parsed GPS data into a CSV file and save it to a µSD card.

Suggested Materials

There are a few extra components you’ll need to get the GPS Logger Shield fully up-and-running:

Most importantly, you’ll need an Arduino or Arduino-compatible development board. The GPS’s serial and µSD SPI ports should be compatible with almost all Arduino-sized development boards. That includes classics, like the Arduino Uno and SparkFun RedBoard, and newer models, like the Arduino Leonardo, Genuino 101, and SparkFun SAMD21 Dev Breakout.

Arduino Uno - R3

DEV-11021
$24.95
60
SparkFun RedBoard - Programmed with Arduino

DEV-12757
$19.95
77
SparkFun SAMD21 Dev Breakout

DEV-13672
$24.95
Arduino Leonardo with Headers

DEV-11286
$24.95
6

We also highly recommend a 12mm Coin Cell Battery, which fits into the GPS Shield’s battery holder. The GP3906 GPS module requires some sort of voltage on its battery supply input. If you don’t have a battery, make sure you read the VBAT section of the hardware overview carefully.

Coin Cell Battery - 12mm (CR1225)

PRT-00337
$1.95
1

You’ll also need to solder some headers into the shield, to create a solid mechanical and electrical connection between it and the Arduino. We recommend the Arduino R3 Stackable Header Pack, but a set of male headers may also suit your needs.

Break Away Headers - Straight

PRT-00116
$1.5
19
Arduino Stackable Header Kit - R3

PRT-11417
$1.5
10
Female Headers

PRT-00115
$1.5
5
MicroSD Card with Adapter - 8GB

COM-11609
$13.95
2

Finally, if you intend on logging the GPS data to a µSD card, you may want to grab a µSD Card and SD Adapter. The Arduino SD library should support most µSD cards formatted with FAT16 or FAT32 file systems.

Suggested Reading

This is a beginner-level tutorial – and the GPS Logger Shield is a beginner-friendly product – but there are a few concepts you should be comfortable with before continuing on. If any of these subjects sound unfamiliar, considering reading those tutorials before continuing on.

  • GPS Basics– This tutorial is a great primer on the wonders of GPS. Learn how we get find our position on the globe by listening to (at least) four satellites send a timestamp and aerial position.
  • Serial Communication– The GP3906 communicates via a simple, serial UART. This tutorial will familiarize you with serial-related concepts like RX, TX, and baud rate.
  • How to Solder: Through-Hole Soldering– If you’ve never soldered before, now’s a great time to start, and this is a great tutorial to learn from.
  • Installing an Arduino Library– We’ll use a pair of fantastic Arduino libraries to log GPS data to an SD card.

How to Solder - Through-hole Soldering

New to electronics and soldering? Have you soldered before but need a refresher? This tutorial with cover everything you need to know about through-hole soldering.

Serial Communication

Asynchronous serial communication concepts: packets, signal levels, baud rates, UARTs and more!

GPS Basics

The Global Positioning System (GPS) is an engineering marvel that we all have access to for a relatively low cost and no subscription fee. With the correct hardware and minimal effort, you can determine your position and time almost anywhere on the globe.

Installing an Arduino Library

How do I install a custom Arduino library? It's easy!

Hardware Overview

For a quick overview of the components and features of the GPS Logger Shield, refer to the image below:

Annotated GPS Shield image

The rest of this section will dive into some of the more critical components of the shield, including power supply requirements and UART and SPI interface configurations.

Powering the GPS Logger Shield

The GPS Logger Shield’s main voltage supply is taken from the Arduino 5V header pin. This voltage is regulated down to 3.3V, which is supplied to both the GPS module and the µSD card.

These two components should consume around 30mA on average, but they may very occasionally spike to upwards of 100mA.

Logic-Level Shifting

The shield includes a TXB0108 8-Channel Level Shifter, which shifts voltage levels between the Arduino and 3.3V GPS UART and µSD SPI signals. Regardless of whether your Arduino runs at 5V or 3.3V, you shouldn’t have to concern yourself with shifting voltages between either component.

The Arduino-side logic-level voltage is set by the IOREF pin, which most Arduino development boards connect to either 5V or 3.3V.

⚡ If your Arduino board doesn't have an IOREF pin, or if no voltage is supplied on that pin, you will need to set the IOREF voltage manually. The shield includes a jumper on the back-side of the board, labeled IOREF-SEL, which you can use to set the IOREF voltage to either 3.3V or 5V.

If your Arduino board doesn't have an IOREF pin, set this jumper to match your desired logic level.

GP3906 Battery Supply (VBAT)

The GP3906 is a great, little module, but it has one, big quirk: A supply voltage between 2.0-4.3V is required on the VBAT pin. If you have a 12mm coin cell battery, supplying that voltage is as easy as pushing it into the battery socket. When you insert the battery, make sure you slot it in + side facing up.

Plugging battery into the GPS Shield

If you don’t have a battery handy, there are a few workarounds. You can grab a soldering iron, and short the 3V3-Batt jumper, next to the battery socket.

Batt/3V3 jumper closed

If you don’t have a 12mm battery, shorting the 3V3/Batt jumper will at least keep your GPS module functional.

Or you can wire the broken out VBAT pin to any voltage supply between 2.0-4.3V.

⚡ VBAT Supply Required: The GP3906 requires some form of voltage supply on its VBAT pin, whether that be an actual battery, or simply the 3.3V regulator output. If your the GPS LED isn't at least blinking (or illuminated) when the shield is powered up, that may indicate lack of supply to the VBAT port (or a dead battery).

Supplying the GP3906 with a backup battery supply ensures that its real-time clock (RTC) will continue to tick, even when the rest of the board is powered off. That allows the module to get faster GPS fixes when it initially powers up. It doesn’t consume a lot of power – we’ve measured around 5-6µA, – so a 12mm coin cell battery could keep the board “running” (in sleep mode) for about a year.

GPS Pin Breakout’s

Most of the GPS input, output, and power pins are connected to something on the GPS Logger Shield, but they’re all also broken out to this 8-pin header.

GPS Pin breakout's highlighted

Here’s a quick overview of each pin and its function:

Pin LabelIn/OutBoard ConnectionPin Description
GNDInGroundGPS module ground (0V reference)
PPSOut1 pulse-per-second time reference
ENInActive-high chip-enable – pull low to reset or turn off
RXInArduino TX/D9Serial data input
TXOutArduino RX/D8Serial data output
FIXOutGPS Fix LEDGPS fix indicator – blinks before a fix, HIGH once a fix is valid
VBATIn12mm coin cell socketBackup power – keeps the RTC running (2.0-4.3V input range)
3V3InOn-board 3.3V regulator3.3V power supply input

The PPS and EN pins are left unconnected. You’re free to wire them up to any Arduino pin should you need either a pulse-per-second signal, or extra control of the GPS module’s operation.

Selecting the Serial Port

The GPS module communicates via a simple, UART (serial) interface. The UART-select switch allows you to switch that interface between either the Arduino’s hardware UART – on pins D0 and D1 – or a SoftwareSerial port on pins D8 and D9.

UART-select switch

Should you need a reference, this table shows the map between GPS module and Arduino UART(s):

GPS PinArduino Software UART PinArduino Hardware UART Pin
RX91 (TX)
TX80 (RX)

If you’re using an Arduino Uno or any development board with one, pre-occupied hardware UART, you may be forced to use the software serial port. Fortunately, the GPS module’s baud rate defaults to a slow, steady 9600 bps, which SoftwareSerial shouldn’t have a problem handling.

If you need to move the software serial port pins, they can be custom-routed to any other pin by cutting the solder jumpers between pins GPS-RX and D8 and/or GPS-TX and D9.

Software UART-select jumpers

Once those jumpers are cut, you can wire the GPS-RX and GPS-TX pins to any other pins you’d like.

Selecting the µSD SPI Pins

On older Arduino boards, finding the SPI port was pretty simple – it’d be on pins 10-13, mapping out to CS, MOSI, MISO, and SCLK respectively. On more recent Arduino board releases, however, these pins are just as likely to be found on only the 6-pin, 2x3 SPI header. The GPS Logger Shield maps the µSD SPI pins to both of these headers, in order to support as many development boards as possible.

A trio of three-way solder jumpers can be used to modify which Arduino pins are routed to the µSD card’s SPI I/O’s.

SPI-select jumpers

The middle pad of these jumpers carries the signal to/from the µSD card. The pads toward the inside of the board carry signals to the SPI header, and the pads toward the outside carry signals to pins 10-13.

Boards that map SPI to pins 10-13 include the Arduino Uno, RedBoard, Arduino Pro's, and most ATmega328P-based boards. If you're using any of these boards, it should be safe to leave the jumper's untouched (as they're also, likely, shorted together on the Arduino).

Boards that only map SPI to the 2x3 SPI header include the Arduino Leonardo (and other most ATmega32U4-based boards), Arduino Due, and the Arduino Zero (and most ATSAMD21-based boards). On these boards, you'll need to cut the solder jumpers connecting the middle pad to the D11-, D10-, and D13-side pads.

Power and GPS Fix Status LEDs

This pair of LEDs on the corner of the shield are a handy tool for initial troubleshooting. The red PWR LED is attached to the output of the shield’s on-board 3.3V regulator. If the shield is getting power, this LED should be on.

The blue GPS FIX LED is connected the GP3906’s “3D_FIX” pin. It can be used to identify whether the GPS module has a proper fix or not. When you initially power the shield up, the LED should blink – indicating it’s trying to find a fix. Once the LED turns solidly on, you can rest assured that your GPS module has a good fix on your location.

3D Fix pin operation

The GP3906’s 3D_Fix pin operation. The LED will be on when the GPS fix is valid, and blinking at ½ Hz otherwise.

Both of these LEDs have solder jumpers underneath, should you find the need to disable either of them. A quick slice between the pads is all it takes to remove them from the circuit. This might be useful if you’re using the GPS Logger Shield in a low-power application, where even the handful of milliamps consumed by the LEDs means months off a project’s battery lifetime.

Hardware Setup

Assembly of the GPS Logger Shield mostly comes down to soldering something to all of the 6, 8, and 10-pin Arduino headers. We usually recommend Arduino R3 Stackable Headers for this job, but male headers can work – as long as this is the top board in a shield stack.

Stackable headers soldered into the shield

If your application requires use of the 6-pin, 2x3 SPI header, you may also want to solder female headers to those pins (make sure they’re pointing down, and slot easily into your Arduino’s male SPI pins).

If you’ve never soldered an Arduino shield before, check out our Arduino Shield Assembly tutorial for some tips.

Pre-Flight Checklist

Before you get the go-ahead for GPS Shield'ing, make sure you double-check these common pitfalls one last time:

Battery (VBAT) Power Supply

Make sure you have a reliable power source supplying the GPS module’s VBAT pin. If you have a shiny, new 12mm coin cell battery plugged in, that’s perfect. Otherwise, make sure you’ve either shorted the 3.3V/VBAT jumper, or are supplying something to the GPS module’s VBAT breakout.

Battery plugged in

UART Selected

Make sure you have the UART-select switch pointing towards your preferred UART. If you’re using an Uno, Redboard, or any other ATmega328P-based Arduino, you’ll most likely need to have the switch pointing towards SW-UART, assuming the hardware UART is used for programming and serial debugging.

If you're using an ATmega328-based Arduino, no matter what your sketch ends up doing, the switch must be in the SW-UART position during any programming upload.

If you’re using a Leonardo (ATmega32U4-based boards), Zero (ATSAMD21-based boards), or any other Arduino that has a dedicated and free hardware UART on pins 0/1, we recommend leaving the switch in the HW-UART position.

µSD SPI Jumpers

Planning on logging data to a µSD card? Make sure the SPI jumpers are set accordingly. If you’re using an Uno, Redboard, or any other ATmega328P-based Arduino, you can probably leave the jumpers untouched. SPI should be broken out to both pins 10-13 and the SPI header anyway.

If you’re using a Leonardo (ATmega32U4-based boards), Zero (ATSAMD21-based boards), or any other Arduino that doesn’t break the SPI signals to pins 10-13, you’ll want to cut the three SPI-select jumpers between the middle pad and the D11-D13 pins. That will free up those pins for other purposes in your project.

SPI jumpers cut for Leonardo

Looking closely, you’ll see traces cut on all three SPI lines between the middle pad and D11, D12, and D13. That disconnects the µSD lines from those pins – leaving them connected to the SPI header.

If you’re relying on the SPI port from the 2x3-pin ICSP header, don’t forget to solder headers to the SPI port!

Example Sketch: GPS Serial Passthrough

Now that your hardware is all set up, we have three pieces of example code to give you a taste of the GPS Logger Shield’s functionality. This first example isn’t all that useful, but it will, at least, make sure everything’s working. Plus it’ll show you the raw ugliness of NMEA GPS strings and make you appreciate great libraries like TinyGPS even more.

This example doesn’t require any additional libraries. Simply plug the shield into your Arduino and upload the example code. We’ve got a couple examples, depending on which Arduino and/or serial port you’re using.

Codebender Examples: For these examples, we're hosting the code on codebender, which not only features code-sharing, but also allows anyone to upload and debug Arduino sketches from within a web browser. Plus, it works on lower-tech machines, like Chromebooks!

There are codebender plugins for Chrome, Chromium, and Firefox. Visit the codebender plugin page for help installing the codebender plugin.

If the codebender embeds don't work for you, we'll also provide a download link to the example code.

SoftwareSerial Port Example

If you’re using an Arduino Mega, Arduino Uno, Redboard, any other ATmega328P-based Arduino, and have the UART-select switch in the SW-UART position, upload this piece of example code to your Arduino:

If the codebender embed doesn’t load for you, you can download the example code from our GitHub repository.

This example uses the SoftwareSerial library to communicate with the GPS module, and leaves the hardware serial port for debugging with the serial monitor.

Hardware Serial Port Example

If you’re using an Arduino Leonardo, Arduino Due, Arduino Zero, or any other Arduino with a free UART on pins 0/1, set the UART-select switch to HW-UART, and upload this example:

If the codebender embed doesn’t load for you, you can download the example code from our GitHub repository.

You may have to alter either or both of the serial port #defines at the top of the code. Refer to your development board’s datasheet or product info page for more information on which serial port is which.

Using the Serial Passthrough Sketch

Once you’ve uploaded the sketch, open up your serial monitor and set the baud rate to 9600. You should immediately begin to see GPS NMEA data begin to flow by at a rate of 1Hz.

For example, one set of strings may look like:

$GPRMC,235316.000,A,4003.9040,N,10512.5792,W,0.09,144.75,141112,,*19
$GPGGA,235317.000,4003.9039,N,10512.5793,W,1,08,1.6,1577.9,M,-20.7,M,,0000*5F
$GPGSA,A,3,22,18,21,06,03,09,24,15,,,,,2.5,1.6,1.9*3E

If you don’t see anything in the serial monitor, make sure the UART-select switch is in the correct position. Also double check that the blue “GPS Fix” LED is at least blinking. If it’s not, the module may not be receiving power. Don’t forget to supply VBAT!

If you’re still not having any luck, get in touch with our technical support team.


NMEA strings are the standard message format produced by almost all GPS receivers. They can relay all sorts of information including the time, latitude, longitude, altitude, and number of satellites visible, but unless you’re an incredibly fast parser, these sentences will mostly mean nothing. Fortunately, the Arduino can read those strings, parse them for you, and give you more human-readable pieces of data.

Example Sketch: TinyGPS Serial Streaming

A couple of our favorite GPS-parsing Arduino libraries are TinyGPS and TinyGPS++. These libraries simplify the task of parsing the excessive NMEA strings, leaving us with just the few bits of data we care about.

The TinyGPS libraries are built into codebender, which we’ll continue to use. If you’d like to install the libraries on your own Arduino development machine, visit the links above to download them. Reference our Installing an Arduino Library tutorial for any additional library-installing help you may need.

TinyGPS++ Example

Here’s a quick example, which uses the TinyGPS++ library to parse NMEA strings for position, altitude, time, and date. The code is also available in our GPS Shield GitHub repository, if the embed doesn’t work for you.

You may need to adjust the gpsPort and SerialMonitor defines near the top of the sketch. As it is, the sketch is set up to use the SoftwareSerial port.

After uploading the code, open up your serial monitor to watch the parsed GPS data stream by:

If your module doesn’t have a good GPS fix, you’ll probably see a lot of 0’s stream by; the time should be incrementing, although it’ll be incorrect (unless you plugged your Arduino in at exactly midnight!).

If you can find a way to take your computer and Arduino setup outside, that’ll be your best bet for getting a fix. Otherwise, try to take it near an open window. The better view it has of the sky, the better chance it’ll have to find the four satellites it needs.

A successful, fixed GPS stream will look something like this:

Lat: 40.090422
Long: -105.184534
Alt: 5243.77
Course: 295.56
Speed: 0.01
Date: 26/1/2016
Time: 20:19:34
Sats: 6

For more information on using the TinyGPS++ Library, check out the project homepage.

Example Sketch: µSD Card GPS Logging

Now that we have good GPS data, the final step is to start logging it to a µSD card.

Like the last example, this sketch uses TinyGPS++, it also uses Arduino’s built-in SD library.

The code is hosted on codebender and embedded below. If the embed below doesn’t load for you, check out the example code in our GitHub repository.

You may need to edit the gpsPort and SerialMonitor objects, toward the top of the code to get the example to work correctly on your Arduino. The sketch defaults to using SoftwareSerial for the GPS, which should work for most boards – as long as the UART-Select switch is shifted towards SW-UART.

Before uploading the code, plug a µSD card into your GPS Logger Shield. Push it in gently until you hear a click. Then release, and let it latch into place.

uSD card plugged into the shield

Once that’s in place, upload and run! You can check the serial monitor for debugging data, or just trust that the logger is logging.

Once the GPS module gets a good fix, the Arduino will start logging longitude, latitude, altitude, speed, course, date, time, and the number of visible satellites into a CSV file. The data is set to log once every five seconds, but that’s easily tunable if you need more or less data.

After letting it log for a bit, turn off your Arduino, load the SD card into your computer, and check for a GPSLOG###.CSV file. Open it up in a spreadsheet program, or just use a text editor to see what your Arduino logged.

CSV example screenshot

Now really test the logger! Power your Arduino up with a battery (our 9V to Barrel Jack Adapter is handy for that)…

Battery-powered Arduino/GPS Shield

…and take your Arduino for a walk.

Resources & Going Further

Now that you’ve got your GPS Logger Shield up-and-running, what kind of position-tracking Arduino project are you going to make. Need a little more guidance, here are a few links you may find handy:

If you need a little project inspiration, here’s a SparkFun Live, where you can watch the full build of a GPS Speedometer:

Or check out some of these related SparkFun tutorials:

Copernicus II Hookup Guide

A guide for how to get started with the Copernicus II GPS module.

Weather Shield Hookup Guide

Read humidity, pressure and luminosity quickly and easily. Add wind speed, direction and rain gauge for full weather station capabilities.

Alphanumeric GPS Wall Clock

This is a GPS controlled clock - a clock you truly never have to set! Using GPS and some formulas, we figure out what day of the week and if we are in or out of daylight savings time.

CAN-Bus Shield Hookup Guide

A basic introduction to working with the CAN-Bus shield.

learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado


Viewing all articles
Browse latest Browse all 1123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>