Gps Data Receiver

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

GPS Receiver

Build and program your own GPS receiver. Contents


Overview Challenge 1: Understanding GPS Data o Collecting our Components o Connecting the !eceiver to our Computer o Setting up a "erminal #mulator o Understanding GPS Data Challenge $: Controlling the !eceiver o Collecting our Components o Connecting the !eceiver to the Chip o Displaying !aw GPS Data on the %CD o Parsing the !aw GPS Data o Selecting GPS Output Streams o Displaying Speci&ic GPS Data #lements o 'ormatting GPS Data on "wo %ines

Overview (n this pro)ect* you will +uild an inter&ace to the Glo+alSat #,-./01 GPS !eceiver. "he #,-./01 is a $/-channel GPS receiver +ased on the Si!' Star((( chipset* and it &eatures a +uilt-in antenna. 1&ter +uilding the inter&ace circuit* you will learn how to customi2e it to display more than 3/ standard GPS data types* including latitude* longitude* altitude* velocity* heading* time* and date.

Figure 1. GlobalSat EM-406 GPS Receiver.

%i4e most GPS receivers* the #,-./01 con&orms to the standard 5#,1 Si!' inter&ace protocol* so the code you write in this pro)ect will wor4 with most other GPS receivers. C!allenge 1" #n$erstan$ing GPS %ata (n order to +etter understand the GPS data &ormat* you will &irst connect your GPS receiver directly to your computer through the ,achine Science programming ca+le. GPS receivers are capa+le o& transmitting a large volume o& data* which can +e di&&icult to see on a small %CD screen. By viewing the data on a computer monitor* you will +e a+le to learn a+out the di&&erent GPS data streams and data types.

Collecting &our Co'(onents (n order to connect your GPS receiver to your computer* you will need the &ollowing components: Part 1 B C D )uantit* 1 1 1 1 %escri(tion Glo+alSat #,-./01 GPS #ngine Connector harness 60-pin7 Bent header 60-pin7 Bent header 6.-pin7

Connecting t!e Receiver to &our Co'(uter Using 'igure $ as a guide* connect the GPS receiver to the programming +oard* which will lin4 it to your computer. "o avoid inte&ering with the microcontroller* +uild this circuit in an area o& the +oard away &rom the chip. 'igure 3 shows one way to lay out this circuit. "o orient the GPS unit properly* note the position o& the grey wire in 'igure 3.

Figure +. Connecting t!e GPS receiver to t!e co'(uter ,sc!e'atic-.

Figure .. Connecting t!e GPS receiver to t!e co'(uter ,(!oto-.

