I have a GPS set to do nothing but the $GPRMC.
With this, I check for the $ and it blinks 13 once / sec ?
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) ?
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 ***
You may want to capture the data as a string like below and extract the desired info.
//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
}
}
}
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.
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.
OK
I've succeeded in capturing the time characters