Hola, tengo instalado una SD formateada a Fat32, y estoy leyendo un archivo txt, con data entre 0-255.
el problema que no se como leer estos numeros, ya que la funcion que lee ,hacede a la memoria los lee como bytes. "read()"
#include <SPI.h>
#include <SD.h>
File myFile;
union { // This Data structure lets
byte asBytes[4]; // us take the byte array
uint8_t asint[1]; // sent from processing and
} // easily convert it to a
foo;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open("data/R0.txt");
if (myFile) {
for(int i=0;i<1;i++){
int index=0;
while(index<4)
{
foo.asBytes[index] = myFile.read();
Serial.println(foo.asBytes[index]);
index++;
}
if(index==4 )
{
Serial.println(foo.asint[0]);
}
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}
yo venia leyendo de esta forma, pero por el puerto serial desde el processing. pero no que pasa yo creo debe ser similar, pero no
consigo.
//data del txt de esta forma:
184,179,179,179,179,179,179,179,179,179,179,179,179,179,179,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,