How to interpret and read NMEA strings using a gps recivier

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

Hey,

I'm pretty new at avr. I'm trying to interpret and read NMEA strings using a gps recivier. So I waswondering if anyone can give a code sample or explain how i can do this and how to for example read of the time to write it on the controllers display? :roll:

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

Well, if your GPS receiver has an USB output, it is very deseperate; else, if it has a serai (rs232 line) output... did you try to connect, via the USART, your AVR to a PC, receive strings you type on a PC (via hyperterminal, brayterminal or many others) and dsplay them on your avr's display (which one, BTW? and can it display constant strings?) )

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

The keyword for Google is "parse". If you google "parse nmea strings/sentences" you will find loads of code to do this. Most can easily be built for an AVR.

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

dbrion0606 wrote:
Well, if your GPS receiver has an USB output, it is very deseperate; else, if it has a serai (rs232 line) output... did you try to connect, via the USART, your AVR to a PC, receive strings you type on a PC (via hyperterminal, brayterminal or many others) and dsplay them on your avr's display (which one, BTW? and can it display constant strings?) )

Yes, I have connected avr to a PC and recived the GPS strings using putty. How do you write the code to get the NMEA strings to the display on the micro controller, as longitude, latitud and time?

we're using Atmega 644P and the GPS has a rs232 which converts to USB.

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

Quote:

If you google "parse nmea strings/sentences" you will find loads of code to do this. Most can easily be built for an AVR.

The same code should work just as well on a PC - that's kind of the point of C in fact ;-)

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

clawson wrote:
Quote:

If you google "parse nmea strings/sentences" you will find loads of code to do this. Most can easily be built for an AVR.

The same code should work just as well on a PC - that's kind of the point of C in fact ;-)

What code do you mean? :roll:

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

We appear to be going round in circles. Was something I wrote not clear. I said that if you Google for "parse nmea strings/sentences" you will find loads of code. THAT is the code I mean.

The fact is (huge surprise coming up!!!) you are NOT the very first person who ever wanted to take the output of an NMEA device and use it in computer usable form. NMEA is designed for humans, not computers to read. So thousands and thousands of programmers before you have faced the same requirement and written code to convert. Thanks to the internet hundreds, even thousands of those programmers have chosen to post their code on line. so these days no one has to write this stuff from scratch. The only "trick" is being able to identify the good code from the bad in what's available. As you begin to google you will find forums where recommendations have been made. After a while you'll probably find the same code being recommended over and over again - that's going to be the good code to use.

Remember that (if using C) you are not looking for AVR specific code. The fact is that NMEA parsing has been done on x86 and Mac and ARM and PIC and MIPS and every form of C programmable device. On the whole the very same C source code from one can just be compiled for another because all it's really doing at the end of the day is converting some text into machine readable numbers and atoi() or sscanf() or whatever the author chose to use is going to operate the same in any C compiler.

EDIT: about 5 seconds in Google got me here:

http://playground.arduino.cc/Tut...

To be honest I don't actually like the look of the code but it seems undeniable that it is able to read the Lat/Long from the sentences presented to it. I'm sure if I spent another 5 seconds with Google I could find something even better.

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

You have two distinct problems:

a) how to have a serial link between an AVR and a sender (you can start with a PC sending strings, via putty, say, at the same rate than the GPS): this is an AVR problem, there are avrfreaks tutorials ....

b) how to parse NMEA strings, and convert them into lat, long, ... : the code can be tested on a PC and ported to an AVR....
"nmea sscanf " google searching led me to , among many others :

https://www.avrfreaks.net/index.p...

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

[sarkasm]

Quote:

about 5 seconds in Google got me here:

http://playground.arduino.cc/Tut...


Is there any code at that site?
[/sarkasm]

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Quote:
I'm pretty new at avr.

Quote:
the GPS has a rs232 which converts to USB

The USB is good for connecting to the PC.
Either save as a file, or print out, several pages of the GPS data, especially the data when the GPS is first starting up, (cold start, warm start, etc). You will need this info later after your basic program is working.

The AVR uses logic level serial, unless your board has an RS-232 chip on it.

You need to get logic level data from the GPS to feed the USART in the AVR. If you only have access to the RS-232 data from the GPS, then you need a RS-232 to logic level converter chip, (Max232), to convert the data for the AVR to read.

If you have access to the logic level data from the GPS then note that it could be 5V or 3V logic levels. It is much easier, to get started, if your GPS, micro, and LCD all run at that same voltage.

It is generally wise to get the micro communicating with the USART to the PC first. (Terminal program on PC). This is easier to debug the micro's clock, baud rate, etc., and make sure your simple serial communications works.

Then switch to the GPS data.

In addition to Google, using the SEARCH at the to of the Forum's page with GPS will show many prior Threads discussing GPS, lots of reading for you to do.

JC

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

Here is an excellent tutorial on how to parse GPS NMEA sentences:

http://www.visualgps.net/WhitePa...

It's also a good tutorial on Finite State Machines (FSM) - which is an extremely valuable tool in embedded programming (among others)...

 

EDIT, June 2017:

 

Sadly, that tutorial is now gone.  sad

 

But I did manage to find it on the Way-Back Machine:

 

https://web.archive.org/web/2016...

 

smiley

 

