Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems with the file path in readSDfile function #8

Open
pedro-nonfree opened this issue Jun 6, 2021 · 4 comments
Open

problems with the file path in readSDfile function #8

pedro-nonfree opened this issue Jun 6, 2021 · 4 comments

Comments

@pedro-nonfree
Copy link

pedro-nonfree commented Jun 6, 2021

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 🤷 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
}
@pedro-nonfree pedro-nonfree changed the title readSDfile path problems with the path in readSDfile function Jun 6, 2021
@pedro-nonfree pedro-nonfree changed the title problems with the path in readSDfile function problems with the file path in readSDfile function Jun 6, 2021
@michalmonday
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

pedro-nonfree commented Jun 8, 2021

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

@smjacques
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants