Serial Read of GPS Every Loop

I have the below code. I am trying to alter it to read the full 80 character sentence every Loop. I have tried lots of ways, but just cant seem to get it.

Does anyone have any ideas please?

Its from here:

#include <SoftwareSerial.h>

SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;

char sentence[sentenceSize];

void setup()
{
  Serial.begin(115200);
  gpsSerial.begin(9600);
}

void loop()
{
  static int i = 0;
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    // Serial.print(ch);
    if (ch != '\n' && i < sentenceSize)
    {
      sentence[i] = ch;
      i++;
    }
    else
    {
     sentence[i] = '\0';
     i = 0;
     displayGPS();
     }
  }
}

void displayGPS()
{
  char field[80];
  getField(field, 0);
  if (strcmp(field, "$GPRMC") == 0)
  {
    Serial.print("Time: ");
    getField(field, 1);  // number
    Serial.print(field);

    Serial.print(" Status: ");
    getField(field, 2);  // number
    Serial.print(field);
    
        Serial.print(" Lat: ");
    getField(field, 3);  // number
    Serial.print(field);
    
        Serial.print(" Lat Dir: ");
    getField(field, 4);  // number
    Serial.print(field);
    
        Serial.print(" Long: ");
    getField(field, 5);  // number
    Serial.print(field);
    
        Serial.print(" Long Dir: ");
    getField(field, 6);  // number
    Serial.print(field);
    
            Serial.print(" Speed in knots: ");
    getField(field, 7);  // number
    Serial.print(field);
    
            Serial.print(" Direction in Degrees: ");
    getField(field, 8);  // number
    Serial.print(field);
    
            Serial.print(" Date in UTC [DdMdAa]: ");
    getField(field, 9);  // number
    Serial.print(field);
    
            Serial.print(" Magnetic cariation: ");
    getField(field, 11);  // number
    
                Serial.print(" Variation [E/W]: ");
    getField(field, 12);  // number
    
                Serial.print(" Mode: ");
    getField(field, 13);  // number
    Serial.print(field);
    
    
    
    Serial.println();
  }
}


void getField(char* buffer, int index)
{
  int sentencePos = 0;
  int fieldPos = 0;
  int commaCount = 0;
  while (sentencePos < sentenceSize)
  {
    if (sentence[sentencePos] == ',')
    {
      commaCount ++;
      sentencePos ++;
    }
    if (commaCount == index)
    {
      buffer[fieldPos] = sentence[sentencePos];
      fieldPos ++;
    }
    sentencePos ++;
  }
  buffer[fieldPos] = '\0';
}

"I want to read the full 80 characters, which take nearly forever to arrive, 16,000,000 times per second". Did I paraphrase what you want to do correctly?

The first question is WHY you think you need to read a complete sentence on every pass through loop?

The second question is what the code you posted is actually doing?

The third is how does that differ from what you want?

"I want to read the full 80 characters, which take nearly forever to arrive, 16,000,000 times per second"

I strongly suspect that what he means is "Read the full 80 characters then display it before repeating the loop() function". In which case, Nick's pointer will help.

That link really helped understand Serial, thank you.

Maybe more background will help. In reality I only want to get GPS data every say 10 seconds. And when I get GPS, I also want to get other sensor data, and log it to a SD Card.

My plan was to use a 10 second delay at the end of the loop, then go around again and collect all readings, and record them. Should I be doing this in a different way?

thanks

Should I be doing this in a different way?

Absolutely.

In reality I only want to get GPS data every say 10 seconds.

Are you sure? I would think that you would want to get everything that the GPS sent, and only log the latest reading every 10 seconds. Big difference.

Learn NOW how to avoid delay() like the plague. Look at the blink without delay example for inspiration.