#StateMachine #FSM #NMEA #FSMtutorial

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Jun 5, 2017 - 09:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Here is an excellent tutorial on how to parse GPS NMEA sentences

And how did I find it? Of course - by googling "parse GPS NMEA"!

:D

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your help.
I have it figured out now, but got errors that say:
undefined reference to lcd_goto
undefined reference to lcd_puts
undefined reference to lcd_putc
undefined reference to lcd_puti
undefined reference to lcd_init
though I have included lcd.h

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

Where's lcd.c?

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

Quote:

though I have included lcd.h

including lcd.h will not cause lcd.c to be compiled. You must add lcd.c to the list of files to be compiled. E.g. in AS6, add it to the same project and folder that holds your main .c file.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

JohanEkdahl wrote:
Quote:

though I have included lcd.h

including lcd.h will not cause lcd.c to be compiled. You must add lcd.c to the list of files to be compiled.

Or you must provide a ready-built library containing the required functions...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

have a good day

Last Edited: Thu. Apr 24, 2014 - 06:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All code flush left - all indentation lost. Code contains yellow smilies with subglasses. I.e. failure to manage to even get CODE tags right. [fixed - moderator]

Did you even notice? Did you care to look at your post after submitting it? No?

If you don't care more than that about yor post, then neither will anyone else.

Quote:
I can't get anything on the screen?

Nothing at all?
You ned to determine if it is the reception on UART or the display on screen that fails (or perhaps both..).

Do your system have any LED attached that you can control with ease?

What do you expect the following to do?

if(komma <=5 && nmea_state>4) while(komma <5);

If you get into the while loop you will never get out..

Since I looked at your code, though it is hardly readable in the state above, I would suggest:

Divide your problem into smaller ones and solve them separately:

-Read a button reliably (are they debounced? are button "active high" as it seems from your code?).

- Display something on the screen reliably.

- Communicate using the UART reliably. First step here is to "talk to" a terminal program on your PC rather than the GPS module. Only when that works should you move on to...

- Communicate with the GPS module. First step is to talk to thst rom a terminal program on your PC. When that has been proven working, and only then, should you move on to attavhing the AVR and the GPS module.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

There are worrying things:
a) did you check the lcd separately?
(if you cannot see Annie Thing on the screen, Shirley the 1rst step to do is to try outputting "hello world")

b) are your lcd routines well known, fully tested ones (J Ekdahl has a site dedicated to links to good docs and good LCD softwares)

c) your ISR call lcd routines: what would happen if they are too slow -math calculations/ conversion/lcd display) and an interrupt occurs?

d) it is very difficult to read unindented code (things go even worse when text is long) : there is a button at the North of the text entry window called "code "...
e) many things I could not detect...

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

I'd like to add one more small detail... if this code was written for and runs on a cpu OTHER than an AVR, the floating point library might actually have the double float type. The fact that declaring a var double (15 digits) just gets you a float (7 digits) with most of the AVR c compilers starts causing problems when you start trying to get decimal degrees equivalent to seconds of arc. Math precision might not matter that much though. I wouldn't use a gps program that didn't have doubles to circumnavigate the globe.

Imagecraft compiler user

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

Quote:

J Ekdahl has a site dedicated to links to good docs and good LCD softwares

http://www.johanekdahl.se/rwiki/... , if it helps. I do believe that Kalliospuke is using Pascal Stangs library - not absolutely sure though..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Well, if he uses a library you recommanded: the complexity diminishes (the LCd library is not the cause)..
Maybe Monsieur OP should first remove the ISR which handles buttons -knapp seem sweedish buttons, according to google Translation I feared OP was Latvian - (can be slow; buttons can bounce) and concentrate on the GPS decoding part; if, as you advised, he uses a PC to send GPS strings, he may test in a great varity of configurations (N/South hemmisphere...) a fixed GPS cannot offer-unless one has a fast plane..-

Parts of his state machine can be put into the ISR, but LCD writing can be slow and unpleasant if one writes one character at the time...

I donot understand what avstond does /i s meant to do..
what is longi_prev?

 for (int i=0;i<10;i++)
   {
      switch(i)
      {
         case 0:
         case 1:
         longi_grad[i]=longi[i+1];
         lati_grad[i]=lati[i];
         break;
         case 2:
         case 3:
         longi_min[i-2]=longi[i+1];
         break;
         case 5:
         case 6:
         case 7:
         case 8:
         longi_sek[i-5]=longi[i+1];
         lati_sek[i-5]=lati[i];
         break;
         default :
         break;
      }
   }

seems more d

ifficult to read than:

   longi_grad[0] = longi[1];
   longi_grad[1] = longi[2];
   lati_grad[[0] = lati[0];
   lati_grad[1] = lati[1];
   longi_min[0] = longi[3];
   longi_min[1] = longi[4];
   lati_min[0] = lati[2];
   lati_min[1] = lati[3];

   longi_sek[0]=longi[6];
   longi_sek[1]=longi[7];
   longi_sek[2]=longi[8];
   longi_sek[3]=longi[9];
   lati_sek[0]=lati[5];
   lati_sek[1]=lati[6];
   lati_sek[2]=lati[7];
   lati_sek[3]=lati[8];
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Avstond is the OPs name for "distance". Yes he seems to be Scandinavian.
"Longi_prev" sounds like "previous longitude" to me.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]