user3912: My SD card initializes fine in the beginning. It finds the right file and opens it. However, after 5 or 6 minutes of data logging, the error "file not found" appears on my LCD. Why would this be the case? I need this to work consistently for at least an hour, this 5 to 6 minutes will not do.
Also, in my code the "sv" and "cpm" data is not yet initialized, due to another problem incorporating a sensor. I left these in there, and the data is just logged as 0 for those variables.
#include <SPI.h>
#include <MPL115A1Lib.h>  // Pressure Sensor MPL115A1
#include <DHT.h>  // Temperature and Humidity Sensor RTH03
#include <U8glib.h>  // LCD Display 128x64
#include <floatToString.h>  // Converts floats to strings
#include <GPS610F.h>  // GPS-610F Module
#include <RFZuluArduino.h>  // Zulu 2km RF Module
#include <SD.h> //SD data logger

//----- Defining Modules and Variables ------//
// Pressure Sensor
MPL115A1Lib PressSens;  // Defines Pressure Sensor for library
#define FT_TO_M(x) ((long)((x)*(0.3048)))
#define KPA_TO_INHG(x) ((x)*(0.295333727))
#define KPA_TO_MMHG(x) ((x)*(7.50061683))
#define KPA_TO_PSIA(x) ((x)*(0.145037738))
#define KPA_TO_KGCM2(x) ((x)*(0.0102))
#define INHG_TO_PSIA(x) ((x)*(0.49109778))
#define DEGC_TO_DEGF(x) ((x)*(9.0/5.0)+32.0)

float press_pKa = 0;
float temp_c = 0;
long alt_ft = 0;
char charPress[7];  // Stores pressure
char charTemp[6];  // Stores temperature in C
char charAlt[5];  // Stores altitude
// Temperature & Humidity Sensor
#define DHTPIN 48     // Defines signal pin connection
#define DHTTYPE DHT22   // Defines Sensor model # DHT22 (RTH03)
DHT dht(DHTPIN, DHTTYPE);  // Defines the Temp/Humd Sensor
float t = 0;  // temp
float h = 0;  // rel. humd.
float f = 0;  // temp in f
float hi = 0;  // heat index
char rh[6];  // Stores Relative Humidity
char tempC[6];  // Stores Temperature in °C
char tempF[7];  // Stores Temp in F
char heatIndex[7];  // Stores heat index
char degree[3] = {176, 67};  // Stores °C symbol
char degreeF[3] = {176, 70};  // Stores °F symbol
// LCD Display
U8GLIB_ST7920_128X64_4X u8g(41, 42, 43);  // Defines LCD pins (SPI: EN = 41, RW = 42, RS = 43)
// GPS Module
GPS610F gps(17, 16, 28, 26, 44, 27, 9600);  // Defines GPS pins (SDI, SDO1, SDO2, PIO, PPS, RST, baudRate)
String gpsData;
char charGPS[82] = "";
String strnmeaProto;
String strutcTime;
String strgpsStatus;
String strlatitude;
String strnsIndicator;
String strlongitude;
String strewIndicator;
String strspeedOverGnd;
String strcourseOverGnd;
String strutcDate;
String strmagVarDegrees;
String strmagVarDirection;
String strmodeIndicator;
String strcheckSum;
char nmeaProto[6] = "";
char utcTime[11] = "";
char gpsStatus[2] = "";
char latitude[11] = "";
char nsIndicator[2] = "";
char longitude[11] = "";
char ewIndicator[2] = "";
char speedOverGnd[6] = "";
char courseOverGnd[6] = "";
char utcDate[7] = "";
char magVarDegrees[6] = "";
char magVarDirection[2] = "";
char modeIndicator[2] = "";
char checkSum[3] = "";
char tempTime[9] = "";
char tempDate[9] = "";
char tempLat[12] = "";
char tempLong[13] = "";
// RF Module
RFZuluArduino rf(15, 14, 2, 3, 4, 5, 4800);  // Defines the RF module's pins (rx1, tx1, RTS, CTS, RST, PD, baudRate)
//Data Logger
const int chipsSelect = 10;
File Data;
String Header = "DATE(utc)  TIME(utc)  STATUS  MODE  LATITUDE(deg)  LONGITUDE(deg)  SPEED(km)  COURSE(deg)  Temperature(C)  Temperature(F)  Humidity(%RH)  Heat Index(F)  Pressure(kPA)  Altitude(m"; //CPM  uSV/hr";
int dcounter = 0;
//Geiger Counter
unsigned int gcount = 0;
unsigned int countStartTime = 0;
int countsPerMinute;
float coefficientOfConversion = 140.0 / 60000.0;
float sV = 0;
String str;  // temporary string
int draw_state = 0;
int tracker = 0;

