Escolar Documentos
Profissional Documentos
Cultura Documentos
Contents
• Overview
• Challenge 1: Understanding GPS Data
o Collecting Your Components
o Connecting the Receiver to Your Computer
o Setting up a Terminal Emulator
o Understanding GPS Data
• Challenge 2: Controlling the Receiver
o Collecting Your Components
o Connecting the Receiver to the Chip
o Displaying Raw GPS Data on the LCD
o Parsing the Raw GPS Data
o Selecting GPS Output Streams
o Displaying Specific GPS Data Elements
o Formatting GPS Data on Two Lines
Overview
In this project, you will build an interface to the GlobalSat EM-406A GPS Receiver. The
EM-406A is a 20-channel GPS receiver based on the SiRF StarIII chipset, and it features
a built-in antenna. After building the interface circuit, you will learn how to customize it
to display more than 30 standard GPS data types, including latitude, longitude, altitude,
velocity, heading, time, and date.
In order to better understand the GPS data format, you will first connect your GPS
receiver directly to your computer through the Machine Science
programming cable. GPS receivers are capable of transmitting a large
volume of data, which can be difficult to see on a small LCD screen. By
viewing the data on a computer monitor, you will be able to learn about the
different GPS data streams and data types.
In order to connect your GPS receiver to your computer, you will need the following
components:
Using Figure 2 as a guide, connect the GPS receiver to the programming board, which
will link it to your computer. To avoid intefering with the microcontroller, build this
circuit in an area of the board away from the chip. Figure 3 shows one way to lay out this
circuit. To orient the GPS unit properly, note the position of the grey wire in Figure 3.
Figure 2. Connecting the GPS receiver to the computer (schematic).
The instructions in this section are for installing TeraTerm Pro Web, but should give you
enough information to help you set up any of the other programs listed above.
1. Determine which COM port your Machine Science programming board is using
by viewing the Options menu in the Programming Window.
2. Download TeraTerm Pro Web from http://www.ayera.com/teraterm/
3. Unzip the .zip file to a convenient location on your hard drive.
4. Open the folder and double click on the file ttermpro.exe. You will see a dialog
box like the one shown in Figure 4.
5. Select Serial and the COM port being used by your Machine Science
programming board. You should now see unintelligible characters scrolling across
and down your screen as shown in Figure 5.
Figure 5. TeraTerm Window.
6. The reason you see a jumble of characters is that you need to set the baud rate in
baud rate in your terminal program to match the baud rate of the GPS receiver.
Select “Serial port...” from the Setup menu. You should now see a dialog box like
the one shown in Figure 6.
7. Select 4800 for the baud rate. You should now see lines of GPS data being
updated every second on your screen, as shown in Figure 7.
Figure 7. Terminal emulator.
Option Description
GGA Time and position data
GLL Latitude, longitude, time and status
GSA GPS receiver operating mode, satellites used in the position solution,
and DOP values
GSV The number of GPS satellites in view, satellite ID numbers, elevation,
and azimuth
MSS Signal-to-noise ratio, signal strength, frequency, and bit rate from a
radio-beacon, receiver
RMC Time, date, position, course and speed data
VTG Course and speed information relative to the ground
ZDA Pulse Per Second (PPS) timing message
Referring to Figure 7 (or your terminal emulator, if it is still running on your computer),
you should see four types of GPS data streams: GGA, RMC, GSV, and GSA. These are
the four default data streams that are transmitted by the GPS receiver. Each stream is
transmitted on a single line. An example of a GGA data stream is shown below.
$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
Each GPS data stream can have up to sixteen GPS data fields. The data fields are
separated by commas, as shown in the sample above. Table 3 below details the data fields
contained in the GGA data stream.
Don't worry about understanding all of the GPS data types shown in this table. The ones
of greatest interest to you will probably be time, latitude, longitude, and altitude. In the
next challenge, you will learn how to display this information in a meaningful way on
your LCD.
IMPORTANT NOTE: The GPS receiver and the Machine Science programming board
both use the same pin for transmitting data to the Atmega168. You must disconnect the
wire linking the GPS pin 4 to the Port D0 of the Atmega168 before downloading your
code. You can immediately reconnect this wire once the code has been downloaded.
1. #include "mxapi.h"
2. #include "usart.h"
3. #include "lcd.h"
4.
5. int main (void)
6. {
7. char gps_characters; //Declare a variable for
storing GPS characters
8. usart_init(4800); //Initialize the USART to
4800 baud
9. lcd_init(); //Initialize your LCD
10. while(1==1) //Start an infinite loop
11. {
12. gps_characters=usart_read(); //Read each
character from the GPS
13. lcd_character(gps_characters); //Display
each character on the LCD
14. }
15. }
The microcontroller has no built-in ability to parse data. As you may have seen in the
previous exercise, the carriage return and line feeds at the end of each data string are
displayed on the LCD as more data. As a result, using the previous code, the GPS data
was displayed on the LCD in long stream without easily discernible breaks.
The next code sample introduces breaks after each line of data, just like the terminal
emulator did. It checks continuously for a line feed character (ASCII 10), and when it
gets one, it repositions LCD's cursor at the start of the first line before displaying the next
character. The data on the display remains somewhat difficult to read, since all of the
different GPS data streams are displayed, but it is easier to pick out patterns in the data.
1. #include "mxapi.h"
2. #include "usart.h"
3. #include "lcd.h"
4.
5. int main (void)
6. {
7. char gps_characters; //Declare a variable to
store GPS characters
8. usart_init(4800); //Initialize the USART to
4800 baud
9. lcd_init(); //Initialize the LCD
10. while(1==1) //Start an infinite loop
11. {
12. gps_characters = usart_read(); //Read
each character from the GPS
13. lcd_character(gps_characters); //Display
each character on the LCD
14. if (gps_characters == 10) //Check for the
line feed (ASCII 10) character
15. {
16. lcd_instruction( FIRST_LINE ); //Move
the cursor to the first line
17. }
18. }
19. }
Programming Challenge
Modify your code so that each line new line scrolls up in the same way that it displays on
your computer monitor. This is difficult!
1. #include "mxapi.h"
2. #include "usart.h"
3. #include "lcd.h"
4. #include "gps.h"
5.
6. int main (void)
7. {
8. char gps_characters; //Declare a variable to
store GPS character
9. usart_init(4800); //Initialize the USART to
4800 baud
10. lcd_init(); //Initialize the LCD
11. delay_ms(2000); //Delay while GPS receiver
warms up
12.
13. /* Turn off all NMEA formats except the one
you want to see. */
14. gps_setdata(NMEA_GGA, 1); //Turn on GGA
format at 1 Hertz
15. gps_setdata(NMEA_GSA, 0); //Turn off GSA
format (0 Hertz)
16. gps_setdata(NMEA_GSV, 0); //Turn off GSV
format (0 Hertz)
17. gps_setdata(NMEA_RMC, 0); //Turn off RMC
format (0 Hertz)
18. while(1==1) //Run the following code in an
infinite loop
19. {
20. gps_characters = usart_read(); //Read
each character from the GPS
21. lcd_character(gps_characters); //Display
each character on the LCD
22. if (gps_characters==10) //Check for the
line feed (ASCII 10) character
23. {
24. lcd_instruction(FIRST_LINE); //Move the
cursor to the first line
25. }
26. }
27. }
You 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 gps_setdata function is
called again.
Programming Challenge
Try changing the GPS stream displayed by your GPS receiver. Try changing how often
the GPS stream is updated.
$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
The following table shows the gps_data[] values for some of the more useful data
elements in the GGA, RMC, and VTC data streams.
This program uses the chip's internal interrupts, which allow the microcontroller to
execute multiple tasks at the same time. A few new statements are added to enable and
initialize the interrupts.
1. #include "mxapi.h"
2. #include "usart.h"
3. #include "lcd.h"
4. #include "gps.h"
5.
6. int main (void)
7. {
8. usart_init(4800); //Initialize the USART to
4800 baud
9. usart_interrupt_rx(ENABLE); //Enable
interrupts for the USART
10. sei(); //Turn on interrupts
11. lcd_init(); //Initialize the LCD
12.
13. while(1==1) //Start an infinite loop
14. {
15. lcd_instruction(FIRST_LINE); //Move the
cursor to the first line
16. lcd_instruction(CLEAR); //Clear the LCD
17. lcd_text(gps_data[2]); //Display the 3rd
value in the selected data stream
18. }
19. }
1. #include "mxapi.h"
2. #include "usart.h"
3. #include "lcd.h"
4. #include "gps.h"
5.
6. int main (void)
7. {
8. usart_init(4800); //Initialize the
Atmega168s USART to 4800 baud
9. usart_interrupt_rx(ENABLE); //Enable
interrupts for the USART
10. sei(); //Turn on interrupts
11. lcd_init(); //Initialize your LCD
12.
13. while(1) //Run the following code in an
infinite loop
14. {
15. lcd_instruction(FIRST_LINE); //Move the
cursor to the first line
16. lcd_text(gps_data[2]); //Display value
of third data field
17. lcd_character(':'); //Display ':'
character
18. lcd_text(gps_data[3]); //Display value of
fourth data field
19.
20. lcd_instruction(SECOND_LINE); //Move the
curse to the first line
21. lcd_text(gps_data[4]); //Display value
of fifth data field
22. lcd_character(':'); //Display ':'
character
23. lcd_text(gps_data[5]); //Display value of
sixth data field
24. lcdBlankLine(); //Send blanks to
clear the lines
25. }
26. }