Adafruit GPS wont work with custom code

I have been working on a project that uses a Adafruit GPS chip, and for some reason it doesn't work with my custom code, only the examples work, i have tried removing parts of the code to see if it works but have had no luck, it only works with my code when i remove everything except the code talking to the GPS.
The code that doesn't work:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#include "SdFat.h"
#include "sdios.h"
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <Adafruit_MS8607.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
#include <Adafruit_INA260.h>

//setup SdFat not confusing at all

uint32_t timer = millis();
//const int8_t DISABLE_CS_PIN = -1;
#ifndef SDCARD_SS_PIN
const uint8_t SD_CS_PIN = BUILTIN_SDCARD;
#else  // SDCARD_SS_PIN
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
//#endif  // SDCARD_SS_PIN
//#if HAS_SDIO_CLASS
//#define SD_CONFIG SdioConfig(FIFO_SDIO)
//#elif ENABLE_DEDICATED_SPI
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(16))
//#else  // HAS_SDIO_CLASS
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(16))
#endif  // HAS_SDIO_CLASS
SdFs sd;
FsFile file;
FsFile file1;
FsFile file2;
FsFile file3;
FsFile file4;
#define LOG_EVENTS "Events.csv"
#define LOG_ALTDAT "Altitude.csv"
#define LOG_GPS "GPS Log.csv"
#define LOG_EVERYTHING "Fused data.csv"
#define LOG_POWER "Power level.csv"

//set up everything else
const int buzzer = 8;
int alt = 0.00;
boolean ready = false;
boolean launch = false;
boolean Main_out = false;
boolean Sec_out = false;
boolean GPS_out = false;
boolean Chip_check = false;
boolean  Powermes = true;
boolean onlybuzz1 = true;
boolean onlybuzz12 = true;
boolean onlyone = true;
boolean onlyone2 = true;
boolean onlyone3 = true;
boolean apogge = false;

unsigned long previousTime = 0;
unsigned long previousTime2 = 0;

int reading1 = 0.0;
int reading2 = 0.0;

#define LED_PIN     4
#define LED_COUNT  2
#define BRIGHTNESS 50 
#define NUMPIXELS 2
Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

Adafruit_MS8607 ms8607;
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BMP3XX bmp;


#define GPSSerial Serial6
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

Adafruit_INA260 ina260 = Adafruit_INA260();

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

  Serial.println("Starting up....");
  //setup GPS 
 

  delay(1000);
  //setup current sensor

   if (!ina260.begin()) {
    Serial.println("Couldn't find INA260 chip :(");
    while (1);
  }
  Serial.println("Current monitor setup....");
  delay(1000);
  // setup main altimeter
   if (!bmp.begin_I2C()) {  
    Serial.println("Could not find BMP390 :(");
    while (1);
  }
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  bmp.setOutputDataRate(BMP3_ODR_50_HZ);
 Serial.println("BMP390 setup....");
 delay(1000);
 //setup high altitude altimeter
 if (!ms8607.begin()) {
    Serial.println("Failed to find MS8607 chip :(");
    while (1) { delay(10); }
  }
  ms8607.setHumidityResolution(MS8607_HUMIDITY_RESOLUTION_OSR_8b);
   Serial.println("High altitude altimeter setup....");
   delay(1000);
   //setup sd card.... pray/send good vibes/plz work

   if (!sd.begin(SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(50)))) {
  Serial.println("SD card not found...bruh :(");
}
//now make the files
file = sd.open(LOG_EVENTS, FILE_WRITE);
file1 = sd.open(LOG_ALTDAT, FILE_WRITE);
file2 = sd.open(LOG_GPS, FILE_WRITE);
file3 = sd.open(LOG_EVERYTHING, FILE_WRITE);
file4 = sd.open(LOG_POWER, FILE_WRITE);


