Need help to read data from SD card or pendrive to arduino

Hello guys,

I'm making one project in which SD card or pendrive has all the data. the data file contains one string and Two integers. i want to read all three data fields at a time and store in three different variables.

so, in which file format i can save the file in storage devices?

How i can read the data from storage devices and put in variables of arduino?

How many number of arduino's can access the same storage device at a time?

Thanks in advance.

Generally, it you want to read data from a file on an Arduino you use one with an SD card socket or add a shield that has one.

File format is up to you. A text file is easy to read from.

Your last question is more tricky. In the scenario I described, the answer is obviously one. Are you planning to have the pen drive attached to a PC instead?

shreekantha_v:
I'm making one project in which SD card or pendrive has all the data.

To use USB storage you would first have to add a USB Host Shield to most Arduinos. For an SD card you just need an SD socket connected to the SPI pins.

shreekantha_v:
the data file contains one string and Two integers. i want to read all three data fields at a time and store in three different variables.

You will need some way to determine the end of the string. If there is a marker character, use "file.readBytesUntil(marker, buffer, bufferSize)". For the integers, use "var = file.parseint();" which will read until it finds a number and then read until it finds the end of the number (or timeout).
https://www.arduino.cc/reference/en/language/functions/communication/stream/streamreadbytesuntil/
https://www.arduino.cc/reference/en/language/functions/communication/stream/streamparseint/

shreekantha_v:
so, in which file format i can save the file in storage devices?

I would use a text file. Given the choice, I would put the two integers first and then the string, ending with a newline character ('\n') as an end marker.

shreekantha_v:
How i can read the data from storage devices and put in variables of arduino?

You would use the file.read() functions.

shreekantha_v:
How many number of arduino's can access the same storage device at a time?

Just one, but that one could communicate with others to share the data.

Have you looked at the SD library example sketches?

Thank you very much for your response.

I'll try and see.

Hello,

list = dataFile.readStringUntil('\r');

using \r or \n i can print the current line in a file. So, to print previous line what character i can use?

thank you

Use file.position() to get the current file position. Save that in a variable. Use file.seek() to go back to that position so you can read that line again.

You can't read backward with readStringUntil(). Only forward.