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
}
}