if (!file.open(LOG_EVENTS, FILE_WRITE)) {
    Serial.println("open failed file 1 :(");
    return;
  }
  if (!file1.open(LOG_ALTDAT, FILE_WRITE)) {
    Serial.println("open failed file 2 :(");
    return;
  }
   if (!file2.open(LOG_GPS, FILE_WRITE)) {
    Serial.println("open failed file 3 :(");
    return;
  }
  if (!file3.open(LOG_EVERYTHING, FILE_WRITE)) {
    Serial.println("open failed file 4 :(");
    return;
  }
  if (!file4.open(LOG_POWER, FILE_WRITE)) {
    Serial.println("open failed file 4 :(");
    return;
  }
  delay(1000);

  
  Serial.println("GPS maybe up..idk.....");
  delay(1000);
  Serial.println("Aight we good");
  pinMode(buzzer, OUTPUT);
  GPS.begin(9600);
  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  delay(1000);

  // Ask for firmware version
  GPSSerial.println(PMTK_Q_RELEASE);
}
void loop()
{

  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) Serial.print(c);
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trying to print out data
    Serial.print(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");
    if (GPS.hour < 10) { Serial.print('0'); }
    Serial.print(GPS.hour, DEC); Serial.print(':');
    if (GPS.minute < 10) { Serial.print('0'); }
    Serial.print(GPS.minute, DEC); Serial.print(':');
    if (GPS.seconds < 10) { Serial.print('0'); }
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    if (GPS.milliseconds < 10) {
      Serial.print("00");
    } else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
      Serial.print("0");
    }
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
      Serial.print("Antenna status: "); Serial.println((int)GPS.antenna);
    }
  }
  
   sensors_event_t temp, pressure, humidity;
   ms8607.getEvent(&pressure, &temp, &humidity);

   if (!file.open(LOG_EVENTS, O_WRITE)) {
    Serial.println("open failed file 1 :(");
    return;
  }
  if (!file1.open(LOG_ALTDAT,O_WRITE)) {
    Serial.println("open failed file 2 :(");
    return;
  }
   if (!file2.open(LOG_GPS, O_WRITE)) {
    Serial.println("open failed file 3 :(");
    return;
  }
  if (!file3.open(LOG_EVERYTHING, O_WRITE)) {
    Serial.println("open failed file 4 :(");
    return;
  }
   file4.open(LOG_POWER, O_WRITE);
   
  
  if(Powermes == true){
    file4.print("Powered up at:");
    file4.print(GPS.hour); file.print(":");
    file4.print(GPS.minute);
    file4.println("--------------------------");
    file.print("Powered up at:");
    file.print(GPS.hour); file.print(":");
    file.print(GPS.minute);
    file.println("--------------------------");
    file1.print("Powered up at:");
    file1.print(GPS.hour); 
    file1.print(":");
    file1.print(GPS.minute);
    file1.println("-------------------------");
    file2.print("Powered up at:");
    file2.print(GPS.hour); 
    file2.print(":");
    file2.print(GPS.minute);
    file2.println("-------------------------");
    file3.print("Powered up at:");
    file3.print(GPS.hour); 
    file3.print(":");
    file3.print(GPS.minute);
    file3.println("------------------------");
    Powermes = false;
  }

   
  if(ready == true){
    if(onlybuzz1 == true){
      if((int)GPS.fix == 1){
        file.print("Ready for launch at  ");
        file.print(GPS.hour); 
        file.print(":");
        file.print(GPS.minute);
        file.println("  UTC");
      }else{
        file.print("Ready for launch at ");
        file.println(millis());
      }
      onlybuzz1 = false;
    }
    if(bmp.readAltitude(1013.25) >= 5.0){
      if(onlyone == true){
        if((int)GPS.fix == 1){
           file.print("Launch! at ");
            file.print(GPS.hour); 
            file.print(":");
            file.print(GPS.minute);
            file.println("  UTC");
         }else{
            file.print("Launch! at: ");
            file.println(millis());
        }
        onlyone = false;
      }
      reading1 = bmp.readAltitude(1013.25) - alt;
        unsigned long currentTime = millis();   //              launch stuff done here
       if(currentTime - previousTime >= 40){   
        reading2 = bmp.readAltitude(1013.25) - alt;
        previousTime = currentTime;
        }           
      if(reading2 - reading1 >= 3.0){
        apogge = true;
      }
      
      
    
      if(apogge == true){
        if(onlyone3 == true){
          if((int)GPS.fix == 1){
            file.print("Apogge at an altitude of: ");
            file.print(bmp.readAltitude(1013.25) - alt);
            file.print("  At ");
            file.print(GPS.hour); 
            file.print(":");
            file.print(GPS.minute);
            file.println("  UTC");
         }else{
            file.println("Apogge at an altitude of: ");
            file.print(bmp.readAltitude(1013.25) - alt);
             file.print("  At ");
            file.println(millis());
        }
        onlyone3 = false;
        }

      }



    }
  }else{
    pixels.clear();
    pixels.setPixelColor(1, pixels.Color(1, 120, 255)); // not ready yet,set MCO blue.
    pixels.show();
    if(bmp.readAltitude(1013.25) >= alt){
      alt++;
    }
    if(bmp.readAltitude(1013.25) <= alt){
      alt--;
   }
   if(bmp.readAltitude(1013.25) - alt <= 0.50){
    ready = true;
    pixels.clear();
    pixels.setPixelColor(1, pixels.Color(12, 255, 1)); // ready for launch, set MCO green.
    pixels.show();
   }
  }
  if((int)GPS.fix == 1){
    pixels.setPixelColor(0, pixels.Color(28, 255, 1)); // no gps fix, set PCI green
    pixels.show();
    if(onlybuzz12 == true){
      file.print("Got a GPS fix at  ");
      file.print(GPS.hour); 
      file.print(":");
      file.print(GPS.minute);
      file.println("  UTC");
      onlybuzz12 = false;
    }
  }else{
    pixels.setPixelColor(0, pixels.Color(255, 8, 1)); // gps got a fix, set PCI red
    pixels.show();

  }
  
