Doubts gps neo6m v2

Hello.

I'm making a speedometer for my race car.

I am using the ublox neo 6m GPS module.

At stable speeds, it works correctly, but when I brake hard or accelerate it has a hard time refreshing, up to 10 seconds...

Could you help me to make it as fast as possible?

my code:

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define rxPin 10
#define txPin 9
SoftwareSerial gps(rxPin, txPin);
TinyGPSPlus gps_gps;
int gps_speed;
 
 
void setup()
{
  Serial.begin(115200);

   gps.begin(9600);
  changeFrequency();
delay(100); gps.flush();

 
  
}
 
void loop()
{
  boolean newData = false;
  for (unsigned long start = millis(); millis() - start < 100;)
  {
    if (gps.available())
    {
      if (gps_gps.encode(gps.read()))
      {
        newData = true;
      }
    }
  }
 
  //If newData is true
  if (newData == true)
  {
    newData = false;

    if (gps_gps.location.isValid() == 1)
    {
int gps_speed = gps_gps.speed.kmph();
      Serial.print(gps_speed);
      Serial.println("km/h");
      Serial.println(gps_gps.satellites.value());
 
    }
  }
 
  else
  {

    Serial.println("No Data");
  }
}

void changeFrequency() {
    byte packet[] = {
        0xB5, // 
        0x62, // 
        0x06, // 
        0x08, // 
        0x06, // length
        0x00, // 
        0x64, // measRate, hex 64 = dec 100 ms
        0x00, // 
        0x01, // navRate, always =1
        0x00, // 
        0x01, // timeRef, stick to GPS time (=1)
        0x00, // 
        0x7A, // CK_A
        0x12, // CK_B
    };
    sendPacket(packet, sizeof(packet));
}

void sendPacket(byte *packet, byte len) {
 for (byte i = 0; i < len; i++)
 {
 gps.write(packet[i]); // GPS is HardwareSerial
 }
}

Just because you encode one of the maybe 10 different GPS NMEA sentences a typical Ublox GPS puts out, it does not mean you have new data to act on.

With most GPSs you only have new fix,altiude or speed data when the GPGGA or GPRMC sentences are received and processed.

OK

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define rxPin 10
#define txPin 9
SoftwareSerial gps(rxPin, txPin);
TinyGPSPlus gps_gps;
int gps_speed;
unsigned long LastGPSTime = 0;

void setup() {
  Serial.begin(115200);

  gps.begin(9600);
  changeFrequency();
  gps.flush();
}

void loop() {
  if (gps.available()) {
    if (gps_gps.encode(gps.read())) {
      LastGPSTime = millis();
      if (gps_gps.location.isValid() == 1) {
        int gps_speed = gps_gps.speed.kmph();
        Serial.print(gps_speed);
        Serial.println("km/h");
        Serial.println(gps_gps.satellites.value());
      }
    }
  }


  // Report if there has not been a GPS message in the last second
  if (millis() - LastGPSTime >= 1000) {
    Serial.println("No Data");
    LastGPSTime = millis();
  }
}

void changeFrequency() {
  const byte packet[] = {
    0xB5,  //
    0x62,  //
    0x06,  //
    0x08,  //
    0x06,  // length
    0x00,  //
    0x64,  // measRate, hex 64 = dec 100 ms
    0x00,  //
    0x01,  // navRate, always =1
    0x00,  //
    0x01,  // timeRef, stick to GPS time (=1)
    0x00,  //
    0x7A,  // CK_A
    0x12,  // CK_B
  };
  gps.write(packet, sizeof packet);
}
1 Like

Finally, I adapted my code in another form and it works perfectly. practically 0 latency.
Thank you all very much for participating, especially johnwasser

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define rxPin 10
#define txPin 9
SoftwareSerial gps(rxPin, txPin);
TinyGPSPlus gps_gps;
int gps_speed;
unsigned long LastGPSTime = 0;

const unsigned char UBLOX_INIT[] PROGMEM = {
  // Rate (pick one)
  0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0x64, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7A, 0x12, //(10Hz)
  // 0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A, //(5Hz)
  // 0xB5,0x62,0x06,0x08,0x06,0x00,0xE8,0x03,0x01,0x00,0x01,0x00,0x01,0x39, //(1Hz)
  // Disable specific NMEA sentences
  //0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, // GxGGA off es de donde saca nº sats
  0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x2B, // GxGLL off
  0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x32, // GxGSA off
  0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x39, // GxGSV off
  //0xB5,0x62,0x06,0x01,0x08,0x00,0xF0,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40, // GxRMC off saca los nudos
  0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x47 // GxVTG off
};

void setup() {
  Serial.begin(115200);
  gps.begin(9600);
    for (unsigned int i = 0; i < sizeof(UBLOX_INIT); i++) {
    gps.write( pgm_read_byte(UBLOX_INIT + i) );
  }
  gps.flush();
}

void loop() {
  if (gps.available()) {
    if (gps_gps.encode(gps.read())) {
      LastGPSTime = millis();
      if (gps_gps.location.isValid() == 1) {
        int gps_speed = gps_gps.speed.kmph();
        Serial.print(gps_speed);
        Serial.println("km/h");
        Serial.println(gps_gps.satellites.value());
      }
    }
  }


  // Report if there has not been a GPS message in the last second
  if (millis() - LastGPSTime >= 1000) {
    Serial.println("No Data");
    LastGPSTime = millis();
  }
}

Hello again!

I've been fighting for days with this code for the speed to work correctly

#include <Nextion.h>
#include <TinyGPS++.h>
TinyGPSPlus gps_gps;
NexNumber n6 = NexNumber(1, 12, "n6");
NexNumber n10 = NexNumber(1, 19, "n10");


void setup() {
  Serial2.begin(9600);
  delay(300);  // This dalay is just in case the nextion display didn't start yet, to be sure it will receive the following command.
  Serial2.print("baud=115200");
  Serial2.write(0xff);  // We always have to send this three lines after each command sent to nextion.
  Serial2.write(0xff);
  Serial2.write(0xff);
  Serial2.end();  // End the serial comunication of baud=9600
  Serial2.begin(115200);  // Start serial comunication at baud=115200

  Serial.begin(250000);

  Serial3.begin(9600);
  Serial3.flush();
}

void loop() {
  speed_GPS();
}

void speed_GPS() {

  if (Serial3.available()) { //probar a poner Serial
    if (gps_gps.encode(Serial3.read())) {
      if (gps_gps.location.isValid() == 1) {
        n6.setValue(gps_gps.speed.kmph());
        n10.setValue(gps_gps.satellites.value());
        Serial.println(gps_gps.satellites.value());
      }
    }
  }
}

If I write these lines of code, the speed updates almost instantly.

The problem comes when i put all my code together (rpm, water temp, oil temp, etc...). I think that the serial read is not able to work.

If I use a for , this way it works.

That could be happening??

void speed_GPS()
{  
  for (unsigned long start = millis(); millis() - start < 1;)
  {
   if (Serial3.available()) { //probar a poner Serial
    if (gps_gps.encode(Serial3.read())) {
      if (gps_gps.location.isValid() == 1) {
        n6.setValue(gps_gps.speed.kmph());
        n10.setValue(gps_gps.satellites.value());
        Serial.println(gps_gps.satellites.value());
      }
    }
  }
}
}

I have used the ublox software to disable NMEA sentences that I don't need. Only work (GxRMC and GxGGA)

In addition, the GPS works at 10hz.

What can be happening?
Thanks!

Nobody can't help me? :frowning:

Maybe the volunteers who provide assitance on this forum were waiting for you to post the code that caused the problem ?

Maximum of 5hz.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.