Evening all,
I've been banging my head on this problem for a few days now and I just don't see why I am not getting any traction on it so, I come to you for help. I seem to be not understanding something about either arduino serial data handling or arduino string handling or, both. The problem is this: I am trying to read a gps module (Argent Data Systems) which outputs standard NMEA sentences. The unit puts out a paragraph every second starting with a "$GPGGA" string. The paragraph content varies in a cyclic manner. Three seconds of typical output looks like the following:
$GPGGA,033332.00,0000.0000,N,00000.0000,E,0,00,0.0,,M,,M,,*5F
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,033332.00,V,0000.0000,N,00000.0000,E,,,050212,,,N*40
$GPGGA,033333.00,0000.0000,N,00000.0000,E,0,00,0.0,,M,,M,,*5E
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,033333.00,V,0000.0000,N,00000.0000,E,,,050212,,,N*41
$GPGGA,033334.00,0000.0000,N,00000.0000,E,0,00,0.0,,M,,M,,*59
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,4,1,15,26,88,090,,02,88,090,,04,88,090,,05,88,090,*7F
$GPGSV,4,2,15,24,88,090,,29,88,090,,08,88,090,,07,88,090,*79
$GPGSV,4,3,15,27,88,090,,10,88,090,,12,88,090,,30,72,270,25*70
$GPGSV,4,4,15,20,72,090,,03,80,090,21,06,80,270,19*41
$GPRMC,033334.00,V,0000.0000,N,00000.0000,E,,,050212,,,N*46
I want to key my code to the GPGGA string that starts every paragraph and that is the only sentence I actually need to extract. I have tried straight strings, the String class, serialEvent(), I've hunted the web for examples and I have yet to find anything with which I can pull this sentence out. I really don't see what I'm doing wrong. I haven't tried TinyGPS or similar yet. When I first read about it, it didn't appear to do what I wanted which is to give me the actual sentence. I will revisit it after I post this. I'd still love to know why the things I have tried haven't worked.
If I read in each character and then just immediately dump it back out on the serial, I see everything (in fact, that's how the list of sentences/paragraphs above was generated:
void setup() {
Serial.begin(4800);
}
void loop() {
while (Serial.available()) {
char inChar = (char)Serial.read();
Serial.print(inChar);
}
}
If I try to do anything else, I either get a garbled, incomplete mess or, nothing at all. I just tried tonight to solve this in the most basic, classical way I could think and even that didn't work. I get no output at all.
/* gps_read_GPGGA
Written 2/12/2012 Steven Buczkowski
Yet another attempt to read GT-320FW GPS module for ProjectDEBO
HAB C&DH and key in on GPGGA sentences for timing, sensor
reads and radio xmit.
*/
char sBuffer[250]; // to store incoming NMEA sentence
int i;
char inChar;
void setup() {
Serial.begin(4800);
}
void loop() {
while (Serial.available()) {
do { // look for '
I am writing this in the Arduino 1.0 environment and running presently on a Duemilanove (once it works, the operational platform will be a pro mini). I'll take any advice I can get on how to break this serial input into strings and then do comparisons on it.
Thanks for any help you can give me!
inChar = Serial.read();
}
while (inChar != '
I am writing this in the Arduino 1.0 environment and running presently on a Duemilanove (once it works, the operational platform will be a pro mini). I'll take any advice I can get on how to break this serial input into strings and then do comparisons on it.
Thanks for any help you can give me!); // end do {
// found start of NMEA sentence. Now look to see which one
sBuffer[0] = inChar;
for (i=1;i<6;i++) {
inChar = Serial.read();
sBuffer[i] = inChar;
} // end for (i=1;i<6;i++)
sBuffer[i] = '\0'; // terminate this portion of string
if (strcmp(sBuffer, "$GPGGA") != 0) {
//goto nextloop;
return;
} // end if (strcmp)
else {
// we've found a NMEA GPGGA string. read in the rest and do something
inChar = Serial.read();
while (inChar != '*') {
sBuffer[i++] = inChar;
inChar = Serial.read();
} // end while (inChar != '*'
// we have the string except for the '*', checksum and \r\n
sBuffer[i++] = inChar; // add '*'
inChar = Serial.read(); // read first byte of checksum
sBuffer[i++] = inChar;
inChar = Serial.read(); // read in second byte of checksum
sBuffer[i++] = inChar;
sBuffer[i] = '\0'; // add null (we'll add \r\n before sending to radio)
} // end else
// send out data for debug check
Serial.println(sBuffer);
// delay(50);
} // end while (Serial.available())
} // end loop()
I am writing this in the Arduino 1.0 environment and running presently on a Duemilanove (once it works, the operational platform will be a pro mini). I'll take any advice I can get on how to break this serial input into strings and then do comparisons on it.
Thanks for any help you can give me!