if(ina260.readBusVoltage() <= 5500){
  unsigned long currentTime2 = millis(); 
       if(currentTime2 - previousTime2 >= 4000){   
          file.print("LOW VOLTAGE! VOLTAGE AT: ");
          file.print(ina260.readBusVoltage() / 1000);
          file.println(" VOLTS!");
          previousTime2 = currentTime2;
       }
} 

if((int)GPS.fix == 1){
      file4.println(GPS.hour); 
      file4.print(":");
      file4.print(GPS.minute);
      file4.print("  UTC");
}else{
   file4.print(millis());
   file4.print("   |   ");
}

file4.print(ina260.readBusVoltage() / 1000);
file4.print("  Volts");
file4.print("   |   ");
file4.print(ina260.readCurrent());
file4.print("  mA");
file4.print("   |   ");
file4.print(ina260.readPower());
file4.print("  mW");
file4.println("   |   ");


  

  file2.print(" Time: ");
  file2.print(GPS.hour);
  file2.print(":");
  file2.print(GPS.minute);
  file2.print(".");
  file2.print(GPS.seconds);
  file2.print("   |   ");
  file2.print(" Location:  ");
  file2.print(GPS.latitude, 4);
  file2.print(GPS.lat);
  file2.print(",  ");
  file2.print(GPS.longitude, 4);
  file2.print(GPS.lat);
  file2.print("   |   ");
  file2.print("  Speed (knots): ");
  file2.print(GPS.speed);
  file2.print("   |   ");
  file2.print(" Angle: ");
  file2.print(GPS.angle);
  file2.print("   |   ");
  file2.print("  Altitude(sea level): ");
  file2.print(GPS.altitude);
  file2.print("   |   ");
  file2.print(" Satellites: ");
  file2.print(GPS.satellites);
  file2.print("   |   ");
  file2.print(" Fix: ");
  file2.print((int)GPS.fix);
  file2.print("   |   ");
  file2.print(" Quality: ");
  file2.print((int)GPS.fixquality);
  file2.print("   |   ");
  file2.print(" Date: ");
  file2.print(GPS.day, DEC);
  file2.print('/');
  file2.print(GPS.month, DEC);
  file2.print("/20");
  file2.print(GPS.year, DEC);
  file2.print("   |   ");
  file2.print(" Antenna status: ");
  file2.println((int)GPS.antenna);

   
  

  
if((int)GPS.fix == 1){
            file1.print(GPS.hour); 
            file1.print(":");
            file1.print(GPS.minute);
            file1.print("  UTC");
         }else{
            file1.print(millis());
        }
        
  file1.print(" BMP390: ");
  file1.print(" Altitude: ");
  file1.print(bmp.readAltitude(1013.25) - alt);
  file1.print("  hPa ");
  file1.print(bmp.pressure / 100.0);
  file1.print(" Temp(C) ");
  file1.print(bmp.temperature);
  file1.print("   |   ");
  file1.print("MS8607: ");
  file1.print(" hPa: ");
  file1.print(pressure.pressure);
  file1.print(" Temp(C): ");
  file1.print(temp.temperature);
  file1.print(" Humidity: ");
  file1.println(humidity.relative_humidity);
  file.flush();
  file1.flush();
  file2.flush();
  file3.flush();
  file4.flush();
  //Serial.println(bmp.readAltitude(1013.25) - alt);


  
} 


