Tento ler do cartao SD uma linha especifica de um txt só que acabo recebendo os dados incompletos
#include <SD.h>
File myFile;
String string = "";
char caracter;
void setup(){
Serial.begin(9600);
Serial.println("Inicializando");
pinMode(10, OUTPUT);
lerSD(0); // linha que ira ser lida do cartao SD
}
void lerSD(int linha){
if(!SD.begin(4)){
Serial.println("Falha na inicializacao!");
}
myFile = SD.open("AR.txt");
if(myFile){
unsigned long linhaEspec = 850 * linha; // cada linha possui 849 caracteres
myFile.seek(linhaEspec); // ponto de partida para cada linha
for(int i=0; i <= 849; i++){
caracter = myFile.read();
Serial.write(caracter);
string.concat(caracter); // concateca o que for recebido pelo myFile.read()
}
Serial.print(string);
//Serial.println();
char arrayString[string.length()]; // defini o tamanho do array que ira receber a string para poder quebra-la
string.toCharArray(arrayString, string.length()); // transfere a string para um array de char
char *p = arrayString;
char *str;
char *aux[200];
int i = 0;
while((str = strtok_r(p, ",", &p)) != NULL){ // quebra o array a partir da ","
aux[i] = str;
Serial.print(aux[i]);
i++;
}
i = 0;
myFile.close();
}
}
void loop(){
}
O que o Serial.print(string) me mostra:
4150,4450,250,1850,300,550,550,1700,450,1700,400,600,500,550,500,1750,400,600,500,550,500,1700,450,600,500,500,550,1750,400,1750,400,550,500,1750,400,600,500,550,500,600,500,1700,450,1750,350,1750,400,1750,400,1750,400,1750,400,1750,400,1700,400,600,500,550,550,550,500,550,550,550,500,600,500,550,500,550,550,550,500,1700,450,600,450,600,500,550,550,1700,400,1750,400,1750,400,1750,400,550,500,1750,400,1750,400,1750,400,5350,4150,4500,250,1800,350,550,500,1800,350,1750,400,550,500,550,550,1750,400,600,45
O que era para ser salvo em string:
4150,4450,250,1850,300,550,550,1700,450,1700,400,600,500,550,500,1750,400,600,500,550,500,1700,450,600,500,500,550,1750,400,1750,400,550,500,1750,400,600,500,550,500,600,500,1700,450,1750,350,1750,400,1750,400,1750,400,1750,400,1750,400,1700,400,600,500,550,550,550,500,550,550,550,500,600,500,550,500,550,550,550,500,1700,450,600,450,600,500,550,550,1700,400,1750,400,1750,400,1750,400,550,500,1750,400,1750,400,1750,400,5350,4150,4500,250,1800,350,550,500,1800,350,1750,400,550,500,550,550,1750,400,600,450,600,500,1750,400,550,500,600,500,1750,350,1800,350,600,500,1650,500,550,550,500,550,550,500,1650,500,1650,500,1650,500,1600,550,1600,550,1600,550,1600,500,1650,500,550,550,500,550,550,550,500,550,550,550,500,550,550,550,500,550,550,550,1600,550,500,550,550,550,500,550,1600,550,1600,550,1600,550,1600,500,550,550,1600,550,1600,550,1600,550
Imagino que seja algo em relação a buffer ou algo do tipo. Se sim, tem alguma forma de armazenar tudo na string?
Faço isso porque depois preciso quebrar a string e armazenar em um array de 200 posicoes