Reading a full line of dataEdit

  • read it into an array buffer

  • another example of an array buffer, with checking number of available bytes

  • links to sample code to get and parse NMEA strings

String functions in strings.h

NMEA DataEdit

NMEA Checksums

NMEA data should have $identifier,data,data,...,data*FF and then a newline, where FF is a checksum Hence, we can check for the newlines, dollar sign, asterisk, and the checksum value to verify the data.

Work on this is being done in reliable_serial_data.pde

Generate a checksum from a command:

NMEA checksum discussion

Handling data after parsingEdit

  • make this a moving average... remember the oldest data and subtract it.
  • maybe this?
  • to get one, we want a FIFO structure (say of 10 values) that we keep bumping the oldest out, subtracting it from our average, adding the new value to the queue and our average
  • look into extending TinyGPS to include the other data fields needed here; dont quite understand how it goes to the next _term
  • all about NMEA strings

Debugging Wind Sensor ParsingEdit

We're using strtok to parse data from the wind sensor. This is now working, strtok_parse.pde on dropbox.


It seems that strtok possibly corrupts our string as it processes it? First time through the loop it parses the full string; 2nd time it thinks that only the first token exists/is the full string (returns garbage when it attempts to tokenize beyond the first token)


 strcpy(cp, val); //make a backup copy of the data to parse
 str1 = strtok(cp, ","); //find location of first ',', and copy everything before it into str1; this will be the type   of command
 Serial.print("command portion from cp strtok is: ");
 if (strcmp(str1, "$PTNTHTM") == 0) 
 { //"$PTNTHTM,285.2,N,-2.4,N,10.7,N,59.1,3844*27"
   // sscanf(val, "$%7s,%s,%c,%s,%c,%s,%c,%c", str, &head2_string, &head_st, &pitch_string, &pitch_st, &roll_string, &roll_st, &valid);
   /*printf("Heading is : %f\n", head2_deg);
    printf("String is : %s\n", str);  
    The %s format in sscanf is defined to read a string until it encounters white space.  If you want it to stop on a comma, you should use the %[^,] format.
// res2 = strtok(NULL, ","); // this will use the cp copied string, since strtok magically remembers which string it was  initially referenced to if NULL if used instead of a string
   result = strtok(val,","); //returns a string section of val up to the first ,
   str=result; // should return $xxxxx identifier
   result = strtok(NULL,","); //should return 285.2
   head2_string = result;
 //convert to decimals
   head2_deg = atof(head2_string);
   roll_deg = atof(roll_string);
   pitch_deg = atof(pitch_string);
   // Including these prints causes the strings to be forever printed - they arent terminated properly by sscanf??
   Serial.print("Str command portion strtok1 from val: ");
   Serial.print("Heading portion strtok2 from val: ");


ÐParses says: valid string, val (full string) is:
command portion from cp strtok is: $PTNTHTM
Str command portion strtok1 from val: $PTNTHTM
Heading portion strtok2 from val: 285.2
Parses says: valid string, val (full string) is:
command portion from cp strtok is: $PTNTHTM
Str command portion strtok1 from val: $PTNTHTM
Heading portion strtok2 from val: Ê
Parses says: valid string, val (full string) is:

External LinksEdit

Serial parsing suggested protocols

A smallish string library

String copy with arduino

String tokenize with arduino

Comparing strings with arduino


A memory-intensive NMEA parsing library

Less memory-intensive NMEA GPS library, designed for arduino

Very good embedded systems controlling information

Using sscanf vs parsing character by character as TinyGPS does