Why GPS part of code is not working fast/need to restart 20 times to work

#include <Arduino_GigaDisplay_GFX.h>
#include <Arduino_GigaDisplay.h>
#include <Arduino_GigaDisplayTouch.h>
#include <WiFi.h>
#include <ArduinoBLE.h>
#include <Arduino_H7_Video.h>
#include <lvgl.h>
#include <Wire.h>
#include <RPC.h>
#include <NMEAGPS.h>
#define gpsPort Serial2
#define BLACK   0x0000
#define WHITE   0xFFFF
#define RED     0xF800
#define GREEN   0x07E0
#define BLUE    0x001F
#define GREY    0xC618
#define REPORTING_PERIOD_MS     1000
unsigned long lastRPCCall = 0;
int networks = 0; 
const char* ssid     = "SSID";
const char* password = "PASSWORD";
GigaDisplay_GFX gfx;
Arduino_GigaDisplayTouch touchDetector;
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
NMEAGPS gps;
gps_fix fix;
int mode = 1;
struct Rect {
  int x1, y1; 
  int x2, y2; 
  bool contains(int px, int py) {
    return (px >= x1 && px <= x2 && py >= y1 && py <= y2);
  }
  void draw(GigaDisplay_GFX &gfx, uint16_t color) {
    gfx.drawRect(x1, y1, x2 - x1, y2 - y1, color);
  }
};
Rect BLEButton = {430, 0, 480, 200};
Rect MainButton = {430, 200, 480, 400}; 
Rect OtherButton = {430,400,480,600};
Rect WiFiInstantButton = {0,600,50,800};
bool jammerSwitch = false;
bool wasTouching = false;
bool WebConnect = false;
bool isMain = true;
bool isOther = false;
int h = 0;
int b = 100;
void setup() {
  RPC.begin();
  gpsPort.begin(9600); 
  Display.begin();
  gfx.begin();
  gfx.fillScreen(RED);
  gfx.setTextSize(5);
  gfx.setRotation(1);
  gfx.setCursor(220,200);
  gfx.print("Doggo OS");
  gfx.setCursor(475,175);
  gfx.setTextSize(3);
  gfx.print("TM");
  delay(1500);
  gfx.fillScreen(RED);
  gfx.setTextSize(5);
  gfx.setCursor(220,200);
  gfx.print("BOOTING...");
  gfx.setTextSize(2);
  Serial.begin(9600);
  gfx.setCursor(220,240);
  gfx.print("Serial:Loaded");
  if(WiFi.begin(ssid,password)){
    gfx.setCursor(220,260);
    gfx.print("WiFi:Loaded");
  }
  else {
    gfx.setCursor(220,260);
    gfx.print("ERROR:002");
  }
  if(BLE.begin()){
    gfx.setCursor(400,240);
    gfx.print("BLE:Loaded");
  }
  else {
    gfx.setCursor(400,240);
    gfx.print("ERROR:003");
  }
  if(touchDetector.begin()){
    gfx.setCursor(400,260);
    gfx.print("Touch:Loaded");
  }
  else {
    gfx.setCursor(400,260);
    gfx.print("ERROR:004");
  }
  delay(500);
  networks = WiFi.scanNetworks();
  gfx.setRotation(0);
  WiFi.disconnect();
  lv_obj_t* screen = lv_obj_create(lv_scr_act());
  lv_obj_set_size(screen, Display.width(), Display.height());
  MAINBTTN();
}
void BTTNUI(){
  gfx.setTextSize(3);
  gfx.setTextColor(BLACK);
  gfx.setCursor(0,0);
  gfx.drawRect(430,0,50,800,BLACK);
  gfx.drawRect(430,0,50,200,BLACK);
  gfx.drawRect(430,0,50,400,BLACK);
  gfx.drawRect(430,0,50,600,BLACK);
  BLEButton.draw(gfx, BLACK);
  gfx.setRotation(1);
  gfx.setCursor(75,15);
  gfx.print("COM");
  gfx.setCursor(260,15);
  gfx.print("MAIN");
  gfx.setCursor(450,15);
  gfx.print("OTHER");
}
void BLEBTTN(){
  Serial.println("BLE BUTTON PRESSED");
  delay(200);
  gfx.setRotation(0);
  gfx.fillScreen(BLUE);
  gfx.fillRect(430, 0, 50, 800, GREY );
  BTTNUI();
  int n = WiFi.scanNetworks();
  for (int i = 0; i < n; i++) {
    String wifiName = WiFi.SSID(i);
    Serial.println(wifiName);
    gfx.setCursor(50, 100 + i * 30);
    gfx.print(wifiName);
  }
  gfx.setTextSize(2);
  gfx.setCursor(500,0);
  BLE.scan();
  unsigned long scanEnd = millis() + 4000; 
  while (millis() < scanEnd) {
    BLEDevice device = BLE.available();
    if (device.hasLocalName()) {
      String name = device.localName();
      Serial.print("BLE: "); Serial.println(name);
      gfx.setCursor(500, b);
      gfx.print(name);
      b += 30;
      h +=1;
      if (b > 600) break;
    }
  }
  Serial.print(h);
} 
void MAINBTTN(){
  Serial.println("MAIN BUTTON PRESSED");
  delay(200);
  gfx.setRotation(0);
  gfx.fillScreen(GREEN);
  gfx.fillRect(430, 0, 50, 800, GREY );
  gfx.setTextSize(3);
  BTTNUI();
  gfx.setCursor(20,65);
  gfx.print("DATE:");
  gfx.setCursor(20,100);
  gfx.print("HOUR:");
  gfx.setCursor(20,135);
  gfx.print("JAMMER:");
  gfx.setCursor(150,135);
  if (jammerSwitch == true){
    gfx.print("ONLINE");
  }
  else{
    gfx.print("OFFLINE");
  }
  gfx.setCursor(20, 170);
  gfx.print("WiFi:");
  gfx.setCursor(120, 170);
  if (WebConnect == true) {;
    gfx.print("CONNECTED");   
  }
  else{
    gfx.print("DISCONNECTED");
  }
}
void onBeatDetected() {
  Serial.println("Beat!");
}
void OTHERBTTN(){
  Serial.println("OTHER BUTTON PRESSED");
  delay(200);
  gfx.setRotation(0);
  gfx.fillScreen(GREEN);
  gfx.fillRect(430, 0, 50, 800, GREY );
  BTTNUI();
}
void WiFiFC(){
  Serial.print("wifi button working");
}
void wyswietlWszystko() {
  Serial.println(F("\n>>>> RAPORT GEOPRZESTRZENNY <<<<"));
  if (fix.valid.time) {
    Serial.print(F("CZAS UTC: "));
    Serial.print(fix.dateTime.hours); Serial.print(':');
    Serial.print(fix.dateTime.minutes); Serial.print(':');
    Serial.print(fix.dateTime.seconds); Serial.print('.');
    if (fix.dateTime_cs < 10) Serial.print('0'); 
    Serial.println(fix.dateTime_cs);
  }
  if (fix.valid.location) {
    Serial.print(F("POZYCJA: ")); Serial.print(fix.latitude(), 7); 
    Serial.print(F(", ")); Serial.println(fix.longitude(), 7); 
    if (fix.valid.lat_err || fix.valid.lon_err) {
      Serial.print(F("BLAD POZ: +/- ")); 
      Serial.print(fix.lat_err()); Serial.println(F(" m"));
    }
  }
  Serial.print(F("SATELITY: ")); 
  if (fix.valid.satellites) Serial.print(fix.satellites); else Serial.print(F("0"));
  if (fix.valid.hdop) { Serial.print(F(" | HDOP: ")); Serial.print(fix.hdop / 1000.0); }
  if (fix.valid.vdop) { Serial.print(F(" | VDOP: ")); Serial.print(fix.vdop / 1000.0); }
  if (fix.valid.pdop) { Serial.print(F(" | PDOP: ")); Serial.print(fix.pdop / 1000.0); }
  Serial.println();
  if (fix.valid.altitude) {
    Serial.print(F("ALT (Ellipsoid): ")); Serial.print(fix.altitude()); Serial.print(F(" m"));
    if (fix.valid.geoidHeight) {
      Serial.print(F(" | MSL (Poziom morza): ")); 
      Serial.print(fix.altitude() + fix.geoidHeight()); Serial.print(F(" m"));
    }
    Serial.println();
  }
  if (fix.valid.speed) {
    Serial.print(F("PREDKOSC: ")); Serial.print(fix.speed_kph(), 3); Serial.print(F(" km/h"));
    if (fix.valid.heading) {
      Serial.print(F(" | KURS: ")); Serial.print(fix.heading(), 2); Serial.print(F(" deg"));
    }
    Serial.println();
  }
  Serial.print(F("STATUS FIX: "));
  switch(fix.status) {
    case gps_fix::STATUS_NONE: Serial.println(F("Brak")); break;
    case gps_fix::STATUS_STD:  Serial.println(F("Standard (GNSS)")); break;
    case gps_fix::STATUS_DGPS: Serial.println(F("DGPS (Wspomagany)")); break;
  }
  Serial.print(F("CRC Errors: ")); Serial.println(gps.statistics.errors);
  
  Serial.println(F("----------------------------------"));
}
void loop() {
    while (gps.available(gpsPort)) {
    fix = gps.read();
    wyswietlWszystko();
  }
  if ((millis() - lastRPCCall >= 1000) && isMain) {
    auto hr = RPC.call("getHeartRate").as<float>();
    auto o2 = RPC.call("getSpO2").as<int>();
      if(hr != 0 ){
        gfx.setTextSize(3);
        gfx.setTextColor(BLACK,GREEN);
        Serial.print("Heart Rate: ");
        Serial.print(hr);
        Serial.print(" bpm | SpO2: ");
        Serial.print(o2);
        Serial.println("%");
        gfx.setCursor(20,205);
        gfx.print("Heart");
        gfx.setCursor(150,205); gfx.print(hr);
        gfx.setCursor(20, 240); gfx.print("SpO2"); 
        gfx.setCursor(150, 240); 
        if (o2 >= 100) {
            gfx.print(o2);  
        } else if (o2 >= 10) {
            gfx.print(o2); 
            gfx.print(" "); 
        } else {
            gfx.print(o2); 
            gfx.print("  "); 
        }
        gfx.print("%");
      }
    lastRPCCall = millis();
  }
      if (isMain) {
      gfx.setTextSize(3);
      gfx.setTextColor(BLACK, GREEN); 
      if (fix.valid.time) {
          char timeStr[10];
          int hh = fix.dateTime.hours + 1; // Korekta strefy czasowej 
          int mm = fix.dateTime.minutes;
          int ss = fix.dateTime.seconds;
          if (hh >= 24) hh -= 24;
          sprintf(timeStr, "%02d:%02d:%02d", hh, mm, ss);
          gfx.setCursor(100, 100);
          gfx.print(timeStr);
      } else {
          gfx.setCursor(100, 100);
          gfx.print("__:__:__");
      }
  }
  if (isOther){
    gfx.setTextColor(BLACK,GREEN);
    gfx.setCursor(20, 65);
    if (fix.valid.satellites){
      gfx.print("SATELITES:  "); gfx.print(fix.satellites);
      gfx.setCursor(20, 100);
    }
    if (fix.valid.altitude) gfx.print(F("ALTITUDE (Ellipsoid): ")); gfx.print(fix.altitude()); gfx.print(F(" m"));
    if (fix.valid.location) {
      gfx.setCursor(20, 135);
      gfx.print(F("LATITUDE: ")); gfx.print(fix.latitude(), 7); 
      gfx.setCursor(20, 170);
      gfx.print(F("LONGITUDE: ")); gfx.println(fix.longitude(), 7); 
  }
  }    
  GDTpoint_t p;
  if (touchDetector.getTouchPoints(&p)) {
    if (!wasTouching) {
      wasTouching = true;

      int x = p.x;
      int y = p.y;

      if (BLEButton.contains(x, y)){
          isMain = false;
          isOther = false;
          BLEBTTN();
      } 
      else if (MainButton.contains(x, y)){
        isMain = true;
        isOther = false;
        MAINBTTN();
      } 
      else if (OtherButton.contains(x, y)){
        isMain = false;
        isOther = true;
        OTHERBTTN();
      } 
      else if (WiFiInstantButton.contains(x,y)){
        isMain = false;
        isOther = false;
        WiFiFC();
      } 
    }
  } else {
    wasTouching = false;
  }
}
type or paste code here

That program has a hell of a lot of stuff going on. When in your program development did the problem appear?

I'm not 100% sure but I'v made it to this point and GPS is last addition , I use NEO-6M and sometimes it works and most of the time doesn't work

i'v flushed it with demo with is hell a lot simpler but this aint working too , connection checked 3,3v ?

Sorry for missleading I'v flushed it with demo and it worked after 15-20s

When you disable the GPS code, does it work again? What have you done to track down the problem?

Code above still ain't working I'v flushed giga with demo code , this got data after 20s re flushed it with code above and now I ' m getting data ???? How it works?????? I think the gps is warm started so it has data in memory ?

demo code

#include <NMEAGPS.h>

#define gpsPort Serial2
NMEAGPS gps;
gps_fix fix;

void setup() {
  Serial.begin(115200);
  while (!Serial); 
  gpsPort.begin(9600); 

  Serial.println(F("========================================"));
  Serial.println(F("   NEOGPS ARCHITECT - FULL UNLOCKED     "));
  Serial.println(F("========================================"));
}

void loop() {
  
  while (gps.available(gpsPort)) {
    fix = gps.read();
    wyswietlWszystko();
  }
}

void wyswietlWszystko() {
  Serial.println(F("\n>>>> RAPORT GEOPRZESTRZENNY <<<<"));

  // 1. CZAS I DATA (Z PRECYZJĄ CS)
  if (fix.valid.time) {
    Serial.print(F("CZAS UTC: "));
    Serial.print(fix.dateTime.hours); Serial.print(':');
    Serial.print(fix.dateTime.minutes); Serial.print(':');
    Serial.print(fix.dateTime.seconds); Serial.print('.');
    if (fix.dateTime_cs < 10) Serial.print('0'); 
    Serial.println(fix.dateTime_cs);
  }

  // 2. LOKALIZACJA I BŁĘDY ESTYMOWANE (Odblokowane błędy!)
  if (fix.valid.location) {
    Serial.print(F("POZYCJA: ")); Serial.print(fix.latitude(), 7); 
    Serial.print(F(", ")); Serial.println(fix.longitude(), 7);
    
    if (fix.valid.lat_err || fix.valid.lon_err) {
      Serial.print(F("BLAD POZ: +/- ")); 
      Serial.print(fix.lat_err()); Serial.println(F(" m"));
    }
  }

  // 3. SATELITY I PRECYZJA (DOP)
  Serial.print(F("SATELITY: ")); 
  if (fix.valid.satellites) Serial.print(fix.satellites); else Serial.print(F("0"));
  
  if (fix.valid.hdop) { Serial.print(F(" | HDOP: ")); Serial.print(fix.hdop / 1000.0); }
  if (fix.valid.vdop) { Serial.print(F(" | VDOP: ")); Serial.print(fix.vdop / 1000.0); }
  if (fix.valid.pdop) { Serial.print(F(" | PDOP: ")); Serial.print(fix.pdop / 1000.0); }
  Serial.println();

  // 4. WYSOKOŚĆ I GEOIDA (To odblokowałeś w configu)
  if (fix.valid.altitude) {
    Serial.print(F("ALT (Ellipsoid): ")); Serial.print(fix.altitude()); Serial.print(F(" m"));
    if (fix.valid.geoidHeight) {
      Serial.print(F(" | MSL (Poziom morza): ")); 
      Serial.print(fix.altitude() + fix.geoidHeight()); Serial.print(F(" m"));
    }
    Serial.println();
  }

  // 5. RUCH I WEKTOR PRĘDKOŚCI
  if (fix.valid.speed) {
    Serial.print(F("PREDKOSC: ")); Serial.print(fix.speed_kph(), 3); Serial.print(F(" km/h"));
    if (fix.valid.heading) {
      Serial.print(F(" | KURS: ")); Serial.print(fix.heading(), 2); Serial.print(F(" deg"));
    }
    Serial.println();
  }

  // 6. STATUS I TRYB PRACY (Kluczowe dla precyzji)
  Serial.print(F("STATUS FIX: "));
  switch(fix.status) {
    case gps_fix::STATUS_NONE: Serial.println(F("Brak")); break;
    case gps_fix::STATUS_STD:  Serial.println(F("Standard (GNSS)")); break;
    case gps_fix::STATUS_DGPS: Serial.println(F("DGPS (Wspomagany)")); break;
  }

  // 7. DIAGNOSTYKA MODUŁU
  Serial.print(F("CRC Errors: ")); Serial.println(gps.statistics.errors);
  
  Serial.println(F("----------------------------------"));
}

How many satellites is your system seeing? First GPS positioning after power up may take quite a while. You are testing out side where your can see the satellites, aren’t you?

Testing Literally inside my window seeing 4-7 satelites

cut off power for 2 mins and same problem happening trying to connect nothing for long long time

reapeted same procedure
1flush gps demo
2getting data
3flush my code
4no data long time ???

Time to add serial.Print() messages to the GPS logic to see where the problem is. Debugging can only be done by you.

okay will try

it seems to need to lock in onto satelite while demo code and then my code can get info when it's locke , will do debugging now

done some debugging and at this point I consider slaming my giga into wall it is truly random one time main code 20 min nothing run another test went to wash tooth 2 mins and connected ????

Satelites come and go. Four is the absolute minimum for a good fix.
More satelites also means a faster fix.
Maybe it's time to take the setup outside, with a 360 degree clear view of the sky.

Also learn how to use code tags when posting code.
Hit tools> auto format before you do.
Leo..

Please edit your posts that contain code.

  1. Select all code in a post.
  2. Click the <CODE/> button.
  3. Save the post.

This makes it easier to read, easier to copy and the forum software will display it correctly.

See https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems

Changed

Will try , Today woke up pluged setup 3 min and now I'ts connected and working maybe yesterday was not a good day for testing