void setup() {
  pinMode(53, OUTPUT);
  dht.begin();
  if (!SD.begin(10, 11, 12, 13)) {
    // see if the card is present and can be initialized:
    u8g.firstPage();
    do {
      drawCardError();
    }
    while (u8g.nextPage());
    while (1);  // don't do anything more:
  }
  Serial1.begin(9600);
  // start serial port for geiger counter
}

void loop() {
  delay(1000);
  //----- Get Sensor Data -----//
  // Temp/Humid
  h = dht.readHumidity();
  t = dht.readTemperature();
  f = dht.readTemperature(true);
  /*if (isnan(h) || isnan(t) || isnan(f)) {  // check for failed reading from sensor
    return;
    }*/
  hi = dht.computeHeatIndex(f, h);
  // Pressure Sensor
  press_pKa = PressSens.calculatePressurekPa();
  alt_ft = PressSens.calculateAltitudeFt(press_pKa);
  // GPS
  gpsData = gps.getData();
  strnmeaProto = gps.dataFields(0);
  strutcTime = gps.dataFields(1);
  strgpsStatus = gps.dataFields(2);
  strlatitude = gps.dataFields(3);
  strnsIndicator = gps.dataFields(4);
  strlongitude = gps.dataFields(5);
  strewIndicator = gps.dataFields(6);
  strspeedOverGnd = gps.dataFields(7);
  strcourseOverGnd = gps.dataFields(8);
  strutcDate = gps.dataFields(9);
  strmagVarDegrees = gps.dataFields(10);
  strmagVarDirection = gps.dataFields(11);
  strmodeIndicator = gps.dataFields(12);
  strcheckSum = gps.dataFields(13);

  //----- Convert to Transmit -----//
  // Temp/Humid
  floatToString(rh, h, 1);  // relative humidity
  floatToString(tempC, t, 1);  // temperature in C
  floatToString(tempF, f, 1);  // temp in F
  floatToString(heatIndex, hi, 1);  // heat index
  // Pressure Sensor
  str = String(FT_TO_M(alt_ft));  // convert altitude in ft to m
  str.toCharArray(charAlt, 5);  // covert string to char array
  floatToString(charPress, press_pKa, 2);
  // GPS Module
  gpsData.toCharArray(charGPS, 80);  // convert string to char array
  strnmeaProto.toCharArray(nmeaProto, 6);
  // time
  strutcTime.toCharArray(utcTime, 11);
  tempTime[0] = utcTime[0];
  tempTime[1] = utcTime[1];
  tempTime[2] = ':';
  tempTime[3] = utcTime[2];
  tempTime[4] = utcTime[3];
  tempTime[5] = ':';
  tempTime[6] = utcTime[4];
  tempTime[7] = utcTime[5];
  strgpsStatus.toCharArray(gpsStatus, 2);
  // latitude
  strlatitude.toCharArray(latitude, 11);
  strnsIndicator.toCharArray(nsIndicator, 2);
  tempLat[0] = latitude[0];
  tempLat[1] = latitude[1];
  tempLat[2] = 176;   // °
  tempLat[3] = latitude[2];
  tempLat[4] = latitude[3];
  tempLat[5] = latitude[4];
  tempLat[6] = latitude[5];
  tempLat[7] = latitude[6];
  tempLat[8] = 39;  // '
  tempLat[9] = ' ';
  tempLat[10] = nsIndicator[0];
  // longitude
  strlongitude.toCharArray(longitude, 11);
  strewIndicator.toCharArray(ewIndicator, 2);
  tempLong[0] = longitude[0];
  tempLong[1] = longitude[1];
  tempLong[2] = longitude[2];
  tempLong[3] = 176;   // °
  tempLong[4] = longitude[3];
  tempLong[5] = longitude[4];
  tempLong[6] = longitude[5];
  tempLong[7] = longitude[6];
  tempLong[8] = longitude[7];
  tempLong[9] = 39;  // '
  tempLong[10] = ' ';
  tempLong[11] = ewIndicator[0];
  strspeedOverGnd.toCharArray(speedOverGnd, 6);
  strcourseOverGnd.toCharArray(courseOverGnd, 6);
  // date
  strutcDate.toCharArray(utcDate, 7);
  tempDate[0] = utcDate[0];
  tempDate[1] = utcDate[1];
  tempDate[2] = '/';
  tempDate[3] = utcDate[2];
  tempDate[4] = utcDate[3];
  tempDate[5] = '/';
  tempDate[6] = utcDate[4];
  tempDate[7] = utcDate[5];
  strmagVarDegrees.toCharArray(magVarDegrees, 6);
  strmagVarDirection.toCharArray(magVarDirection, 2);
  strmodeIndicator.toCharArray(modeIndicator, 2);
  strcheckSum.toCharArray(checkSum, 3);
  // transmit the data
  rf.transmit(gpsData, tempC, rh, charPress);
  //-----Writes Data to SD Card-----//
  Data = SD.open("DATA", FILE_WRITE);
  if (!Data) {
    u8g.firstPage();
    do {
      drawFileError();
    }
    while (u8g.nextPage());
    while (1);  // don't do anything more:
  }
  dcounter++;
  if (dcounter == 1) {
    Data.println(Header);
  }
  Data.print(strutcDate + "     " + strutcTime + "   " + strgpsStatus + "      " + strmodeIndicator + "     " + strlatitude + "     " + strlongitude + "     " + strspeedOverGnd + "        " + strcourseOverGnd + "          ");
  Data.print(t);
  Data.print("          ");
  Data.print(f);
  Data.print("            ");
  Data.print(h);
  Data.print("         ");
  Data.print(hi);
  Data.print("            ");
  Data.print(press_pKa);
  Data.print("         " + str + "  ");
  Data.flush();
  Data.print(countsPerMinute);
  Data.print("  ");
  Data.println(sV, 5);
  Data.flush();
  //----- Output to LCD Display -----//
  u8g.firstPage();
  do {
    draw();
  }
  while (u8g.nextPage());
  tracker++;
  if (tracker <= 2) {
    draw_state = 0;
  } else if (tracker <= 5) {
    draw_state = 1;
  } else if (tracker <= 8) {
    draw_state = 2;
  } else {
    tracker = 3;
  }
}

