michalmonday / CSV-Parser-for-Arduino

It turns CSV string into an associative array (like dict in python)
MIT License
58 stars 12 forks source link

problems with the file path in readSDfile function #8

Open pedro-nonfree opened 3 years ago

pedro-nonfree commented 3 years ago

hi @michalmonday , congratulations for such an amazing piece of software :)

we are using the reading from sd card example

in our case, to correctly read the file we had to place a / before the filename

-  cp.readSDfile("file.csv"); // this wouldn't work if SD.begin wasn't called before
+  cp.readSDfile("/file.csv"); // this wouldn't work if SD.begin wasn't called before

the upstream documentation was lastly reviewed on ~2018 so maybe something changed :shrug: https://www.arduino.cc/en/Tutorial/DumpFile

it might be useful too if there is some kind of checking such as:

file_read_ok =  cp.readSDfile("file.csv"); // this wouldn't work if SD.begin wasn't called before
if( ! file_read_ok ) {
  Serial.println("cannot read file from sdcard, check the path is correct");
  // don't know if `exit(1);` would work works
}
michalmonday commented 3 years ago

Hi, thank you for letting me know, I edited the filename just in case. It's a bit weird though because the reference page of SD library states:

Because the working directory is always the root of the SD card, a name refers to the same file whether or not it includes a leading slash (e.g. "/file.txt" is equivalent to "file.txt").

Btw by looking at the SD library history, it doesn't seem that there were any relevant changes since 2018. There is one from 2017 which at first glance could be related but I have no idea if it has something to do with this issue.

Also, thank you for the error checking suggestion, I just added it in this commit.

michalmonday commented 3 years ago

Btw, what version of Arduino and SD library do you have? (the library version can be checked by going to "Tools -> Manage libraries" and typing "sd cards")

I'm going to try to reproduce the issue (with Arduino 1.8.12 and SD 1.2.4 it works well when backslash is not used).

pedro-nonfree commented 3 years ago

I was helping remotely a friend (I don't have that device here), the answer is with @smjacques (ping!)

smjacques commented 3 years ago

Hi! The SD lib version is 1.2.4 and the Arduino IDE is the 1.8.13.