Let's Make Robots!

GPS - The Complete Guide - Arduino based Global Positioning System


GPS:- The Complete Guide to Global Positioning Systems.

Blogged Here :- Guide to Global Positioning Systems.  

Check also:- Fundamentals of a GPS guided vehicle ( patrickmccabe)

How they Work and How to interface them into your Robot.

Does your Robot need to fix its absolute Position - Speed - Heading - Time - Date & Altitude.


Here is a Guide to explain the Process.


GPS satellites (presently totalling 31) orbit the Earth at an approx. altitude of 20,000Km.

For a GPS unit to fix its location it needs to receive at least 3 satellites

The GPS signal that is transmitted from each satellite contains:-


Time.        down to the millisecond range (GMT-referenced).
Position.   accuracy 2 to 3 meters.
Altitute.
Date.

From this information it is also possible to work out Compass Heading and Speed.

 

 


What follows below is an Arduino based system that i can Highly recommend.

It is very easy to interface into projects.

It is a compact robust system and very reliable.


I will be using a GPS Shield using the USGlobalSat EM-406A receiver

This Shield has also a data logging facility that saves to an SD card .

 


 This walk through is in three parts :-


 Part 1 :- using a serial port to retrieve data from a GPS unit


Setting up the basic system - (i included the first part because it is possible to talk directly to the GPS via its serial port just by connecting a FTDI cable direct to the GPS sheild board .)

 

So for the first part we will be using just the serial port of the Arduino as an example.

Remove the ATMEGA chip on the Arduino Board (we only need the serial circuit on the Arduino).

place a jumper cable between digital i/o pin 2 and ground (as Shown Below).

this switches the GPS Unit on and you can use the Arduinos serial port to read the data.

 

 

Then wire the  GPS unit so:-

GPS RX to digital pin 0
GPS TX to digital pin 1
GPS PWR to digital 2

The GPS unit can be attached to the Arduino and the USB connected.
Select the Arduinos Serial Port and adjust the speed to 4800 Baud.


The resulting output stream looks a bit like this:-
------------------------------------------------------------------------------------------------
$GPRMC,150135.000,A,4725.0890,N,00922.8760,E,0.06,198.98,190309,,*00
$GPGGA,150136.000,4725.0890,N,00922.8758,E,1,04,3.0,766.6,M,48.0,M,,0000*58
$GPGSA,A,3,13,25,23,20,,,,,,,,,3.2,3.0,1.0*37
$GPRMC,150136.000,A,4725.0890,N,00922.8758,E,0.05,195.81,190309,,*0E
$GPGGA,150137.000,4725.0891,N,00922.8757,E,1,04,3.0,766.4,M,48.0,M,,0000*55
$GPGSA,A,3,13,25,23,20,,,,,,,,,3.2,3.0,1.0*37
$GPRMC,150137.000,A,4725.0891,N,00922.8757,E,0.07,208.54,190309,,*0C
$GPGGA,150138.000,4725.0892,N,00922.8755,E,1,04,3.0,766.3,M,48.0,M,,0000*5C
$GPGSA,A,3,13,25,23,20,,,,,,,,,3.2,3.0,1.0*37
$GPRMC,150138.000,A,4725.0892,N,00922.8755,E,0.04,197.77,190309,,*05
$GPGGA,150139.000,4725.0892,N,00922.8755,E,1,04,3.0,766.2,M,48.0,M,,0000*5C
$GPGSA,A,3,13,25,23,20,,,,,,,,,3.2,3.0,1.0*37
$GPRMC,150139.000,A,4725.0892,N,00922.8755,E,0.05,178.49,190309,,*09
-------------------------------------------------------------------------------------------------

Lets break it down the last Bold Line
$GP ----- Geographic Position
RM ------- Reccomended Minimum
150139.000 -------- Time 15:01 and remainder in milliseconds
A --------- Active (else could be V for Void)
4725.0892,N ------ Position Latitude 47 Deg 25.0892 Minutes North
00922.8755,E ------Position Longitude 009 Deg 22.8755 Minutes East
190309 --------- Date 19th march 2009
*09 ------ Checksum


$GPGSA string contain information about quality of signal
$GPGGA string contains location - quality of signal - and amazingly Altitute information

 

 

 

 


Part 2 :- How can we make use of this information by using an Arduino Script.


Remove the Jumper off the Arduino and Plug the ATMEGA chip back in and install the GPStest_RMC.pde script.

 

Dont forget to install a AFSoftSerial.h library into the Hardware/Libraries

 


Then wire the  GPS unit so (picture above) :-

GPS RX to digital pin 3
GPS TX to digital pin 2
GPS PWR to digital 4



Open up the Arduinos Serial Port and set to 4800 Baud

