Go Down

Topic: Problem to read SD card (Read 426 times) previous topic - next topic

carlosivoup

Hi all,
I'm trying to read a file from the SD card with no success… I don't know with if have done something wrong so if anyone could point a solution, it will help a lot.
First, I created a folder called "arduino" using "mkdir arduino" in the root. Then, I uploaded the Datalogger example. But I don't know if has created in the right place. In the Arduino terminal I put "cd /mnt/sd" and there it was the catalog.txt file.
Then I tried to read the file using an example by another forum user:
Code: [Select]
  File dataFile = FileSystem.open("/mnt/sd/datalog.txt");
  Stringtext="";
  Serial.println(dataFile.size());
  if(FileSystem.exists("/mnt/sd/datalog.txt")) {
     Serial.println("file exists");
   } else {
          Serial.println("file does not exist");
              }
  while (dataFile.available()) {
        text += (char)dataFile.read();
                                  }
    dataFile.close();


but I got nothing… FileSystem.exists("/mnt/sd/datalog.txt") returns false. Using :
Code: [Select]
if(dataFile) Serial.println("file exists"); else Serial.println("file does not exist");
it returns true, but changing the file name by any other name returns also true… And the dataFile.size() returns always 0(zero).
So, the question is: am I trying to open the file in the wrong place? Or is there a problem with the code?


carlosivoup

Well, I put a Serial.print inside the loop:
Code: [Select]
while (dataFile.available()) {
        text=text + (char)dataFile.read();
        Serial.println(text);
   }

and a lot of data appeared on the monitor. I mean, a mess like this:
Quote
..4B00DA.......................%6$...?..$.$.....N%6$......$.$....5..
..........................................................r......6....d.......xt......."....O$.%.#...@+.r........P.............4B00DA3856FF
..4B00DA.......................%6$...?..$.$.....N%6$......$.$....5..
...........o.+.s..'..@"?...................................................r......6....d.......xt......."....O$.%.#...@+.r........P.............4B00DA3856FF
..4B00DA.......................%6$...?..$.$.....N%6$......$.$....5..
...........o.+.s..'..@"?........... ....e.......... ....e.<..3&
..."....O$.%.#...@+.r.................................<..3&.
..."....O$.%.#...@+.r........................................
..."....O$.%.#...@+.r..................................................................................................r......6....d.......xt......."....O$.%.#...@+.r........P.............4B00DA3856FF
..4B00DA.......................%6$...?..$.$.....N%6$......$.$....5..
...........o.+.s..'..@"?........... ....e.<..3&................................r......6....d.......xt......."....O$.%.#...@+.r........P.............4B00DA3856FF
..4B00DA.

I could recognize that it was related to my file (the RFID codes)
So, now the question is: why is it messed? How to put an order on the output?

sonnyyu

The output of

Code: [Select]
cat  /mnt/sd/datalog.txt

some case  should be "/mnt/sd1/datalog.txt".


carlosivoup

Ok, using this code
Code: [Select]
cat  /mnt/sd/datalog.txt
it shows the right output.
But how to do it on the Arduino Yun/FileIO code? Is the Serial.print in the wrong place?

simonecangioli

Ciao, anche io ho lo stesso problema.
Leggendo un semplice file txt, appaiono molti caratteri non presenti nel file.

Ho provato sia utilizzando la funzione Read() che la funzione ReadString().... Ma il risultato è lo stesso.

Vorrei capire se sbaglio qualcosa io oppure se è un bug.

Ciao

Go Up