SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By trialex
#143626
I have a GPS module that occasionally loses it's settings and gets reset to the factory defaults. I want my arduino sketch to therefore send the required commands to the GPS to put it back to the settings I want (i.e. update rate, strings that are reported) at start up just in case.

If I connect the GPS to my PC and load up a terminal program (such as the arduino serial monitor or realterm), I can see that if I just send to the GPS the plain string "$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" nothing happens. If I choose the option to also send "new line" and "carriage return", the GPS listens, and changes to the right setting.

OK cool, so in my sketch, I should just be able to use the "Serial.println" command right? The reference page (http://arduino.cc/en/Serial/Println) says "Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n')".

Simple right? Here's my code:
Code: Select all
Serial.println("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); // report GGA every update
So of course it doesn't work.

I've also tried this:
Code: Select all
  Serial.print("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); // report GGA every update
  Serial.print('\n');
  Serial.print('\r');
No luck either.

Any ideas? There is obviously something the terminal programs are doing that I'm not.

Thanks!
By trialex
#143628
Hmmmm...

I think I solved it myself - it's a "feature" that the GPS won't let you choose a slower baud rate while too much data is being sent. The following code seems to work (i.e. change the frequency, change the messages, then change the baud rate)
Code: Select all
  Serial.begin(57600);            // Start the serial port
  Serial.print("Booting");
  delay(1000);
    Serial.println("$PMTK300,1000,0,0,0,0*1C");   // 1Hz update rate
  delay(1000);
  Serial.println("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); // report GGA every update
  delay(1000);
  Serial.println("$PMTK251,4800*14");  // Use 4800 bps
  delay(1000);
  Serial.begin(4800);
  delay(1000);