Hi, I'm in little trouble, I need to be able to read a line of text from a .txt file on an SD card. I've been searching the forums and I only found like two people with this problem, but I think that only one managed to get close to the answer, is this:
I don't know if it succeeded, but with trying to use the codes they sent in that forum and they didn't work for me.
Ok, here are the specifications you always ask for:
I want to be able to read any line of a file just by changing the value of a variable (a line can be identified as '\n' (enter) or a comma, whichever is best for me to be able to identify a line).
I am using the SD.h library with the latest version.
If it wasn't too much trouble, I'd like an example of a functional code...
Here you go, with "myFile.seek (3 * 5);" you can search for anything, 3 represents the row, 5 is the width of each row, this is very easy if all the lines have the same width, but if you know the number of byts that there are from the beginning to your destination, well there will not be any problem. When Entering the file, going from one line to another takes 2 bytes.
Code:
#include <SPI.h> #include <SD.h>
File myFile;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Iniciando tarjeta SD...");
if (!SD.begin(4)) {
Serial.println("Ah fallado la inicializacion");
while (1);
}
Serial.println("Inicializacion Exitosa");
myFile = SD.open("Ejemplo.txt");
if (myFile) {
Serial.println("Ejemplo.txt:");
myFile.seek(3 * 5);
String lista = myFile.readStringUntil('\r');
Serial.println(lista);
myFile.close();
} else {
Serial.println("Error al abrir Ejemplo.txt");
}
}