The code that does work:

// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or FeatherWing)
//
// This code shows how to listen to the GPS module via polling. Best used with
// Feathers or Flora where you have hardware Serial and no interrupt
//
// Tested and works great with the Adafruit GPS FeatherWing
// ------> Adafruit Ultimate GPS FeatherWing : ID 3133 : Adafruit Industries, Unique & fun DIY electronics and kits
// or Flora GPS
// ------> Flora Wearable Ultimate GPS Module : ID 1059 : Adafruit Industries, Unique & fun DIY electronics and kits
// but also works with the shield, breakout
// ------> Adafruit Ultimate GPS Logger Shield - Includes GPS Module : ID 1272 : Adafruit Industries, Unique & fun DIY electronics and kits
// ------> Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates [PA1616S] : ID 746 : Adafruit Industries, Unique & fun DIY electronics and kits
//
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>

// what's the name of the hardware serial port?
#define GPSSerial Serial6

// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false

uint32_t timer = millis();

void setup()
{
//while (!Serial); // uncomment to have the sketch wait until Serial is ready

// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.begin(115200);
Serial.println("Adafruit GPS library basic parsing test!");

// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
// the parser doesn't care about other sentences at this time
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz

// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);

delay(1000);

// Ask for firmware version
GPSSerial.println(PMTK_Q_RELEASE);
}

void loop() // run over and over again
{
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trying to print out data
Serial.print(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}

// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
if (GPS.hour < 10) { Serial.print('0'); }
Serial.print(GPS.hour, DEC); Serial.print(':');
if (GPS.minute < 10) { Serial.print('0'); }
Serial.print(GPS.minute, DEC); Serial.print(':');
if (GPS.seconds < 10) { Serial.print('0'); }
Serial.print(GPS.seconds, DEC); Serial.print('.');
if (GPS.milliseconds < 10) {
Serial.print("00");
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
Serial.print("0");
}
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("Location: ");
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(", ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
Serial.print("Antenna status: "); Serial.println((int)GPS.antenna);
}
}
}



In my code it just outputs all the info as zero even when it has a fix, not sure what is going on. Im using a Teensy 3.6 built onto a custom pcb for my micro processor.
type or paste code here

I didn't look deeply in the code, but after the short view I would say that you have too many complex and long operations in the main loop. For example, why do you read the pressure, temperature, battery voltage in each loop cycle - and then write all this to a file on the SD? Do it once every couple of seconds, or even less often. The same about outputting the data to the screen - updating the screen more than five times in a second seems to be pointless.

In order for the GPS to work, you must read its port at least 20-40 times per second. I think that with everything you have put into the program, you read the GPS much less often

Ok, i will try to do that. The reason i log so much is that its for a model rocket flight computer so i want to get really accurate altitude readings.

That was the problem. Not sure why though, i have done more complex stuff before, i guess that gps chip is a little needy. Might also try to overclock the teensy a little to help it.

The GPS module will send data in spurts. Every second, you'll get multiple sentences from it. Then the module will be quiet until the next second ticks over. It's imperative that when the GPS is sending data that you focus on that and not logging data to several files at once on the SD card. While the core code will buffer a limited number of characters, the GPS is almost certainly going to overflow that buffer with the amount of time your code spends doing things other than keeping the buffer empty.

Consider something like this (and this is right off the top of my head so forget about the grain of salt and go right for the whole salt lick):

unsigned long lastCharRxTime = 0;
const unsigned long gpsIdleTime = 50; // delay other processing until GPS is silent for 50ms
.
.
.
void loop {
   char c = GPS.read();
   do {
      if( c ) {  // I'm assuming that if c is 0, no character was received
         lastCharRxTime = millis();
         if( GPS.newNMEAreceived() ) {
            GPS.parse(GPS.lastNMEA());
         }
      }
   } while( c );
   // here's where you can read the other sensors and make whatever determinations
   // you need
   .
   .
   .
   if( millis() - lastCharRxTime > gpsIdleTime ) {
      // the GPS has been silent for a bit, so you can now afford to go off and do
      // SOME logging
      .
      .
      .
   }

(And by the way, once you've opened a file in setup(), don't open it again every time through loop().)

That's actually a really good idea, i think i will try to implement that. Thanks for the tip.