//----- LCD Display Drawings -----//
void drawCardError() {
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(12, 32, "Card Failed, or not present");
}

void drawFileError() {
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(5, 32, "Error opening DATA");
}

void draw(void) {
  LCDprepare();
  switch (draw_state) {
    case 0:
      AECLlogo();
      break;
    case 1:
      SensorInfo();
      break;
    case 2:
      GpsInfo();
      break;
  }
}


user15819: Might be a flaky SD card, you get that sometimes. Try changing to another card and see if it helps.
SD card formatter tool might also be useful: https://www.sdcard.org/downloads/formatter_4/

3912: <p>My SD card initializes fine in the beginning. It finds the right file and opens it. However, after 5 or 6 minutes of data logging, the error "file not found" appears on my LCD. Why would this be the case? I need this to work consistently for at least an hour, this 5 to 6 minutes will not do.</p>

<p>Also, in my code the "sv" and "cpm" data is not yet initialized, due to another problem incorporating a sensor. I left these in there, and the data is just logged as 0 for those variables.</p>

<pre><code>#include &lt;SPI.h&gt;
#include &lt;MPL115A1Lib.h&gt;  // Pressure Sensor MPL115A1
#include &lt;DHT.h&gt;  // Temperature and Humidity Sensor RTH03
#include &lt;U8glib.h&gt;  // LCD Display 128x64
#include &lt;floatToString.h&gt;  // Converts floats to strings
#include &lt;GPS610F.h&gt;  // GPS-610F Module
#include &lt;RFZuluArduino.h&gt;  // Zulu 2km RF Module
#include &lt;SD.h&gt; //SD data logger

