SD data formating

He did in .txt file

Yes, but he had every piece of data available each time he wrote a line which you don't.

I you are happy to have blanks in columns 2, 3 and 4 with switch 1 data is in column 1, spaces in 1, 3, and 4 with switch 2 data in column 2 and so on you can do that

Hi Bob,

I can try that. It is also learning new codes, not much about formatting.

Please give me hints, how to proceed with spaces between column. I will try to take it from there.

Please give me hints, how to proceed with spaces between column. I will try to take it from there.

If you mean leaving blanks for switches where no data is being read then you need to do something like this

if switch 1 is closed
  read 1 data item for switch 1
  write data to SD
  write ,,, to SD  //3 blank columns
  write a new line to SD
else
if switch 2 is closed
  read 1 data item for switch 2
  write , to SD //1 blank column
  write data to SD
  write ,, to SD  //2 blank columns
  write a new line to SD
else
if switch 3 is closed
  read 1 data item for switch 3
  write ,, to SD  //2 blank columns to file
  write data to SD
  write , to SD  //1 blank column to file
  write a new line to SD
else
if switch 4 is closed
  read 1 data item for switch 4
  write ,,, to SD  //3 blank columns to file
  write data to SD
  write a new line to SD
end if

Thanks Bob! Let me try your suggestion. Will post the code here

Hi Bob, as you suggested, I rewrote the code and got following output on SD FR1, FR2 are the switches 1 & 2. How to bring the the FR2(switch 2) in top row? Now it is appearing where FR1 data ended. I attached the code.

if (dataFile) 
 {
    if(Relay1On)
    {
    currentBurner = 1;
    dataFile.print("FR");
    dataFile.print(currentBurner);
    dataFile.print(',');
    dataFile.println(dataString);
    }
    else if(Relay2On)
    {
    dataFile.print(",,");
    currentBurner = 2;
    dataFile.print("FR");
    dataFile.print(currentBurner);
    dataFile.print(',');
    dataFile.println(dataString);
    }
    
    // print to the serial port too:
    //Serial.println(dataString);
    dataFile.close();
    return 0;
  }

row (1st row)? Here is the code

FR1 0
FR1 0
FR1 0
FR1 1.2
FR1 2.7
FR1 2.7
FR2 2.7
FR2 2.7
FR2 2.7
FR2 2.7

How to bring the the FR2(switch 2) in top row? Now it is appearing where FR1 data ended.

No surprise there. Why do you think I said

If you are happy to have blanks in columns 2, 3 and 4 with switch 1 data is in column 1, spaces in 1, 3, and 4 with switch 2 data in column 2 and so on you can do that

You could, of course, move the data in Excel

Stop looking for solutions using the Arduino directly unless you can make changes to your proposed procedure. You could save the data in 4 separate files, one for each switch then, when required copy the data into a combined file but honestly, you are better off writing the data for each switch to its own row in a single file then using the Excel transpose() function to rotate the data 90 degrees so that what is in a row is now in a column and vice versa. You could even write an Excel macro to do it

If you had a fixed number of readings for each switch you could save the readings in a 2 dimensional array on the Arduino the, at the appropriate time, write it to a file in the format that you want. That was why I was asking about the number of readings and were they fixed, but they aren't

The procedure you described in reply #15 is so full of possible mistakes that could be made that I suggest that it is bound to go wrong. How about a system whereby a user presses just one button, the Arduino records data for each channel in turn for a fixed time for a maximum number of readings then writes the file ?

Hi Bob, I understand what you said. Excel is always there to do formatting. At least I learnt something after discussion with you, rewriting the codes, use of coma separator etc. Thank you very much!

Regarding the procedure, we have been following for recording, our test technician prefers this way. We have been logging data for last 7 days, no issue so far. Hopefully we will be able to successfully record the data for total of 30 days. That is the intent.

Hi Bob,
How to write time stamp on the SD card? Is there any arduino code, I can refer?

First you need to get the time. An RTC (Real Time Clock) module would be a good candidate

Actually writing the time to the file is no problem

Do I need to have additional hardware?

I was thinking of getting time from the computer, instead of additional hardware. Is that feasible?

An RTC would mean additional hardware but they are quite cheap

To get the time from the PC would need having software on the PC sending it to the Arduino either periodically or on demand from the Arduino. An RTC is a cheap and easy solution to getting the time (and date if required) and they are really cheap

An example 1/2/5/10PCS DS3231 AT24C32 IIC Module Precision Real Time Clock Quare Memory | eBay

jag68:
I was thinking of getting time from the computer, instead of additional hardware. Is that feasible?

It is feasible but it implies that Arduino is connected to the PC, which immediately makes the exercise pointless, and also absolves you from finding out how difficult it is.

Just about any PC terminal programme can add time from the PC clock to the data it is receiving from Arduino. You can also feed the datastream from Arduino directly into Excel, and add the PC time in a similar manner. RTCs are cheap and common practice in data logging, but the only time you need the time from one is when you are not connected to a PC, or the Internet, and even then not necessarily.

"I was thinking of getting time from the computer, instead of additional hardware. Is that feasible?"

Change over to a NodeMCU (ESP8266-based) or ESP-32 and, with network access, you can get the time from an NTP server.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.