Go Down

Topic: Reading GPS data  - SOLVED (Read 1 time) previous topic - next topic

Morwel

Oct 21, 2010, 10:17 pm Last Edit: Oct 21, 2010, 10:35 pm by Morwel Reason: 1
Hi everyone.
I'm trying to use GPS data coming from PMB-248 GPS Receiver in order to calculate distance to my target. When I use Serial.print(GPS.read(),BYTE); I see all NMEA data. I use char array to store specific parts of the NMEA data, however if I print this char array the displayed data misses every second symbol. I'm using the following code
Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial GPS(2,300); // rx pin = 2 for GPS
char tag[6], gpsData[60];

void setup()
{
 GPS.begin(4800);
 Serial.begin(9600);
}

void GPSRead()
{
 while(1)
 {
   if(GPS.read() == '$')
   {
     for(int i=0;i<6;i++)
     {
       tag[i] = GPS.read();  
     }
     if(memcmp(tag, "GPGGA,",6) == 0)
     {
       GPSCollect();
       break;
     }
   }
 }
 Serial.println(gpsData);
}

void GPSCollect()
{
 for(int i=0;i<60;i++)
 {
   gpsData[i] = GPS.read();
   if(GPS.read()=='*')
   {
     break;
   }
 }
}

void loop()
{
 GPSRead();
}

The data should come out like this:
183356,4239.4169,N,02321.3495,E,0,00,,00655.8,M,036.9,M,,
but the char array stores only this:
140,2946,,22.45E00,0658M069M,

I'm not sure what I'm missing here...
I'll appreciate your help.

Best regards,
Morwel

AWOL

#1
Oct 21, 2010, 10:27 pm Last Edit: Oct 21, 2010, 10:27 pm by AWOL Reason: 1
Code: [Select]
   gpsData[i] = GPS.read();
   if([glow]GPS.read()=='*'[/glow])

You're reading, but not storing in the highlighted section.

Did you mean:
Code: [Select]
   gpsData[i] = GPS.read();
   if(gpsData[i] =='*')

?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Morwel

AWOL, thank you so much. This change fixed the problem.

Go Up