Read CSV or TXT from SD card into string or array

(Read 740 times)
Read CSV or TXT from SD card into string or array on: September 17, 2019, 11:03:43 PM
I am working on an system and need to read values on an sd card. The txt or csv will have multiple lines with 2 rows of values. What I would like to achieve is for the arduino to open the sd file, take line one, split it into its two values. val1 and val2. It will then compare the values to what a sensor reads. If they match, it will stop searching the txt file. If the values don't match, it will read and compare the values from the next line in the txt file. I am very new to programming and think the values would either be a string or array. Please help! Thanks



Re: Read CSV or TXT from SD card into string or array Reply #1 on: September 18, 2019, 09:59:25 AM
Code: [Select]
String l_line = "";
//open the file here
while (l_SDFile.available() != 0) {   
    //A inconsistent line length may lead to heap memory fragmentation           
    l_line = l_SDFile.readStringUntil('\n');           
    if (l_line == "") //no blank lines are anticipated           
      break;         
    //   

   //parse l_line here
}
//close the file here
« Last Edit: September 18, 2019, 10:01:31 AM by ELECTRONOOBS »