Can't open SD card for write

Hi all,

I’ve been stuck on a problem for many hours now, and I could really use some insight into what is going wrong!

I am simply trying to log temperature and humidity data from a SHT15 sensor, onto a microSD card. I am using the microSD adapter from the pjrc shop and I have double checked that the wiring is correct to the Teensy.

I’ve narrowed down the problem to: The sensor is doing something that is causing the SD card to be unable to open the file I am trying to write in. After the sensor does it’s thing, myFile = SD.open(“text.txt”, FILE_WRITE), turns out to be false and I’m not sure why that is. The SD card logs fine with all my other sensors. My code is below:

#include <SHT1X.h>
#include <SPI.h>
#include <SD.h>

File myFile;
//variables for storing values
float tempC = 0;
float tempF = 0;
float humidity = 0;

String dataStr = "";
//Create an instance of the SHT1X sensor
SHT1x sht15(A1, 13);//Data, SCK


void setup()
{
  Serial.begin(9600); // Open serial connection to report values to host
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}
//-------------------------------------------------------------------------------------------
void loop()
{
  myFile = SD.open("test.txt", FILE_WRITE);
  Serial.print("myFile1 = ");
  Serial.println(myFile);
  readSensor();
  printOut();
  
  dataStr += tempF;
  dataStr += " ";
  dataStr += tempC;
  dataStr += " ";
  dataStr += humidity;
  dataStr += " ";
//  Serial.println(dataStr);
  
  
  Serial.print("myFile2 = ");
  Serial.println(myFile);
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println(dataStr);
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
    delay(1000);
  }
}
  //-------------------------------------------------------------------------------------------
  void readSensor()
  {
    // Read values from the sensor
    tempC = sht15.readTemperatureC();
    tempF = sht15.readTemperatureF();
    humidity = sht15.readHumidity();
  }
  //-------------------------------------------------------------------------------------------
  void printOut()
  {
    Serial.print(" Temp = ");
    Serial.print(tempF);
    Serial.print("F, ");
    Serial.print(tempC);
    Serial.println("C");
    Serial.print(" Humidity = ");
    Serial.print(humidity);
    Serial.println("%");

Thank you for your help in advance!

-AG

// File myFile; (comment this)
//variables for storing values

//-------------------------------------------------------------------------------------------
void loop()
{
File myFile = SD.open("test.txt", FILE_WRITE); // add the 'File' here
Serial.print("myFile1 = ");
...
...
}