Hi,
I'm having a bit of trouble with my GPS unit and I'm hoping someone can help. I'm using a ublox 5 module and have it connected to Serial2 on my Arduino Mega. With the following bit of code
while(Serial2.available() > 0){
char data;
data=Serial2.read();
if(data=='$'){
Serial.print('\n');
}
Serial.print(data);
}
I get a nice print out of the NMEA data. However, the problem with this is my Arduino board does nothing but sit and read the output from the GPS unit. What I want to do is read in 10-15 bytes of data, place that in a buffer to sort through, allow my Arduino board to go and do something else, and then come back to read another 10-15 bytes of data. To do that I used the following bit of code
for(int k=0;k<10;k++){
if(Serial2.available() > 0){
char data;
data=Serial2.read();
if(data=='$'){
Serial.print('\n');
}
Serial.print(data);
}
}
However, when I use this bit of code it's clear that when I go to read the input of Serial2, I don't pick up where I left off. Instead of getting nice NMEA data, It's clear I'm missing pieces of data.
Is there a way to send a command to the u-block to have it hold it's output until I come back to it? i.e. something like the following
for(int k=0;k<10;k++){
*** Start sending data ***
if(Serial2.available() > 0){
char data;
data=Serial2.read();
if(data=='$'){
Serial.print('\n');
}
Serial.print(data);
}
*** stop sending data ***
}
Thanks for any help
Kathy