Go Down

Topic: Serial read, Wait for $GPRMC [Solved!] (Read 1 time) previous topic - next topic

Runaway Pancake

Mar 06, 2012, 03:50 am Last Edit: Mar 09, 2012, 01:46 am by runaway_pancake Reason: 1
I have a GPS set to do nothing but the $GPRMC.

With this, I check for the $ and it blinks 13 once / sec ?
Code: [Select]

void setup()
{
 Serial.begin(4800);
 pinMode(13, OUTPUT);
}

void loop()
{
 if (Serial.available() > 0)
 {
   int inByte = Serial.read();
   if (inByte == 36)
   {
     dollarblink();
   }
 }
}

void dollarblink ()
{
 digitalWrite(13, HIGH);
 delay(100);
 digitalWrite(13, LOW);
}


So, for my follow-up, I wanted to test for the complete sentence header, but 13 stays on all the time (my scheme craters) ?
Code: [Select]

int i;
int GPSchar [13];
int GPScheck [7] = {36,71,80,82,77,67,44};
//                   $  G  P  R  M  C  ,  
void setup()
{
 Serial.begin(4800);
 pinMode(13, OUTPUT);
}

void loop()               // wait for $GPRMC,
{              
 for (i = 0; i < 7; i++)  
 {
   if (Serial.available() > 0)
   {
     GPSchar[i] = Serial.read();
     if (GPSchar[i] != GPScheck[i])
     {
       checkbombed();
     }
   }
 }
 successblink();
}  
     
void checkbombed ()
{
 i = 0;    // re-initialise loop
}

void successblink()
{
 digitalWrite(13, HIGH);
 delay(75);
 digitalWrite(13, LOW);
}


Do I need more/some delay between Serial.reads?
Once I verify that I've captured the header - $GPRMC, - I want to grab the next six characters/bytes [hhmmss].
*** Modify subject title ***
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

zoomkat

You may want to capture the data as a string like below and extract the desired info.

Code: [Select]

//zoomkat 3-5-12 simple delimited ',' string parce
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,
 
  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      //do stuff
      Serial.println(readString); //prints string to serial port out
      readString=""; //clears variable for new input     
     } 
    else {     
      readString += c; //makes the string readString
    }
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Runaway Pancake

Thanks for your Reply, zoomkat.
OK
I have, what appears to be, a successful "Wait for $GPRMC".
I could test it more thoroughly, by enabling another sentence or sending it some manual input, but it's D13'ing 1pps.
Code: [Select]

int idx;
int GPSchar [13];
int GPSchk [7] = {36,71,80,82,77,67,44};
//                 $  G  P  R  M  C  , 
void setup()
{
  Serial.begin(4800);
  pinMode(13, OUTPUT);
}

void loop()               // wait for $GPRMC,
{
  while (idx < 7)
  { 
    if(Serial.available() > 0)
    {
      GPSchar[idx] = Serial.read();
      if(GPSchar[idx] == GPSchk[idx])
      {
        idx++;
      }
      else
      {
        idx = 0;
      }
    }
  }
  successblink();
}

void successblink()
{
  digitalWrite(13, HIGH);
  delay(75);
  digitalWrite(13, LOW);
  for (int a=0; a<7; a++)
  {
    GPSchar[a]=0;
  }
  idx = 0;
}


I haven't captured the time characters yet, haven't tried ??? one step at a time.
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Runaway Pancake

OK
I've succeeded in capturing the time characters

http://www.youtube.com/watch?v=OW8FVmrA7js
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Go Up