//----- Defining Modules and Variables ------//
// Pressure Sensor
MPL115A1Lib PressSens;  // Defines Pressure Sensor for library
#define FT_TO_M(x) ((long)((x)*(0.3048)))
#define KPA_TO_INHG(x) ((x)*(0.295333727))
#define KPA_TO_MMHG(x) ((x)*(7.50061683))
#define KPA_TO_PSIA(x) ((x)*(0.145037738))
#define KPA_TO_KGCM2(x) ((x)*(0.0102))
#define INHG_TO_PSIA(x) ((x)*(0.49109778))
#define DEGC_TO_DEGF(x) ((x)*(9.0/5.0)+32.0)

float press_pKa = 0;
float temp_c = 0;
long alt_ft = 0;
char charPress[7];  // Stores pressure
char charTemp[6];  // Stores temperature in C
char charAlt[5];  // Stores altitude
// Temperature &amp; Humidity Sensor
#define DHTPIN 48     // Defines signal pin connection
#define DHTTYPE DHT22   // Defines Sensor model # DHT22 (RTH03)
DHT dht(DHTPIN, DHTTYPE);  // Defines the Temp/Humd Sensor
float t = 0;  // temp
float h = 0;  // rel. humd.
float f = 0;  // temp in f
float hi = 0;  // heat index
char rh[6];  // Stores Relative Humidity
char tempC[6];  // Stores Temperature in °C
char tempF[7];  // Stores Temp in F
char heatIndex[7];  // Stores heat index
char degree[3] = {176, 67};  // Stores °C symbol
char degreeF[3] = {176, 70};  // Stores °F symbol
// LCD Display
U8GLIB_ST7920_128X64_4X u8g(41, 42, 43);  // Defines LCD pins (SPI: EN = 41, RW = 42, RS = 43)
// GPS Module
GPS610F gps(17, 16, 28, 26, 44, 27, 9600);  // Defines GPS pins (SDI, SDO1, SDO2, PIO, PPS, RST, baudRate)
String gpsData;
char charGPS[82] = "";
String strnmeaProto;
String strutcTime;
String strgpsStatus;
String strlatitude;
String strnsIndicator;
String strlongitude;
String strewIndicator;
String strspeedOverGnd;
String strcourseOverGnd;
String strutcDate;
String strmagVarDegrees;
String strmagVarDirection;
String strmodeIndicator;
String strcheckSum;
char nmeaProto[6] = "";
char utcTime[11] = "";
char gpsStatus[2] = "";
char latitude[11] = "";
char nsIndicator[2] = "";
char longitude[11] = "";
char ewIndicator[2] = "";
char speedOverGnd[6] = "";
char courseOverGnd[6] = "";
char utcDate[7] = "";
char magVarDegrees[6] = "";
char magVarDirection[2] = "";
char modeIndicator[2] = "";
char checkSum[3] = "";
char tempTime[9] = "";
char tempDate[9] = "";
char tempLat[12] = "";
char tempLong[13] = "";
// RF Module
RFZuluArduino rf(15, 14, 2, 3, 4, 5, 4800);  // Defines the RF module's pins (rx1, tx1, RTS, CTS, RST, PD, baudRate)
//Data Logger
const int chipsSelect = 10;
File Data;
String Header = "DATE(utc)  TIME(utc)  STATUS  MODE  LATITUDE(deg)  LONGITUDE(deg)  SPEED(km)  COURSE(deg)  Temperature(C)  Temperature(F)  Humidity(%RH)  Heat Index(F)  Pressure(kPA)  Altitude(m"; //CPM  uSV/hr";
int dcounter = 0;
//Geiger Counter
unsigned int gcount = 0;
unsigned int countStartTime = 0;
int countsPerMinute;
float coefficientOfConversion = 140.0 / 60000.0;
float sV = 0;
String str;  // temporary string
int draw_state = 0;
int tracker = 0;

