Pages: [1]   Go Down
Author Topic: Serial read, Wait for $GPRMC [Solved!]  (Read 1679 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 64
Posts: 2465
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a GPS set to do nothing but the $GPRMC.

With this, I check for the $ and it blinks 13 once / sec ─
Code:
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:
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 ***
« Last Edit: March 08, 2012, 07:46:35 pm by runaway_pancake » Logged

"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?"

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
//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
    }
  }
}

Logged

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

Offline Offline
Edison Member
*
Karma: 64
Posts: 2465
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

"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?"

Offline Offline
Edison Member
*
Karma: 64
Posts: 2465
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK
I've succeeded in capturing the time characters

Logged

"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?"

Pages: [1]   Go Up
Jump to: