I found this small program on this forum and it works rather well with very minimal overhead. KUDOS, to choose specific NMEA sentences, but it adds a extra mystery byte and I am not sure where it is coming from. At the end of the NMEA sentence the end should always be "0D 0A"
But this script is making the end come come out "0D 0D 0A" The other gps i am interfacing with does not like this and prompts "invalid gps". Any thoughts where the extra "0D" is magically appearing from.
I have been using IO Ninja to verify my outputs, The gps's I have neither produce this so it is coming from the Arduino somehow? Any thoughts? I have been learning C for 1 week so far BTW.
/*
Example 17.1 UART ONLY - MODIFIED
Display any data coming out of the GPS receiver in the serial monitor box
tronixstuff.com/tutorials > Chapter 17
*/
/*
Modified by Robert M. Jaarsma
sends only desired sentences as a string over the serial port.
String can be inspected and/or manipulated before sending it to serial.
Could be usefull for long range (low baudrate) RF modems or with power limited applications.
Can extract different NMEA sentences by entering different sentence identifiers ar begin of the code
at String sentence1 = "$GPRMC";
MAKE SURE SHIELD SWITCH IS SET TO UART, code will not work when DLINE is selected.
However, DLINE does need to be selected when code is uploaded to the board.
After uploading the code to the board set shield to UART and reset de board (reset button on shield).
Without resetting after code upload the UART serial communications to the PC will not work (unless
you reconnect the USB cable).
Revision: 12 jun 2011 13:08 GMT
*/
char gpsin;
String stringgps = "$"; // as the code looks for the '
it needs
// to be added manually again in the string
// SET DESIRED SENTENCE IDENTIFIER HERE, set "$" only for all sentences
String sentence1 = "$GPRMC";
void setup()
{
Serial.begin(4800); // the 406A GPS module puts out serial at 4800 bps
}
void loop()
{
if (Serial.available()>0) // if there is data coming into the serial line
{
gpsin = Serial.read(); // get a byte of data
}
if (gpsin == 36) // ascii code '
{
while (gpsin != 13) // ascii code 'return', end of sentence
{
if (Serial.available()>0) // if there is data coming into the serial line
{
gpsin = Serial.read(); // get the next byte of data while gpsin != 13
stringgps += gpsin; // add the latest byte to the string
}
}
if (stringgps.startsWith(sentence1))// look if string starts with ex. '$GPRMC'
{
Serial.println (stringgps); // when gpsin != 13 NOT true (gpsin == 13)
// send string with complete sentence to serial
}
stringgps = "$"; // empty string for next sentence,
// '
is already added to the string manually here.
//delay (100);
}
}