i need a solution

I have problems with my project. where the values ​​set forth in excel can not be well ordered in the column.
My question is how to organize and segregate the data values ​​in the column Excel.?

#include <SD.h>
File myFile;
const int chipSelect=10;

int dat1=A0;
int dat2=A1;
int data1=0;
int data2=0;
int i=0;
boolean present=0;
void setup()
{
  pinMode(dat1,INPUT);
  pinMode(dat2,INPUT);
  Serial.begin(9600);
  checkSD();
  // Write label Excel
  myFile = SD.open("nilai.csv", FILE_WRITE);
  if(myFile)
  {
    myFile.print("line");
    myFile.print(",");
    myFile.print("data1");
    myFile.print(",");
    myFile.println("data2");
    myFile.close();
  }
}
void loop()
{
  if(present==1)
  {
    i++;
    data1=analogRead(dat1);
    data2=analogRead(dat2);
    Serial.print("Val1 : ");
    Serial.print(data1);
    Serial.print("    ");
    Serial.print("Val2 : ");
    Serial.println(data2);
    writeSD();
  }
  delay(200);
}

void checkSD()
{
  Serial.println("check SD card");
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed");
    return;
  }
  Serial.println("SD card OK");
  present=1;
  delay(2000);
}
void writeSD()
{
  myFile = SD.open("nilai.csv", FILE_WRITE);
  if(myFile)
  {
    myFile.print(i);
    myFile.print(",");
    myFile.print(data1);
    myFile.print(",");
    myFile.println(data2);
    myFile.close();
    
  }
}

Hi,

Should be used ';' as separator. Adding the semi-colon to the end of the value will help you.

ucd18:
Hi,

Should be used ';' as separator. Adding the semi-colon to the end of the value will help you.

I've tried but still,
You can give an example..?
thank you responses

You just need to set excel to use comma as the delimiter. You could use a different delimiter but your current sketch will work fine. The "C" in .csv stands for "comma" after all. There is another problem that you're adding the column headings to the file every time the sketch runs. You should only do that once after nilai.csv is first created. Really you don't even need to do that in your sketch. You could just manually create the file on the SD card and add the heading text at that time. If you want to do it in your sketch then use SD.exists() to check if the file exists before opening it and then only write the column headings if the file didn't already exist(open() will create the file if it doesn't exist).

Please don't double post.

.

LarryD:
Please don't double post.

.

sorry i was very confused :C

pert:
You just need to set excel to use comma as the delimiter. You could use a different delimiter but your current sketch will work fine. The "C" in .csv stands for "comma" after all. There is another problem that you're adding the column headings to the file every time the sketch runs. You should only do that once after nilai.csv is first created. Really you don't even need to do that in your sketch. You could just manually create the file on the SD card and add the heading text at that time. If you want to do it in your sketch then use SD.exists() to check if the file exists before opening it and then only write the column headings if the file didn't already exist(open() will create the file if it doesn't exist).

What is an example of SD.exists() to check if the file exists before opening it and then only write the column headings if the file didn't already exist(open() will create the file if it doesn't exist).?

thanks

if (SD.exists("nilai.csv") == false) {  //the file doesn't already exist
  myFile = SD.open("nilai.csv", FILE_WRITE);  //create and open the file
  //add the column headings
  myFile.print("line");
  myFile.print(",");
  myFile.print("data1");
  myFile.print(",");
  myFile.println("data2");
  myFile.close();
}

This is pretty basic stuff. I recommend you study the SD library reference:

Hi,
Can you post a copy of a dump from the your SD card that you want to import into Excel?

Thanks.. Tom.. :slight_smile:

Already asked in the other thread. Needs to be as an attachment so we have the exact file.