I Could Use Some Help (Reading .ini setting file from SD Card)

I have been working on a data logger project (Temp, Humidity, Light and Current) (using the Adafruit Data Logger Sheild) for about 3 weeks now, and everything was going very well, until I decided to add a settings .ini file "feature".

Out of that 3 weeks I've spent at least a week trying to figure out what and where my problem is, as the same code that pertains to grabbing the information from the .ini works perfect when everything else is stripped out.

The work is based on Steve Marple's work, and modified for use with the SD Reader Only. (I just removed the stuff for the Ethernet Card)

I have attached the modified source files.

The issues I have are:

  1. Most of the time the ini.open fails, but on occasion it returns true but when it does...

  2. Either ini.validate fails OR just a bunch of gibberish in the serial monitor OR my IniSDCard() functions keeps repeating over and over again OR other functions just simply don't work correctly.

Here is my entire program, somewhere there is a conflict that I cannot find for the life of me.

(The I have also posted the code that works every single time below this one)

IniFile.zip (16.2 KB)

The sketch was too big to post so I had to attach it. I hope that is Ok..

EDIT: Forgot to add the settings.ini file... Attached

ReferationDataLogger.pde (11.9 KB)

settings.zip (369 Bytes)

This work perfectly every single time..

So I just don't know why my does not...

#include <SD.h>
#include <IniFile.h>
// The select pin used for the SD card
#define SD_SELECT 10
long WO_UnderTest;
long Equip_Voltage;
void setup()
{
  // Configure all of the SPI select pins as outputs and make SPI
  // devices inactive, otherwise the earlier init routines may fail
  // for devices which have not yet been configured.
  pinMode(SD_SELECT, OUTPUT);
  
  const size_t bufferLen = 80;
  char buffer[bufferLen];

  const char *filename = "/settings.ini";
  Serial.begin(115200);
  if (!SD.begin(SD_SELECT))
    while (1)
      Serial.println("SD.begin() failed");
  
 IniFile ini(filename);
 if (!ini.open()) {
 Serial.print("Ini file ");
 Serial.print(filename);
 Serial.println(" does not exist");
 //error("Ini Setting File Does NOt Exist");
 }
 Serial.println("Ini file exists");

 // Check the file is valid. This can be used to warn if any lines
 // are longer than the buffer.
 if (!ini.validate(buffer, bufferLen)) {
 Serial.print("ini file ");
 Serial.print(ini.getFilename());
 Serial.print(" not valid: ");
 //error("Setting File Is Not Valid");
 }
 
  // Fetch a value from a key which is present
  ini.getValue("Job Site Info", "WO", buffer, bufferLen,WO_UnderTest);
  Serial.println(WO_UnderTest);
  
  ini.getValue("Sensors", "Voltage", buffer, bufferLen,Equip_Voltage);
  Serial.println(Equip_Voltage);
  
  ini.close();
  
}
void loop()
{


}
String DateTimeStamp;

Quit pissing away the limited resources that you have.

Keep string literals out of SRAM:
Serial.print(F("Initializing SD card..."));

http://playground.arduino.cc/Code/AvailableMemory