gps speedometor

Hello I have been making a gps speedometer with a small oled for quite some time now. I have code but it updates at terribly slow pace. If anyone has any suggestions on how i could get the gps to update my speed faster it would be much appreciated.

//Connections:
 //GPS TX -> Arduino 0 (disconnect to upload this sketch)
// GPS RX -> Arduino 1
 //Screen SDA -> Arduino A4
 //Screen SCL -> Arduino A5


#include <NMEAGPS.h>
NMEAGPS gps;
gps_fix fix;

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI

#define gpsPort Serial

void setup()
{
  u8g.setColorIndex(1);

  gpsPort.begin(9600);

  gps.send_P( &gpsPort, F("PUBX,40,GLL,0,0,0,0,0,0") );
  gps.send_P( &gpsPort, F("PUBX,40,GSV,0,0,0,0,0,0") );
  gps.send_P( &gpsPort, F("PUBX,40,GSA,0,0,0,0,0,0") );
  gps.send_P( &gpsPort, F("PUBX,40,VTG,0,0,0,0,0,0") );
  gps.send_P( &gpsPort, F("PUBX,40,ZDA,0,0,0,0,0,0") );
  gps.send_P( &gpsPort, F("PUBX,40,RMC,0,1,0,0,0,0") );
  gps.send_P( &gpsPort, F("PUBX,40,GGA,0,1,0,0,0,0") );
}

char spinner( uint8_t pos )
{
  static const char spinnerChars[] PROGMEM = "/-\\|"; // saves RAM!

  return (char) pgm_read_byte( &spinnerChars[ pos % 4 ] ); // ...but requires special read
}

uint16_t kph              = 0;
uint16_t lastScreenUpdate = 0;
byte     screenRefreshes  = 0;
byte     gpsUpdates       = 0;

void loop() {

  uint16_t now = millis();

  if ( gps.available( gpsPort ) ) {
    fix        = gps.read();
    gpsUpdates++;

    if (fix.valid.speed)
      kph = (((uint32_t) fix.spd.whole) * 1852) / 1000; // knots to kph, integer math
    else
      kph = 0;
    lastScreenUpdate = now - 102; // force a redraw
  }

  if ( now - lastScreenUpdate > 101 ) {
    updateScreen();
    lastScreenUpdate = now;
    screenRefreshes++;
  }
}

void draw() {
  //u8g.setScale2x2(); don't do this!
  u8g.setFont(u8g_font_courB24);
  u8g.setPrintPos( 36, 45 );
  if (kph < 100)      // alternative to sprintf, just print leading spaces
    u8g.write( ' ' );
  if (kph < 10)
    u8g.write( ' ' );
  u8g.print( kph );

  //u8g.undoScale();
  u8g.setFont(u8g_font_fur11);
  u8g.setPrintPos( 2, 12 );
  u8g.write( spinner( screenRefreshes ) );
  u8g.write( ' ' );

  u8g.write( spinner( gpsUpdates ) );
  u8g.write( ' ' );

  if (!fix.valid.satellites || (fix.satellites < 10))
    u8g.write( ' ' );
  if (fix.valid.satellites)
    u8g.print( fix.satellites );
  else
    u8g.write( ' ' );
}

void updateScreen() {

  u8g.firstPage();
  do {
    draw();
  } while( u8g.nextPage() );
}

Start by checking the data type returned by millis()

dmitri_gorchev:
If anyone has any suggestions on how i could get the gps to update my speed faster it would be much appreciated.

I built a speedometer and GPS tracker for my truck some years back and it has been fine. Had to use a Mega to have enough room for the BigFont Library for the LCD and SD-Card data.

I am using the TinyGPS++ Library and I just checked and I can call it for data every second. Although I dropped that to 10-seconds to slow down for the SD-card writes. But, if yours is just an LCD display, every second should be fine.

Maybe start again with the TinyGPS++ it does all the heavy lifting for you.

UKHeliBob:
Start by checking the data type returned by millis()

im confused by what this means

dmitri_gorchev:
im confused by what this means

When you're confused about one of the standard Arduino functions, go to the Language Reference and read the documentation for that function:
https://www.arduino.cc/reference/en

Thx I figured it out but it still don't help with the gps refresh rate.