SD card Logging issue

Hi All,

I have been using this code to log info to an SD card. However whenever i get the results back.

0.00,0.00,2.78
Sucessful Log
3VA1: 0 3.3 Volt =0.00
5VAO: 0 5 Volt =0.00
LDRA2: 464.00 LDR Volt =2.78

0.00,0.00,2.78
Sucessful Log
3VA1: 0 3.3 Volt =0.00
5VAO: 0 5 Volt =0.00
LDRA2: 464.00 LDR Volt =2.78

The Successful log statement is supposed to let me know when the SD card was successful since it comes after the close file statement. However when i look in the SD card on the computer, it never actually logs it on the SD card. Sometimes i will get error logging text file until i change the name of the file. Can someone please help me understand why i have nothing on my SD card even thought it says log sucessfull?

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

const int chipSelect = 4;
Sd2Card card;
SdVolume volume;
SdFile root;
void setup() {
  Serial.begin(9600);
  Serial.println("initializing SD Card...");
  if (!SD.begin(chipSelect)){
    Serial.println("Card Failed, or not Present");
    return;
  }
pinMode (8,OUTPUT);
}


void loop() {
  // put your main code here, to run repeatedly:

int Three = analogRead(A0);
Serial.print("3VA1: ");
Serial.print(Three);
float Three1 = Three*(3.3/683);
Serial.print("      ");
Serial.print("3.3 Volt =");
Serial.print(Three1);

int Five = analogRead(A1);
Serial.println("");
Serial.print("5VAO: ");
Serial.print(Five);
float Five1= Five* (5.0/1023.0);
Serial.print("      ");
Serial.print("  5 Volt =");
Serial.println(Five1);

float LDR = analogRead(A2);

Serial.print("");
Serial.print("LDRA2: ");
Serial.print(LDR);
float LDR1= LDR* (5.0/835.0);
Serial.print("      ");
Serial.print("  LDR Volt =");
Serial.println(LDR1);
Serial.println("");
if (LDR1 > 4.0){
     digitalWrite(8,LOW);
  }
  else{
  digitalWrite(8,HIGH);
  }


String dataString = String(Three1) + "," + String(Five1) + "," + String(LDR1);
Serial.println(dataString);

File Voltage = SD.open("vol.txt", FILE_WRITE);
if (Voltage){
  Voltage.println(dataString);
  Voltage.close();
  Serial.println("Sucessful Log");
}
else {
  Serial.println("error opening voltage.txt");
}
delay(500);
}

How can i create a new text file everytime instead?

File Voltage = SD.open("vol.txt", FILE_WRITE); ----> Do i just make vol.txt a variable?
if (Voltage){
Voltage.println(dataString);
Voltage.close();
Serial.println("Sucessful Log");

krackyz:
How can i create a new text file everytime instead?

File Voltage = SD.open("vol.txt", FILE_WRITE); ----> Do i just make vol.txt a variable?
if (Voltage){
Voltage.println(dataString);
Voltage.close();
Serial.println("Sucessful Log");

For your first question I do not know the answer because I am new at this field also. But in order to generate a new file, please refer to fat16lib reply in this thread:
http://forum.arduino.cc/index.php?topic=315571.0

Hope this help.

krackyz:
Hi All,

I have been using this code to log info to an SD card.

 pinMode (8,OUTPUT);

Have you got a good reason for doing that? I'm sure everybody else uses pin 10.