The resulting output stream looks a bit like this:-
-------------------------------------------------------------------------------------------------
read:
$GPGGA,152635.000,4725.0900,N,00922.9192,E,1,05,3.9,809.1,M,48.0,M,,0000*5E
read:
$GPGSA,A,3,13,23,16,25,07,,,,,,,,5.1,3.9,3.4*3F
read:
$GPGSV,3,1,11,07,69,140,36,25,65,075,43,13,54,059,44,02,42,264,*79
read:
$GPGSV,3,2,11,23,24,073,46,16,10,034,30,20,01,128,,08,38,193,21*78
read:
$GPGSV,3,3,11,04,34,211,28,10,22,304,15,29,01,332,*48
read:
$GPRMC,152635.000,A,4725.0900,N,00922.9192,E,0.21,257.90,190309,,*0A
Time: 15:26:35
Date: 3/19/9
Lat: +470 25' 5.40"
Long: +90 22' 55.15"

--------------------------------------------------------------------------------------------------

If you notice the Arduino has extracted the data (in Bold) into variables which can be used in your normal programming.

Its as simple as that.


Part 3:- Third party Software.


With the Arduino Set up this way you can attach many third party GPS software packages.
Here is a free-ware version called mini GPS.

 

If you take a close look the Altitude - Speed - and Track (heading) are also calculated.

 

 

 and here is another

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
flokos's picture

Hey Gareth I tried it outside at 9600 baudrate but nothing happens .

Here is what the log says:

³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ίp;³(T%²+V%²+T)ΆΆK—΅ΡšΊ·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ίp;³(T%²+V%²+T)ΆΆK—΅ΡšΊ·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ίp;³(T%²+V%²+T)ΆΆK—΅ΡšΊ·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ίp;³(T%²+V%²+T)ΆΆK—΅ΡšΊ·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ίp;³(T%²+V%²+T)ΆΆK—΅ΡšΊ·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ίp;³(T%²+V%²+T)ΆΆK—΅ΡšΊ·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σtΉ‹(”)Q•ŠT)Q•Š”¥JE”©ΆJT?ΆKT)]•κT7ΆΆ»V!՚Ί·³J”)]¥ΚQ)Q•Š”¥JE”©ΆJT?ΆΆ*T)Ω­•%²•§ΆδQ©Ά*P%ΆΆ*S©Ά*S³:σ$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

$GPGGA,000000.000,0000.0000,S,00000.0000,W,0,00,00.0,0.0,M,0.0,M,,*52

$GPRMC,000000.000,V,0000.0000,S,00000.0000,W,0.00,0.00,110732,,,A*70

$GPVTG,0.00,T,,,0.00,N,0.00,K,A*70

Gareth's picture

Flokos your data is almost there.........

Forget the first half of the data ...... this i suspect to be a loose wire.

Second half of the data proves that the GPS is half working .... ie the GPS housekeeping.

It looks like it is not getting a fix from enough satellites......

If you have one of the 406S modules then on power-up there is a red led that is permanently on. The data coming out will look exactly like your last data...... the one with all the 00000.00 .etcetc.

Then "after a while" ....when enough satellites have been detected the red led will blink at 1 second intervals and the GPS will spit out actual coordinate data.

......Re:- "after a while"..... this process can take from 1 minute to even 10 minutes ...... however once it is synchronised the data updates very fast........(even my car gps can take this amount of time)......sometimes its less than a minute (all depends on number and type of saterlites)

 

So a few things to check:-

Check for good sound connections .... and short serial leads to GPS unit

Set the baudrate lower - mine is set to 4800baud for reliable data.

Most important ..Place it in total open blue sky - well away from buildings.

and Give it at least 10-15minutes and recheck data.

flokos's picture
Gareth's picture

My first idea after seeing the pdf is to check this pin........

GPIO [4] ...........It will be pulled low when the first satellite is acquired.

This will be a good indication that it can see a satellite.

Also caution ...... this is a 3.3volt device so logic levels are not Arduino prepared.

flokos's picture

but arduino  has a 3.3v supply .

 

Gareth's picture

Yes the arduinos 3.3 Volt is perfect for the module.

flokos's picture

I think that it has to do with the antenna some string of the antennas wire were cut and I added some solder to fix it.

Could this be the problem?

Gareth's picture

.... ahha i just noticed it has an external antenna ..... check ...or better still resolder the antenna connections making sure that the outer braid and inner wire are not shorted.....

NB. normally Antenna cable has an impedence matched to the internal receiver... ie so extra wire in addition to the antenna cable can cause problems.

flokos's picture

I resoldered the antenna but still no improvement inside ,though I cant test it outside now because its raining.

flokos's picture

Can i connect a gps module and a xbee module simultaneously to my arduino ?

Because i saw that both of them use the rx and tx pins .

Is that possible?