Go Down

Topic: Reading specific lines from SD (Read 1 time) previous topic - next topic

BeyondFear

Hi there, I'm a newbie with the arduino & coding it.
I've managed to get a SD card working with my Arduino. I've used the sdfatlib library to access the card.
The example for reading a file works great, but what I like to know: how can I read for example (only) line 15 and use the text as a variable (String or Array) in my Sketch.
Can anyone help me? Thanks!


tmoney1177

Hello,

I was hoping to have this same question answered and think it needs a little more attention.

Does anyone have any input?

Thanks

el_supremo

If the lines are different lengths, the only way to do it is to start at the beginning of the file, read each line (using fgets) and count them until you get to the 15th one.
If every line is the same length, there are seek functions you can use to position the file just before the first character of the 15th line and then read however many characters are on the line.
I haven't tried it myself so I can't give you a working example but look in the SDfile Class Reference for the seekSet function.

Pete

Go Up