Professional Documents
Culture Documents
GPS Shield: Arduino
GPS Shield: Arduino
GPS is a powerful tool that can be fun and easy to use with the help
of Arduino. Projects ranging from logging a trip in your car, all the way
to navigating autonomously are all possible with GPS.
This quickstart guide will tell you everything you need to know about
how to get time and position data with a GPS module. All you need is
a GPS module, the GPS Shield, and an Arduino.
What do you do with GPS?
We all know GPS can show your immediate location, similar to what
you would find in a hand held unit or automobile console. GPS is also
good for everything from tracking and logging, extremely accurate
time keeping, to autonomous navigation and geocaching. These
types of applications rely on more than just simple latitude and
longitude, but elevation, time, heading, ground speed, and signal
strength from the satellites. This guide will show you how to get
started writing code that will parse or pick out meaningful information
from the data that comes out of the TX pin on a GPS module.
For a detailed explanation on how GPS works, please refer to the
GPS Tracking Comparisons Tutorial.
Where to start?
The first thing you want to do is assemble the GPS shield as shown
above. See the GPS Shield Assembly Guide for detailed assembly
instructions.
• GPS Shield Assembly Guide
Next, choose a GPS module that will work with the GPS Shield (see
the product page for compatible GPS modules). The GPS Shield has
a connector for an EM-406, so the EM-406 is the easiest option to get
moving.
Here are the configuration options for the GPS Shield.
There are two slide switches, one push button switch, and two solder
jumpers on the GPS Shield as shown above.
Here is what it looks like after the GPS has sat for about a minute:
If you see this, your GPS has a valid lock.
No, I am not moving at 5km per hour, I am just inside an office
building and not moving. It's sometimes hard for GPS to know if you
are completely still, especially if you are inside.
Main loop
The main loop constantly runs as long as your Arduino is powered.
Here is where we want to check to see if there is any serial data
coming out of the GPS, check to see if that data is valid, and if so,
jump to the getgps function and print the data we want.
while(uart_gps.available())
{
int c = uart_gps.read();
if(gps.encode(c))
{
getgps(gps);
}
}
Here is the step through: While there is data on the RX pin,
nss.available() is TRUE, so jump into the while loop and read one
byte off of the RX pin with nss.read() and load it into variable 'c'. Then
check to see if variable 'c' is a finish to a new valid GPS NMEA
sentence with gps.encode(c). If there is a new valid sentence,
gps.encode(c) is TRUE and we jump into getgps(gps).
GetGPS function
The GetGPS function simply calls the TinyGPS functions which
automatically load the data into variables then prints them out in a
readable format.
To get latitude and longitude you need to define variables and call the
TinyGPS function responsible for grabing that data.
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
Why float and not int or byte?Think about the data you want and if
that data will need to have fractional precision. In other words, will the
values be whole numbers, like the day or month, or will the values be
decimals, like latitude or elevation (i.e. 40.06477 N)? If you want to
print decimal numbers you will need to define float variables.
Serial.print(latitude, 5);
Serial.print(longitude, 5);
This will print the latitude and longitude with 5 decimal precision,
which looks like: 40.06477.
If the data you want is a whole number, you need to define them as
either int or byte. However, if using the crack_datetime function, you
need to define the variables in exactly this way.
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year, &month, &day, &hour, &minute,
&second, &hundredths);