Serial GPS change baud rate work only after board reset

Hi, i have an Adafruit Ultimate GPS connected to Arduino DUE Serial1 port.
I want to change communication baud rate to increase the information readable from the GPS.
The default GPS baud rate is 9600, so

  • connect to GPS in 9600,
  • send a command to the GPS sensor to switch to 57600
  • reinitialize the Serial1 connection with new baud rate

I do this in setup() method, but this take effect only after an hardware reset of the board.
Why ?
I suppose, that after a reset the GPS is already configured with 57600 baud rate, so the Serial1 work good.
But what are the right steps to change this configuration ?

This is my configuration code:

  delay(500);
  Serial1.begin(9600);
  Serial1.println("$PMTK251,57600*2C"); // 57600 Baudrate
  delay(500);
  Serial1.end();
  delay(500);
  Serial1.begin(57600);

In the attachment there is the entire code that is a modified of TinyGPS++ example that turn ON and turn OFF the pin13 led in setup() and than turn ON pin13 led when detect a valid date in GPS signal.

Thanks in advance

test_tinygpsplus.ino (2.59 KB)

This seems to work.

  Serial1.begin(9600);
  delay(500);

  Serial1.println("$PMTK251,57600*2C"); // 57600 Baudrate
  delay(500);

// warm start
  Serial1.println("$PMTK102*31");
  Serial1.end();
  
  Serial1.begin(57600);
  delay(500);

edit: This does too.

  Serial1.begin(9600);
  delay(500);

// warm start
  Serial1.println("$PMTK102*31");
  delay(500);

  Serial1.println("$PMTK251,57600*2C"); // 57600 Baudrate

  Serial1.end();
  
  Serial1.begin(57600);
  delay(500);

I use 9600 baud and it seems to do ok. I read only one packet type ($GPRMC) at one update per second. I disable all the others.

  Serial1.println("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29");

I could see if you boosted that to 10 updates per second why you would need to increase the speed.

Thanks for reply SurferTim!
I have tried all 2 solution, but still not work at power ON :frowning:
I need a board reset the board or open serial monitor (that cause reset) to work.
My goal is exactly to set the GPS to 10hz to have the best speed.

There is a way to debug it ?
I have no ideas how to fix this problem..

I have tried all 2 solution, but still not work at power ON :frowning:
I need a board reset the board or open serial monitor (that cause reset) to work.

Mine does that also. I purchased a Due from a company in China (Bang Good), and I'm regretting it. It won't reliably run any code at power on. It needs a reset to start. Here is my thread on that subject. I noticed it when using the ethernet shield with it.

Where did you get your Due?

edit: After reading the reviews of the Due at the Bang Good site, it appears the company that populates the Due boards for them may use incorrect parts, like using zero ohm resistors instead of caps.

I have an original Arduino DUE R3-E, purchased from Germany (EXP TECH).
I read your post, i've also tried blink led code, but setup() at power on run ok on my DUE.

I compile my code with latest (1.6.5) IDE on Mac OS.
I also suppose that the problem can be in the Arduino Serial lib, so i have tried an earlier IDE version (1.5.6), but it still not work at power on.

Mine from China looks just like that. I didn't have a problem with starting simple sketches at first, but is got worse the more boards I connected. Now it won't start even with the blink example. I must press the reset or open the serial monitor to start almost any sketch.

Now adding a 1sec delay before begin serial seem to work good:

  delay(1000);
  Serial1.begin(9600);
  Serial1.println("$PMTK251,57600*2C"); // 57600 Baudrate
  delay(200);
  Serial1.end();
  delay(200);
  Serial1.begin(57600);

tongo:
Now adding a 1sec delay before begin serial seem to work good:

  delay(1000);

Serial1.begin(9600);
  Serial1.println("$PMTK251,57600*2C"); // 57600 Baudrate
  delay(200);
  Serial1.end();
  delay(200);
  Serial1.begin(57600);

Hey I am facing the same issue. I am also using an original Arduino Due and I have to reset or open the serial monitor. Only then it works. So, will adding a delay do or is it some board problem?