[SOLVED] Data not writing to SD Card

[SOLVED] - Based on the advice of a few different people I slowly took the code apart and tested each part individually before plugging sections back in. I also tested the code on new sensors individually after seeing it working, I made a new wiring harness and retested. Worked perfectly!

Hey, I’m trying to write a sketch that will pull data from a BME280 and ADXL345 and then write that data to an SD card. Using different sketches I’ve found online I got something that I think should work, but isn’t and I’m not sure what the issue is. Another issue I’m having is my BME sensor not working. I’ve got both sensors connected on a FeatherWing Proto as follows

Feather ADXL345 BME
SCL ------> SCL-------> SCK
SDA------> SDA-------> SDI
3V-------> VIN-------> VIN
GND-----> GND------> GND
3V-------> CS

Any insight as to where I went wrong would be greatly appreciated!

Hardware specs:
1x Feather M0 Adalogger
1x ADXL345
1x BME280
1x FeatherWing Proto

#include <SdFat.h>                 // SD card library
#include <Wire.h>               // I2C wire lbrary
#include <Adafruit_BME280.h>    // Pressure Sensor library
#include <Adafruit_Sensor.h>    // Adafruit Sensor library
#include <Adafruit_ADXL345_U.h> // ADXL345 library

#define SEALEVELPRESSURE_HPA (1013.25)
#define RANGE_2_G 0;

int chipSelect = 4;
float hgInches = 29.97;

SdFat SD;
Adafruit_BME280 bme;
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);


void setup() {
        //turn on serial monitor
        Serial.begin(9600);
        while (!Serial){
          ;
        }// end while - serial
        
        // initialize I2C bus
        Wire.begin();

        bool status;
        //initialize BME sensor
        status =  bme.begin();
        if (!status) {
                Serial.println("No BME");
                while (1);
        } // end if - BME

        //initialize ADXL sensor, range and data rate
        status = accel.begin();
        accel.setRange( ADXL345_RANGE_2_G );
        accel.setDataRate( ADXL345_DATARATE_50_HZ );
        if (!status) {
                Serial.println("No ADXL");
                while (1);
        } // end if - accel

        // initialize the SD card
        Serial.print("Looking for SD: ");
        if (!SD.begin(chipSelect)) {
                Serial.println("SD not found ");
                return;
        } // end if - SD
        Serial.println(" SD found");
        // print a header in HAB Flight Data.txt
        File flightData = SD.open("HAB Flight Data.txt", FILE_WRITE);
        if (flightData) {
                flightData.print("HAB FLight Data");
                flightData.println("Temperature, Pressure, Altitude, Humidity, X-Axis, Y-Axis, Z-Axis");
                flightData.println("_________________________________________________________________");
                flightData.close();
        } //end if - flightdata
} // end main setup

void loop() {
        //var to hold sensor data
        float BMEt1 = (bme.readTemperature());
        float BMEh1 = (bme.readHumidity());
        float BMEp1 = (bme.readPressure() / 100.0F);
        float BMEa1 = (bme.readAltitude(SEALEVELPRESSURE_HPA));
        // register events for ADXL
        sensors_event_t event;
        accel.getEvent(&event);

        // print out BME data to serial monitor
        Serial.println("BME Data.");
        Serial.print("Temperature = "); Serial.print(BMEt1); Serial.println(" *F");
        Serial.print("Pressure = "); Serial.print(BMEp1); Serial.println(" hPa");
        Serial.print("Approx. Altitude = "); Serial.print(BMEa1); Serial.println(" meters");
        Serial.print("Humidity = "); Serial.print(BMEh1); Serial.println(" %");

        // print out ADXL data to serial monitor
        Serial.println("Accelerometer Data");
        Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
        Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
        Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");

        delay(1000); //Pause between readings.

        // Create a txt file adn record data
        File flightData = SD.open("HAB Flight Data.txt", FILE_WRITE);
        if (flightData) {
                flightData.print(BMEt1); flightData.print(","); flightData.print(BMEp1); flightData.print(",");
                flightData.print(BMEa1); flightData.print(","); flightData.print(BMEh1); flightData.print(",");
                flightData.println("X: "); flightData.print(event.acceleration.x); flightData.print(",");
                flightData.println("Y: "); flightData.print(event.acceleration.y); flightData.print(",");
                flightData.println("Z: "); flightData.print(event.acceleration.z); flightData.print(",");
                flightData.close();
        } //  end if - data recorder
        else {
                Serial.println("error opening HAB Flight Data.txt");
        } // end else - SD error

} //end Main loop

I'm missing the links to the used boards (I strongly guess you don't use the chips directly).

What output do you get? What does "not work" mean?

File flightData = SD.open("HAB Flight Data.txt", FILE_WRITE);

The SD library implements only a FAT file system, no extensions to it. That means you are limited to the 8.3 file name restriction as in the old MSDOS ages (I don't know if you're old enough to remember).