void setup() {
  pinMode(53, OUTPUT);
  dht.begin();
  if (!SD.begin(10, 11, 12, 13)) {
    // see if the card is present and can be initialized:
    u8g.firstPage();
    do {
      drawCardError();
    }
    while (u8g.nextPage());
    while (1);  // don't do anything more:
  }
  Serial1.begin(9600);
  // start serial port for geiger counter
}

void loop() {
  delay(1000);
  //----- Get Sensor Data -----//
  // Temp/Humid
  h = dht.readHumidity();
  t = dht.readTemperature();
  f = dht.readTemperature(true);
  /*if (isnan(h) || isnan(t) || isnan(f)) {  // check for failed reading from sensor
    return;
    }*/
  hi = dht.computeHeatIndex(f, h);
  // Pressure Sensor
  press_pKa = PressSens.calculatePressurekPa();
  alt_ft = PressSens.calculateAltitudeFt(press_pKa);
  // GPS
  gpsData = gps.getData();
  strnmeaProto = gps.dataFields(0);
  strutcTime = gps.dataFields(1);
  strgpsStatus = gps.dataFields(2);
  strlatitude = gps.dataFields(3);
  strnsIndicator = gps.dataFields(4);
  strlongitude = gps.dataFields(5);
  strewIndicator = gps.dataFields(6);
  strspeedOverGnd = gps.dataFields(7);
  strcourseOverGnd = gps.dataFields(8);
  strutcDate = gps.dataFields(9);
  strmagVarDegrees = gps.dataFields(10);
  strmagVarDirection = gps.dataFields(11);
  strmodeIndicator = gps.dataFields(12);
  strcheckSum = gps.dataFields(13);

  //----- Convert to Transmit -----//
  // Temp/Humid
  floatToString(rh, h, 1);  // relative humidity
  floatToString(tempC, t, 1);  // temperature in C
  floatToString(tempF, f, 1);  // temp in F
  floatToString(heatIndex, hi, 1);  // heat index
  // Pressure Sensor
  str = String(FT_TO_M(alt_ft));  // convert altitude in ft to m
  str.toCharArray(charAlt, 5);  // covert string to char array
  floatToString(charPress, press_pKa, 2);
  // GPS Module
  gpsData.toCharArray(charGPS, 80);  // convert string to char array
  strnmeaProto.toCharArray(nmeaProto, 6);
  // time
  strutcTime.toCharArray(utcTime, 11);
  tempTime[0] = utcTime[0];
  tempTime[1] = utcTime[1];
  tempTime[2] = ':';
  tempTime[3] = utcTime[2];
  tempTime[4] = utcTime[3];
  tempTime[5] = ':';
  tempTime[6] = utcTime[4];
  tempTime[7] = utcTime[5];
  strgpsStatus.toCharArray(gpsStatus, 2);
  // latitude
  strlatitude.toCharArray(latitude, 11);
  strnsIndicator.toCharArray(nsIndicator, 2);
  tempLat[0] = latitude[0];
  tempLat[1] = latitude[1];
  tempLat[2] = 176;   // °
  tempLat[3] = latitude[2];
  tempLat[4] = latitude[3];
  tempLat[5] = latitude[4];
  tempLat[6] = latitude[5];
  tempLat[7] = latitude[6];
  tempLat[8] = 39;  // '
  tempLat[9] = ' ';
  tempLat[10] = nsIndicator[0];
  // longitude
  strlongitude.toCharArray(longitude, 11);
  strewIndicator.toCharArray(ewIndicator, 2);
  tempLong[0] = longitude[0];
  tempLong[1] = longitude[1];
  tempLong[2] = longitude[2];
  tempLong[3] = 176;   // °
  tempLong[4] = longitude[3];
  tempLong[5] = longitude[4];
  tempLong[6] = longitude[5];
  tempLong[7] = longitude[6];
  tempLong[8] = longitude[7];
  tempLong[9] = 39;  // '
  tempLong[10] = ' ';
  tempLong[11] = ewIndicator[0];
  strspeedOverGnd.toCharArray(speedOverGnd, 6);
  strcourseOverGnd.toCharArray(courseOverGnd, 6);
  // date
  strutcDate.toCharArray(utcDate, 7);
  tempDate[0] = utcDate[0];
  tempDate[1] = utcDate[1];
  tempDate[2] = '/';
  tempDate[3] = utcDate[2];
  tempDate[4] = utcDate[3];
  tempDate[5] = '/';
  tempDate[6] = utcDate[4];
  tempDate[7] = utcDate[5];
  strmagVarDegrees.toCharArray(magVarDegrees, 6);
  strmagVarDirection.toCharArray(magVarDirection, 2);
  strmodeIndicator.toCharArray(modeIndicator, 2);
  strcheckSum.toCharArray(checkSum, 3);
  // transmit the data
  rf.transmit(gpsData, tempC, rh, charPress);
  //-----Writes Data to SD Card-----//
  Data = SD.open("DATA", FILE_WRITE);
  if (!Data) {
    u8g.firstPage();
    do {
      drawFileError();
    }
    while (u8g.nextPage());
    while (1);  // don't do anything more:
  }
  dcounter++;
  if (dcounter == 1) {
    Data.println(Header);
  }
  Data.print(strutcDate + "     " + strutcTime + "   " + strgpsStatus + "      " + strmodeIndicator + "     " + strlatitude + "     " + strlongitude + "     " + strspeedOverGnd + "        " + strcourseOverGnd + "          ");
  Data.print(t);
  Data.print("          ");
  Data.print(f);
  Data.print("            ");
  Data.print(h);
  Data.print("         ");
  Data.print(hi);
  Data.print("            ");
  Data.print(press_pKa);
  Data.print("         " + str + "  ");
  Data.flush();
  Data.print(countsPerMinute);
  Data.print("  ");
  Data.println(sV, 5);
  Data.flush();
  //----- Output to LCD Display -----//
  u8g.firstPage();
  do {
    draw();
  }
  while (u8g.nextPage());
  tracker++;
  if (tracker &lt;= 2) {
    draw_state = 0;
  } else if (tracker &lt;= 5) {
    draw_state = 1;
  } else if (tracker &lt;= 8) {
    draw_state = 2;
  } else {
    tracker = 3;
  }
}

//----- LCD Display Drawings -----//
void drawCardError() {
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(12, 32, "Card Failed, or not present");
}

void drawFileError() {
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(5, 32, "Error opening DATA");
}

void draw(void) {
  LCDprepare();
  switch (draw_state) {
    case 0:
      AECLlogo();
      break;
    case 1:
      SensorInfo();
      break;
    case 2:
      GpsInfo();
      break;
  }
}
</code></pre>
 15819: <p>Might be a flaky SD card, you get that sometimes. Try changing to another card and see if it helps.</p>

<p>SD card formatter tool might also be useful: <a href="https://www.sdcard.org/downloads/formatter_4/" rel="nofollow noreferrer">https://www.sdcard.org/downloads/formatter_4/</a></p>
