0

I am starting a project in Arduino and I need to read data from an CSV stored in an SD card. The data is stored as the following:

id, value, date

What I want to do is read the file, filter by date and then store the values by id. Each id will correspond to different values from that same date.

Is it possible to do something like this?

Thank you very much for your advice.

5
  • Since and Arduino does not know about SDCards you will have to use an SDCard shield and that shield's library to access the card. Once you have decided on which shield / library you are using - modify your question identifying which you picked. Then people can answer your question specifically.
    – st2000
    Commented Jul 24, 2016 at 22:18
  • Also, most Arduinos run on embedded processors with very limited RAM. So there is an upper limit on the size and number of variables you can keep at hand. For example, you probably could not read and keep 100,000 of your records at hand. But you could read 100,000 records and keep, say, 100 records or maybe even several thousands at hand.
    – st2000
    Commented Jul 24, 2016 at 23:34
  • It scarcely matters which hardware is used. But it is true that limited RAM may mean the algorithm has to read through the source data many times, pulling out only what is of interest for one iteration at a time. Or else, the destination data will have to be written with large gaps between each distinct set - in effect, it could be like sorting things into boxes, but having to be sure that your boxes are big enough that none of them will end up heaped aboved the rim. Generally speaking, an Arduino is a poor choice for data processing. Commented Jul 25, 2016 at 4:07
  • This is not arduino-specific. Have you tried searching for "parse csv c++"?
    – JayEye
    Commented Jul 26, 2016 at 3:09
  • Actually, you can sort 100,000 records, given enough time, and being able to save them back to the sd-card. But it may not be as efficiënt and also wear out the sd-card raster. You could check every two records, and swap them if the second is higher than the first. If you keep doing this until nothing has to be swapped in a whole iteration, it's sorted.
    – aaa
    Commented Mar 20, 2017 at 6:39

1 Answer 1

1

I highly suggest checking out this YouTube video (https://www.youtube.com/watch?v=5v5A3j7Rrco), especially around 21:30. It goes over in detail to do exactly what you are asking for, mainly the headings with IDs for each data point. At the end of the day you are going to need something that looks similar to this:

float id = 0; //used to provide a numbered ID to each data point

void setup(){
//initialize all your once-run variables and such
}

void loop(){
  //Write Log File Header
  File logFile = SD.open("NAME.csv", FILE_WRITE); 

  if (logFile){
    logFile.println(", , , ,"); //Just a leading blank line, incase there was previous data

    String header = "ID, Time, Light, Temp"; //These will be the headers for your excel file, CHANGE "" to whatevr headers you would like to use
    logFile.println(header);
    logFile.close();
    Serial.println(header);
  }

  else {
    Serial.println("Couldn't open log file");
  }
}
}

This is all code that I currently use to do the exact same thing as you, and its a small edit from what Jeremy Blum does in the YouTube video I just linked you too. This is how the header files will look on an excel sheet, I took a screenshot of an actual file I have created using this method:

Sample File with Headers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.