Hello, I have installed an SD formatted to FAT32, and I am reading a txt file with data 0-255.
the problem is not how to read these numbers, because the function that reads, memory reads as 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
}
I was reading in this way, but the serial port from the processing. but I think that happens to be similar, but not
them.
/ / data from txt this:
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,