EM-406 GPS module from spark fun

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

i was wondering is anyone has had any experience using the EM-406 gps module from sparkfun heres a link : http://www.sparkfun.com/commerce/product_info.php?products_id=465

any way, i have it outputting the NMEA strings to my terminal, but i would like tto write some software that can search for the begining characters $Gxxxx, here are some example strings it sends

$GPRMC,014247.000,A,2729.1220,S,15305.1823,E,1.10,190.03,160706,,*12
$GPGGA,014248.000,2729.1218,S,15305.1825,E,1,03,4.3,22.6,M,37.1,M,,0000*75
$GPGSA,A,2,09,02,05,,,,,,,,,,4.4,4.3,1.0*3B
$GPRMC,014248.000,A,2729.1218,S,15305.1825,E,0.50,322.62,160706,,*19
$GPGGA,014249.000,2729.1209,S,15305.1827,E,1,03,4.3,22.7,M,37.1,M,,0000*77
$GPGSA,A,2,09,02,05,,,,,,,,,,4.4,4.3,1.0*3B
$GPRMC,014249.000,A,2729.1209,S,15305.1827,E,0.71,357.09,160706,,*16

so i want it to seek out certain parts of the string and "decode" it so tat its easyer to read. i would like to display it on an LCD later on but will just concentrate on the dcoding to start with. im using a atmega 128 in WinAVR. at 16mhz.

like for exampler i would like it to send something like this to the terminal:

Lattitude = xxxx.xxxx
longtitude = xxxx.xxxx
UTC = xx:xx.xx

with just the values changing.

any ideas would be greatly appreciated.

:arrow: Dan :!:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Dan,
I'm thinking of a similar project. Only in thought mode at the moment.
The way I was going to do it is to capture the whole string set, using the header codes $GPGSA etc, to dedicated RAM locations, then use a pointer say "Y+ offeset" for the required info string, then exstract this to the LCD.
I use a similar technique to read data on digital comms radio between the main unit and the control head. It works quite well.
Hope this helps.
Roy

73's
Roy
VK5ASY

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Roy,

That's extreamley similar to what I first thought of (I've been discussing this with Dan via MSN, and suggested he post here to hear other algorithms).

My idea was to first store the entire string in a large array. Then pass over the string, replacing each comma with a NULL character, and storing the pointer to the next location in an array. You could then use the string copy library commands to copy out each section (the NULLs will ensure only the wanted parameter would be read out). Since the order of the parameters stays the same, you could define symbolic names for each of the pointer elements.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yeah cheers Roy, sounds like what i will end up doing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using my idea of replacing the commas with NULLs but using Roy's method of saving the array indexes rather than pointers (in case you need the indexes for something, or want to save RAM):

uint8_t GPSData[1024];
uint8_t ParamLocations[{NUM_OF_PARAMS}];

void FormatGPSArray(void)
{
	uint8_t ParamNum  = 1;
	ParamLocations[0] = 0;

	for (uint16_t ArrayLoc = 0; ArrayLoc < 1024; ArrayLoc++)
	{
		if (GPSData[ArrayLoc] == ',')
		{
			GPSData[ArrayLoc] = NULL;
			ParamLocations[ParamNum++] = ArrayLoc + 1;

			if (ParamNum == 14)
			  break;
		}
	}	
}

That assumes the string is already in GPSData[]. Once run you can then get the array index of each element via ParamLocations[{PARAM_NUM}]. By replacing the commas with NULLs you can then use your existing string handling commands but instead of passing it the pointer to the first element of GPSData[] you pass it the pointer to GPSData[ParamLocations[{PARAM_NUM}]].

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

Last Edited: Sun. Jul 16, 2006 - 05:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Way to go Dean.
You could use the commas as delimiters on their own!
Dan,
I mostly only use asm so I do direct compares on the UART data reg. This way I look for the header say $ then G etc, once I have a known string I dump the remainder to RAM, drag the offset to the required info then move that to the LCD for the number of Characters required. This way I can limit the RAM size and capture only the GPS strings I need.

let us know how you go?

Roy

73's
Roy
VK5ASY

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RAS Young wrote:
Way to go Dean.
You could use the commas as delimiters on their own!

Ah, another fellow Aussie! Yes, you could use the comma as a delimiter, but changing them to NULLs requires little extra CPU power and allows you to use the built in string libraries (strcat, etc) which expect NULLs as the terminator.

In it's most simplest form - assuming the string is never corrupt, and that it always starts with a $:

void GetGPSData(void)
{
    uint8_t  ReadParams = 0;
    uint8_t* DataPtr    = GPSData;

    // Wait for start of string
    while (!(USART_GetChar() == '$'));
    
    while (1)
    {
        DataPtr = USART_GetChar;

        if (*DataPtr == ',')
          ReadParams++;
        
        if ((*DataPtr == NULL) && (ReadParams == 14))
          break;

        DataPtr++;
    }    
}

That's very quick, and VERY unsafe. But it should serve as a starting point. Also check out TagData.c from my ButtLoad project which deals with searching incoming data (from a dataflash chip) for a known header, and then loading that data into an array - pretty much exactly what you want to accomplish.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dean, quite correct
My method can also be "unsafe" but I do a checksum on the whole string and a window comparison with the previous data. this gives me some security.
Also as you say I record all the data strings required (less headers) and can do a live access to all data at any time.
With the GPS application I want to use the UTC clock info to correct any time slip in my RTC. As the GPS might not be capable of full exsposure to the satalites all of the time I need to run my internal clock as well.

Dan did you see my pointer to "gpspassions" interesting stuff there?

Roy

73's
Roy
VK5ASY