Setting u( a /er'inal E'ulator Connected as shown in 'igure $* the GPS receiver will send satellite data to your computer8s CO, port. "o view the data* you will need to run a terminal emulator--a program that emulates an older-style te9t-only computer terminal. Depending on your operating system* your computer may already have a terminal emulator* or you may need to download one &rom the (nternet:

:indows 6;ista7: "era"erm Pro :e+ is availa+le here: http:<<www.ayera.com<teraterm< :indows 6pre-;ista7: =yper"erminal is availa+le in the Start menu under Programs > 1ccessories > Communication.

,acintosh: ?"erm comes pre-installed with OS@ and a+ove. %inu9: CuteCom can +e &ound at: http:<<cutecom.source&orge.net<

"he instructions in this section are &or installing "era"erm Pro :e+* +ut should give you enough in&ormation to help you set up any o& the other programs listed a+ove. 1. Determine which CO, port your ,achine Science programming +oard is using +y viewing the Options menu in the Programming :indow. $. Download "era"erm Pro :e+ &rom http:<<www.ayera.com<teraterm< 3. Un2ip the .2ip &ile to a convenient location on your hard drive. .. Open the &older and dou+le clic4 on the &ile ttermpro.e9e. ou will see a dialog +o9 li4e the one shown in 'igure ..

Figure 4. 0ew connection $ialog bo1.

A. Select Serial and the CO, port +eing used +y your ,achine Science programming +oard. ou should now see unintelligi+le characters scrolling across and down your screen as shown in 'igure A.

Figure 2. /era/er' 3in$ow.

0. "he reason you see a )um+le o& characters is that you need to set the +aud rate in +aud rate in your terminal program to match the +aud rate o& the GPS receiver. Select BSerial port...C &rom the Setup menu. ou should now see a dialog +o9 li4e the one shown in 'igure 0.

Figure 6. Serial (ort setu(.

D. Select .E// &or the +aud rate. ou should now see lines o& GPS data +eing updated every second on your screen* as shown in 'igure D.

Figure 4. /er'inal e'ulator. #n$erstan$ing GPS %ata GPS receivers are capa+le o& transmitting eight types o& GPS data streams* shown +elow: O(tion GG1 G%% GS1 GS; ,SS !,C ;"G ?D1 %escri(tion "ime and position data %atitude* longitude* time and status GPS receiver operating mode* satellites used in the position solution* and DOP values "he num+er o& GPS satellites in view* satellite (D num+ers* elevation* and a2imuth Signal-to-noise ratio* signal strength* &reFuency* and +it rate &rom a radio-+eacon* receiver "ime* date* position* course and speed data Course and speed in&ormation relative to the ground Pulse Per Second 6PPS7 timing message

!e&erring to 'igure D 6or your terminal emulator* i& it is still running on your computer7* you should see &our types o& GPS data streams: GG1* !,C* GS;* and GS1. "hese are the &our de&ault data streams that are transmitted +y the GPS receiver. #ach stream is transmitted on a single line. 1n e9ample o& a GG1 data stream is shown +elow. GGPGG1*101$$H..ED*3D$3.$.DA*5*1$1AE.3.10*:*1*/D*1./*H./*,* * * *////I1E

#ach GPS data stream can have up to si9teen GPS data &ields. "he data &ields are separated +y commas* as shown in the sample a+ove. "a+le 3 +elow details the data &ields contained in the GG1 data stream. 0a'e ,essage (D U"C "ime %atitude 5<S (ndicator %ongitude #<: (ndicator Position 'i9 (ndicator Satellites Used =DOP ,S% 1ltitude Units Geoid Separation Units 1ge o& Di&&. Corr. Di&&. !e&. Station (D Chec4sum KC!>K%'> E1a'(le GGPGG1 101$$H..ED 3D$3.$.D. 5 1$1AE.3.10 : 1 /D 1./ H./ , %escri(tion GG1 protocol header hhmmss.sss 6hJhours* mJminutes* sJseconds7 ddm.mmmm 6dJdegrees* mJminutes7 5Jnorth or SJsouth dddmm.mmmm 6dJdegrees* mJminutes7 #Jeast or :Jwest /J&i9 not valid* 1*$* or 3J &i9 valid !ange / to 1$ =ori2ontal dilution o& precision ,eters a+ove sea level ,eters ,eters ,eters Seconds Chec4 &or valid data Carriage return and line &eed indicating end o& message

//// I1E

DonLt worry a+out understanding all o& the GPS data types shown in this ta+le. "he ones o& greatest interest to you will pro+a+ly +e time* latitude* longitude* and altitude. (n the ne9t challenge* you will learn how to display this in&ormation in a meaning&ul way on your %CD. C!allenge +" Controlling t!e Receiver (n this challenge* you will construct a circuit connecting the #,-./01 to the 1tmega Board and program the chip to display reada+le GPS data on the %CD.

Collecting &our Co'(onents (n order to +uild the circuit* you will need the &ollowing components: Part 1 B C D )uantit* 1 1 1 1 %escri(tion Glo+alSat #,-./01 Connector harness 60-pin7 Bent header 60-pin7 1tmega Board

Connecting t!e Receiver to t!e C!i( Using the schematic in 'igure E as a guide* add your components to the +read+oard. 'igure H shows an e9ample o& a completed +oard &or this circuit. Since the leads on the GPS receiver are not la+eled* you may need to e9amine the picture to ma4e the correct connections.

Figure 5. Connecting GPS receiver to t!e t'ega165 ,sc!e'atic-.

Figure 6. Connecting GPS receiver to t!e t'ega165 ,(!oto-. %is(la*ing Raw GPS %ata on t!e 7C% "he &ollowing code will allow you to +egin receiving data &rom your GPS receiver and displaying the in&ormation on your %CD. (n this &irst step* you will not +e parsing the data &rom your receiver. 1s you learned in the previous challenge* GPS receivers can produce a lot o& data* so your tiny %CD will Fuic4ly &ill up with a lot o& num+ers* letters* and sym+ols. :hile you will not +e a+le to read the data* it will indicate that your circuit is wor4ing properly. 6(t also loo4s 4ind o& coolM7 (,PO!"15" 5O"#: "he GPS receiver and the ,achine Science programming +oard +oth use the same pin &or transmitting data to the 1tmega10E. ou must disconnect the wire lin4ing the GPS pin . to the Port D/ o& the 1tmega10E +e&ore downloading your code. ou can immediately reconnect this wire once the code has +een downloaded. 1. #include "mxapi.h" $. #include "usart.h" 3. #include "lcd.h"

4.
A. int main (void) 0. { D. char gps_characters; //Declare a variable

storing !"# characters

or

usart_init(4$%%); //&nitiali'e the (#)*+ to 4$%% baud H. lcd_init(); //&nitiali'e ,our -.D 1/. /hile(0110) //#tart an in inite loop 11. { 1$. gps_characters1usart_read(); //*ead each character rom the !"# 13. lcd_character(gps_characters); //Displa, each character on the -.D 1.. 2 1A. 2
E. Parsing t!e Raw GPS %ata (n order to +etter view the data on your %CD* you will need to parse the raw data stream &rom the GPS receiver. (n 'igure D* you can see that the terminal emulator on your computer displays each data stream on a separate line. (t does this +y chec4ing &or a carriage return and line &eed* the 1SC(( characters 13 and 1/* at the end o& each data stream 6as shown in the last rows o& "a+le 37. :hen the terminal emulator &inds these two characters* it starts the ne9t data set on a new line* ma4ing the data much easier to read than i& it were simply a continuous stream. "he microcontroller has no +uilt-in a+ility to parse data. 1s you may have seen in the previous e9ercise* the carriage return and line &eeds at the end o& each data string are displayed on the %CD as more data. 1s a result* using the previous code* the GPS data was displayed on the %CD in long stream without easily discerni+le +rea4s. "he ne9t code sample introduces +rea4s a&ter each line o& data* )ust li4e the terminal emulator did. (t chec4s continuously &or a line &eed character 61SC(( 1/7* and when it gets one* it repositions %CDLs cursor at the start o& the &irst line +e&ore displaying the ne9t character. "he data on the display remains somewhat di&&icult to read* since all o& the di&&erent GPS data streams are displayed* +ut it is easier to pic4 out patterns in the data. 1. #include "mxapi.h" $. #include "usart.h" 3. #include "lcd.h"

4.
A. int main (void)

3. {
D.

char gps_characters; //Declare a variable to store !"# characters E. usart_init(4$%%); //&nitiali'e the (#)*+ to 4$%% baud H. lcd_init(); //&nitiali'e the -.D 1/. /hile(0110) //#tart an in inite loop

11. 1$.

gps_characters 1 usart_read(); //*ead each character rom the !"# 13. lcd_character(gps_characters); //Displa, each character on the -.D 1.. i (gps_characters 11 0%) //.hec4 or the line eed ()#.&& 0%) character 1A. { 10. lcd_instruction( 5&*#+_-&67 ); //8ove the cursor to the irst line 1D. 2 1E. 2 1H. 2
Programming Challenge ,odi&y your code so that each line new line scrolls up in the same way that it displays on your computer monitor. "his is di&&icultM Selecting GPS Out(ut Strea's "he &ollowing code turns on and o&& speci&ic GPS data streams. !emem+er that the receiver is capa+le o& transmitting any or all o& the eight di&&erent GPS streams listed in "a+le $ at a rate o& up to 1// =ert2 each. (n order to display the data on the %CD* it is +est to turn on only one stream and turn o&& the rest* using a &unction called gpsNsetdata. "his &unction ta4es two arguments: the &irst argument selects the GPS stream that you want to turn on or o&&O the second argument determines how &reFuently 6in =ert27 the GPS receiver transmits the stream. 1 value o& / turns o&& the stream entirely* while a value o& 1 to HH speci&ies a transmission &reFuency o& 1 to HH times a second. 1. $. 3. ..

9.
E.

#include #include #include #include

"mxapi.h" "usart.h" "lcd.h" "gps.h"

0. int main (void)

:. { char gps_characters; //Declare a variable to store !"# character H. usart_init(4$%%); //&nitiali'e the (#)*+ to 4$%% baud 1/. lcd_init(); //&nitiali'e the -.D 11. dela,_ms(;%%%); //Dela, /hile !"# receiver /arms up 0;.

/< +urn o all 687) ormats except the one ,ou /ant to see. </ 1.. gps_setdata(687)_!!)= 0); //+urn on !!) ormat at 0 >ert' 1A. gps_setdata(687)_!#)= %); //+urn o !#) ormat (% >ert') 10. gps_setdata(687)_!#?= %); //+urn o !#? ormat (% >ert') 1D. gps_setdata(687)_*8.= %); //+urn o *8. ormat (% >ert') 1E. /hile(0110) //*un the ollo/ing code in an in inite loop 1H. { $/. gps_characters 1 usart_read(); //*ead each character rom the !"# $1. lcd_character(gps_characters); //Displa, each character on the -.D $$. i (gps_characters110%) //.hec4 or the line eed ()#.&& 0%) character $3. { $.. lcd_instruction(5&*#+_-&67); //8ove the cursor to the irst line $A. 2 $0. 2 $D. 2
13.

ou do not need to select a GPS data stream every time you program the device. Once a stream is selected* the receiver displays only that stream until the gpsNsetdata &unction is called again. Programming Challenge "ry changing the GPS stream displayed +y your GPS receiver. "ry changing how o&ten the GPS stream is updated. %is(la*ing S(eci8ic GPS %ata Ele'ents :ith the &ollowing code* you can display speci&ic GPS data elements* such as time* latitude* longitude* and altitude* &rom the selected data stream. "o simpli&y matters* every GPS data stream is parsed in the +ac4ground +y a &unction within the Bgps.hC header &ile. "he parsed data is stored in an array called gpsNdataP Q* with each value in the array representing a di&&erent GPS data element. ou can re&erence any element in the gpsNdataP Q array in your code.

'or e9ample* with the GG1 data stream* selected a line o& data might loo4 li4e this: GGPGG1*101$$H..ED*3D$3.$.DA*5*1$1AE.3.10*:*1*/D*1./*H./*,* * * *////I1E (n this instance* gpsNdataP/Q would eFual GGPGG1* gpsNdataP1Q would eFual 101$$H..ED* gpsNdataP$Q would eFual 5* and so on. "he &ollowing ta+le shows the gpsNdataPQ values &or some o& the more use&ul data elements in the GG1* !,C* and ;"C data streams. GPS %ata E1a'(le ,essage (D GGPGG1 %atitude 3D$3.$.DA #nits Degrees and minutes For'at ddmm.mmmm GG / $ R9C / 3 :/G /

5orth<South 5 %ongitude 1$1AE.3.10 Degrees dddmm.mmmm and minutes #ast<:est : 1ltitude H./ ,eters Speed /.$ Rilometers < hour Course 3/H.0$ Degrees "ime 101$$H..ED hhmmss.ss Date 1$/AHE ddmmyy Satellites /D / to 1$

3 .

. A

A H

0 D E 1 H 1

1 D

"his program uses the chipLs internal interrupts* which allow the microcontroller to e9ecute multiple tas4s at the same time. 1 &ew new statements are added to ena+le and initiali2e the interrupts. 1. $. 3. ..

#include #include #include #include

"mxapi.h" "usart.h" "lcd.h" "gps.h"

9.
0. int main (void)

:. {
E.

usart_init(4$%%); 4$%% baud

//&nitiali'e the (#)*+ to

usart_interrupt_rx(76)@-7); //7nable interrupts or the (#)*+ 1/. sei(); //+urn on interrupts 11. lcd_init(); //&nitiali'e the -.D 0;. 13. /hile(0110) //#tart an in inite loop 1.. { 1A. lcd_instruction(5&*#+_-&67); //8ove the cursor to the irst line 10. lcd_instruction(.-7)*); //.lear the -.D 1D. lcd_text(gps_dataA;B); //Displa, the Crd value in the selected data stream 1E. 2 1H. 2
H. For'atting GPS %ata on /wo 7ines "he last code e9ample in this pro)ect will display and &ormat multiple GPS data &ields on +oth lines o& the %CD. "he added &unctions in this e9ample should +e &amiliar to you &rom other ,achine Science pro)ects. 1. $. 3. ..

9.
E.

#include #include #include #include

"mxapi.h" "usart.h" "lcd.h" "gps.h"

0. int main (void)

:. { usart_init(4$%%); //&nitiali'e the )tmega03$s (#)*+ to 4$%% baud H. usart_interrupt_rx(76)@-7); //7nable interrupts or the (#)*+ 1/. sei(); //+urn on interrupts 11. lcd_init(); //&nitiali'e ,our -.D 0;. 13. /hile(0) //*un the ollo/ing code in an in inite loop 1.. { 1A. lcd_instruction(5&*#+_-&67); //8ove the cursor to the irst line 10. lcd_text(gps_dataA;B); //Displa, value o third data ield 1D. lcd_character(DED); //Displa, DED character

1E.

0F.
$/.

lcd_text(gps_dataACB); ourth data ield

//Displa, value o

lcd_instruction(#7.G6D_-&67); //8ove the curse to the irst line $1. lcd_text(gps_dataA4B); //Displa, value o i th data ield $$. lcd_character(DED); //Displa, DED character $3. lcd_text(gps_dataA9B); //Displa, value o sixth data ield $.. lcd@lan4-ine(); //#end blan4s to clear the lines $A. 2 $0. 2

You might also like