Help adding & removing NMEA Data from code

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
whitwell
 
Posts: 3
Joined: Sat Nov 24, 2012 2:36 pm

Help adding & removing NMEA Data from code

Post by whitwell »

Hi

I have some code (from the net) which utilises a GPS and outputs the NMEA sentences along with a summary of the Lat/Long, Date/Time.

Code: Select all

// GPRMC String

#include <NewSoftSerial.h>

NewSoftSerial mySerial =  NewSoftSerial(5, 3);
#define powerpin 4

#define GPSRATE 9600
//#define GPSRATE 38400


// GPS parser for 406a
#define BUFFSIZ 90 // plenty big
char buffer[BUFFSIZ];
char *parseptr;
char buffidx;
uint8_t hour, minute, second, year, month, date;
uint32_t latitude, longitude;
uint8_t groundspeed, trackangle;
char latdir, longdir;
char status;

void setup() 
{ 
  if (powerpin) {
    pinMode(powerpin, OUTPUT);
  }
  pinMode(13, OUTPUT);
  Serial.begin(GPSRATE);
  mySerial.begin(GPSRATE);
   
  // prints title with ending line break 
  Serial.println("GPS parser"); 
 
   digitalWrite(powerpin, LOW);         // pull low to turn on!
} 
 
 
void loop() 
{ 
  uint32_t tmp;
  
  Serial.print("\n\rread: ");
  readline();
  
  // check if $GPRMC (global positioning fixed data)
  if (strncmp(buffer, "$GPRMC",6) == 0) {
    
    // hhmmss time data
    parseptr = buffer+7;
    tmp = parsedecimal(parseptr); 
    hour = tmp / 10000;
    minute = (tmp / 100) % 100;
    second = tmp % 100;
    
    parseptr = strchr(parseptr, ',') + 1;
    status = parseptr[0];
    parseptr += 2;
    
    // grab latitude & long data
    // latitude
    latitude = parsedecimal(parseptr);
    if (latitude != 0) {
      latitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      latitude += parsedecimal(parseptr);
    }
    parseptr = strchr(parseptr, ',') + 1;
    // read latitude N/S data
    if (parseptr[0] != ',') {
      latdir = parseptr[0];
    }
    
    //Serial.println(latdir);
    
    // longitude
    parseptr = strchr(parseptr, ',')+1;
    longitude = parsedecimal(parseptr);
    if (longitude != 0) {
      longitude *= 10000;
      parseptr = strchr(parseptr, '.')+1;
      longitude += parsedecimal(parseptr);
    }
    parseptr = strchr(parseptr, ',')+1;
    // read longitude E/W data
    if (parseptr[0] != ',') {
      longdir = parseptr[0];
    }
    

    // groundspeed
    parseptr = strchr(parseptr, ',')+1;
    groundspeed = parsedecimal(parseptr);

    // track angle
    parseptr = strchr(parseptr, ',')+1;
    trackangle = parsedecimal(parseptr);


    // date
    parseptr = strchr(parseptr, ',')+1;
    tmp = parsedecimal(parseptr); 
    date = tmp / 10000;
    month = (tmp / 100) % 100;
    year = tmp % 100;
    
    Serial.print("\nTime: ");
    Serial.print(hour, DEC); Serial.print(':');
    Serial.print(minute, DEC); Serial.print(':');
    Serial.println(second, DEC);
    Serial.print("Date: ");
    Serial.print(date, DEC); Serial.print('/');
    Serial.print(month, DEC); Serial.print('/');
    Serial.println(year, DEC);
    
    Serial.print("Lat: "); 
    if (latdir == 'N')
       Serial.print('+');
    else if (latdir == 'S')
       Serial.print('-');

    Serial.print(latitude/1000000, DEC); Serial.print('\°', BYTE); Serial.print(' ');
    Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
    Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
    Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
   
    Serial.print("Long: ");
    if (longdir == 'E')
       Serial.print('+');
    else if (longdir == 'W')
       Serial.print('-');
    Serial.print(longitude/1000000, DEC); Serial.print('\°', BYTE); Serial.print(' ');
    Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
    Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
    Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
   
  }
  //Serial.println(buffer);
}

uint32_t parsedecimal(char *str) {
  uint32_t d = 0;
  
  while (str[0] != 0) {
   if ((str[0] > '9') || (str[0] < '0'))
     return d;
   d *= 10;
   d += str[0] - '0';
   str++;
  }
  return d;
}

void readline(void) {
  char c;
  
  buffidx = 0; // start at begninning
  while (1) {
      c=mySerial.read();
      if (c == -1)
        continue;
      Serial.print(c);
      if (c == '\n')
        continue;
      if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
        buffer[buffidx] = 0;
        return;
      }
      buffer[buffidx++]= c;
  }
}
I'm looking for the output to be altered so that nothing other than the GPRMC string is output and then a seperate set of lines are generated for:

Lat (already there)
Long (already there)
Date (already there)
Time (already there)

WANT
Speed
Altitude
Bearing (course over ground)

Greatly appreciate your help.

User avatar
madhunm
 
Posts: 41
Joined: Thu Dec 16, 2010 6:06 pm

Re: Help adding & removing NMEA Data from code

Post by madhunm »

Hello whitwell,

Have you considered using the TinyGPS library by Mikal Hart?

Download link: http://arduiniana.org/TinyGPS/TinyGPS12.zip

Thanks,
Madhu.

whitwell
 
Posts: 3
Joined: Sat Nov 24, 2012 2:36 pm

Re: Help adding & removing NMEA Data from code

Post by whitwell »

I stubbled across this earlier today. Thanks.

Any ideas how I may use that string to send to an NTX2 radio transmitter?

http://www.radiometrix.com/files/additi ... x2nrx2.pdf

Thanks

User avatar
wethaguy
 
Posts: 54
Joined: Sun May 06, 2012 9:00 pm

Re: Help adding & removing NMEA Data from code

Post by wethaguy »

This isn't that hard. I googled arduino + radiometrix and found two different source codes and videos for interfacing the radiometrix and arduino. Not sure what help you could need beyond what a very basic google search can provide. Download or copy/paste the code and start tinkering.

whitwell
 
Posts: 3
Joined: Sat Nov 24, 2012 2:36 pm

Re: Help adding & removing NMEA Data from code

Post by whitwell »

WethaGuy wrote:This isn't that hard. I googled arduino + radiometrix and found two different source codes and videos for interfacing the radiometrix and arduino. Not sure what help you could need beyond what a very basic google search can provide. Download or copy/paste the code and start tinkering.

Thanks - You're quite right.. However injecting a captured NMEA string $GPRMC into the string to be delivered to the NTX2 is a little different. Can you help with that? I know Google can't.

Cheers

User avatar
wethaguy
 
Posts: 54
Joined: Sun May 06, 2012 9:00 pm

Re: Help adding & removing NMEA Data from code

Post by wethaguy »

whitwell wrote: injecting a captured NMEA string $GPRMC into the string to be delivered to the NTX2
Step 1. Get nmea data from GPS (as char[])
Step 2. Send char[] to NTX2
Step 3. don't need step 3, it's already done

There are 3 copy/paste example code webpages on the first page of google results that will accomplish step 2. I don't think the answer to your question can get much easier to find than that.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”