Subject:** NEO-M8N GPS not saving baud rate permanently
Hello everyone,
I’m using an ESP32 with a NEO-M8N GPS module, and I’m trying to change the GPS baud rate from 115200 to 9600 permanently using UBX configuration commands.
Here’s the first code I upload to set and save the new baud rate:
#include <TinyGPSPlus.h>
#include <HardwareSerial.h>
TinyGPSPlus gps;
#define RXD2 16
#define TXD2 17
// UBX command to set UART1 baud to 9600
const uint8_t setBaud9600[] = {
0xB5, 0x62, 0x06, 0x00, 0x14, 0x00,
0x01, 0x00, 0x00, 0x00,
0xD0, 0x08, 0x00, 0x00,
0x80, 0x25, 0x00, 0x00, // 9600 baud
0x07, 0x00,
0x03, 0x00,
0x00, 0x00,
0x00, 0x00,
0xA2, 0xB5
};
// UBX command to save configuration (Flash + BBR)
const uint8_t saveCfg[] = {
0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x17,
0x31, 0xBE
};
void setup() {
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, RXD2, TXD2);
Serial.println("Setting GPS baud rate to 9600...");
delay(2000);
Serial1.write(setBaud9600, sizeof(setBaud9600));
Serial1.flush();
Serial.println("Command sent. Waiting for GPS to switch...");
delay(2000); // Allow GPS to apply new baud rate
Serial1.end(); // Close old UART
Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial.println("Reconnected at 9600 baud.");
Serial1.write(saveCfg, sizeof(saveCfg));
Serial1.flush();
Serial.println("Configuration saved to flash.");
delay(1000);
Serial.println("NEO-M8N GPS configured to 9600 baud permanently.");
}
void loop() {
while (Serial1.available() > 0) {
char c = Serial1.read();
gps.encode(c);
if (gps.location.isUpdated()) {
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
Serial.print("Satellites: ");
Serial.println(gps.satellites.value());
Serial.print("Altitude (m): ");
Serial.println(gps.altitude.meters());
Serial.print("Speed (km/h): ");
Serial.println(gps.speed.kmph());
Serial.println("---------------------");
}
}
}
After running this code, I then upload the following sketch to test communication at 9600 baud:
#include <TinyGPSPlus.h>
#include <HardwareSerial.h>
TinyGPSPlus gps;
#define RXD2 16
#define TXD2 17
void setup() {
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2); // GPS now fixed at 9600
Serial.println("NEO-M8N GPS started at 9600 baud");
}
void loop() {
while (Serial1.available() > 0) {
char c = Serial1.read();
gps.encode(c);
if (gps.location.isUpdated()) {
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
Serial.print("Satellites: ");
Serial.println(gps.satellites.value());
Serial.print("Altitude (m): ");
Serial.println(gps.altitude.meters());
Serial.print("Speed (km/h): ");
Serial.println(gps.speed.kmph());
Serial.println("---------------------");
}
}
}
However, the GPS module only works after resetting — it doesn’t seem to save the new baud rate permanently.
Each time I power-cycle or reset the GPS, it returns to the default baud rate (115200).
Could someone please help me understand why the configuration is not being saved permanently, or if I’m missing any additional UBX commands or steps?
Thank you!