   //Initialize SD card reader
   Serial.print("Initializing SD card...");
 
-  if (!SD.begin(chipSelect)) {
+  while (!SD.begin(chipSelect)) {
 
     Serial.println("Card failed, or not present");
     return;

    received_from_sensor = ecSerial.readBytesUntil(13, EC_data, 48);
    EC_data[received_from_sensor] = 0; // Null terminate the data by setting the value after the final character to 0.

  }

  if ((EC_data[0] >= 48) && (EC_data[0] <= 57)) { // Parse data, if EC_data begins with a digit, not a letter (testing ASCII values).

    parse_data();

  }

  //output readings to serial monitor. A whole mess of if/else statements to keep numbers formatted correctly
  Serial.print(now.year(), DEC);
  Serial.print('/');

  if (now.month() < 10) {

    Serial.print(0);
    Serial.print(now.month(), DEC);

  }

  else {

    Serial.print(now.month(), DEC);

  }

  Serial.print('/');

  if (now.day() < 10) {

    Serial.print(0);
    Serial.print(now.day(), DEC);

  }

  else {

    Serial.print(now.day(), DEC);

  }

  Serial.print("  ");

  if (now.hour() < 10) {

    Serial.print(0);
    Serial.print(now.hour(), DEC);

  }

  else {

    Serial.print(now.hour(), DEC);

  }

  Serial.print(':');

  if (now.minute() < 10) {

    Serial.print(0);
    Serial.print(now.minute(), DEC);

  }

  else {

    Serial.print(now.minute(), DEC);

  }

  Serial.print(':');

  if (now.second() < 10) {

    Serial.print(0);
    Serial.print(now.second(), DEC);

  }

  else {

    Serial.print(now.second(), DEC);

  }

  Serial.print("  ");
  Serial.print(pressure_abs);
  Serial.print("  ");
  Serial.print(tempA);
  Serial.print("  ");
  Serial.print(tempB);
  Serial.print("  ");
  Serial.print(tempC);
  Serial.print("  ");
  Serial.println(EC);

  //output readings to data file. A whole mess of if/else statements to keep numbers formatted correctly
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (dataFile) {

    dataFile.print(now.year(), DEC);
    dataFile.print('/');

    if (now.month() < 10) {

      dataFile.print(0);
      dataFile.print(now.month(), DEC);

    }

    else {

      dataFile.print(now.month(), DEC);

    }

    dataFile.print('/');

    if (now.day() < 10) {

      dataFile.print(0);
      dataFile.print(now.day(), DEC);

    }

    else {

      dataFile.print(now.day(), DEC);

    }

    dataFile.print("  ");

    if (now.hour() < 10) {

      dataFile.print(0);
      dataFile.print(now.hour(), DEC);

    }

    else {

      dataFile.print(now.hour(), DEC);

    }

    dataFile.print(':');

    if (now.minute() < 10) {

      dataFile.print(0);
      dataFile.print(now.minute(), DEC);

    }

    else {

      dataFile.print(now.minute(), DEC);

    }

    dataFile.print(':');

    if (now.second() < 10) {

      dataFile.print(0);
      dataFile.print(now.second(), DEC);

    }

    else {

      dataFile.print(now.second(), DEC);

    }

    dataFile.print("  ");
    dataFile.print(pressure_abs);
    dataFile.print("  ");
    dataFile.print(tempA);
    dataFile.print("  ");
    dataFile.print(tempB);
    dataFile.print("  ");
    dataFile.print(tempC);
    dataFile.print("  ");
    dataFile.println(EC);
    dataFile.close();

  }

  delay(50);

}



const int chipSelect = 4; //sets chip select pin for SD card reader

/* This integer specifies how high accuracy you want your pressure sensor to be (oversampling resolution).
 * Ok values: 256, 512, 1024, 2048, or 4096 (Higher = more accuracy but slower sampling frequency**)
 * ** There is no reason not to use the highest accuracy. This is because the datalogging rate is set by the
 * sampling/response frequency of the ec sensor [default = 1 sec] (this is to avoid the case where both sensors send data at the same time). */
#define PRESSURE_SENSOR_RESOLUTION 4096
MS_5803 sensor = MS_5803(PRESSURE_SENSOR_RESOLUTION); // Define pressure sensor.

OneWire oneWire(6); // Define the OneWire port for temperature.
DallasTemperature sensors(&oneWire); //Define DallasTemperature input based on OneWire.
