Pages: [1]   Go Down
Author Topic: [SOLVED] Dumpfile stop before to read completelly the file  (Read 2081 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I try to read a file stored in this microSD shield:
http://www.cooking-hacks.com/index.php/microsd-2gb-module-for-arduino.html

I used the Dumpfile example from the Sd library at the Arduino 22 IDE.

I modified a little bit the code to be running with this module, to be like this:
Code:
/*
  SD card file dump
 
 This example shows how to read a file from the SD card using the
 SD library and send it over the serial port.
 
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created  22 December 2010
 
 This example code is in the public domain.
 
 */

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
#define MEM_PW 8                 // Define el pin que alimenta la tarjeta microSD
const int chipSelect = 10;

void setup()
{
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
  Serial.begin(115200);
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datos.log");

  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
    Serial.print("Completed");
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datos.log");
  }
}

void loop()
{
}

It works nearly perfect, except that it stop to read the file very soon, and it only return something more than 100 lines in the serial monitor, after to write "Completed" such as i modified in the code. So it seems that the card connection is closed.... ???

any of you had a similar problem? Any idea about what could be the problem or how could i solve it?

Thanks!
« Last Edit: September 01, 2011, 04:47:11 pm by madepablo » Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 This is the default chip select pin #10.
Code:
const int chipSelect = 10;

 If I understand your code, your chipselect pin is #8. If so change the above to:
Code:
const int chipSelect = 8;
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks cyclegadget,

No, no. The CS pin is 10. Pin 8 is declared to power the SD shield, but it does not disturb the other part of the code, because they are independant function. In other shields, this pin declaration is not necessary, but this is not the problem.

In fact, the code works... it start to return the content of the file... the problem is that it stop early, before to finish to return all the content of the file...

Thanks!
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  There are more experience people here but, I am going to take a GUESS. Maybe you need to add a delay after serial.write. I don't know how much data you have but, maybe you have too much for the buffer. So, I would try to add a small delay, perhaps delay(5);  It may be too much but, it would be worth a try.

Mark
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!

However, it does not work.  I tried with a delay from 1 to 100 and the file stop exactly at the same character of the file...

By the way, the file that i use now for testing if only about 250Kb... not s big for what i expect to have on the real use on my project...

Yes, i have the same idea. I think that there is a problem with the buffer... because it even stop at the same point! But i don´t  know what buffer it is or how to clean to allow to new data to be readed...

Thanks for the guess!
« Last Edit: August 27, 2011, 06:23:12 pm by madepablo » Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  Now that I am home I looked at your code some more and I don't see any problems. It looks cut and paste from the example so, it should work.

 By the way, how do you know your file is 250Kb? Did you load it or read it to verify the contents?

 I don't have a fix but, I can give you a link to a new library that has been made for SD cards. Maybe just trying something different will help you solve your problem.

 http://code.google.com/p/beta-lib/downloads/list

 This thread explains it all http://arduino.cc/forum/index.php/topic,64813.0.html
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again,

Yes, the code is the example provided with the Arduino 22 IDE. I only added three lines to declare the pin to power the SD Shield (and one more for the delay that you proposed).

About the file, the file was filled by arduino with the data from different sensors. I know that it is about 250 Kb because i copied to my laptop meanwhile i formated the SD card to see if it was the problem... I also open it in my laptop to see where the arduino stopped to transmit the content to serial...

I will check the beta version of the library to see if it solve the problem. I will report here any news (i hope good ones).
Thanks!

Quote
Edited:

I tested the Sdfat library, and the problem is bigger, because it reads one and a half lines of my file.

Meanwhile, the SD library reads 177 and a half lines, what is about 17Kb of the original file...
« Last Edit: August 28, 2011, 04:50:34 pm by madepablo » Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

one more question related to this problem. Is it possible to overflow the serial monitor buffer? I don´t know if it exist and if it is possible.

But may be this could be the problem.... (????)
any idea? nobody had similar problems with dumpfile example??
Thanks!
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1637
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The SD library has a bug in available() that will return zero even if more data is available.

http://arduino.cc/forum/index.php?topic=59667.0

http://code.google.com/p/arduino/issues/detail?id=571
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!

I was near to go crazy because i thought i was doing something wrong.

Thanks for the links, but... is it possible to solve it? How?
I took a look to the links that you provided but i do not have clear what can i do to solve it...
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1637
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Replace
Code:
    while (dataFile.available()) {
with
Code:
    while (dataFile.position() < dataFile.size()) {
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GREAT!!!!

IT WORKS! Thanks so much fat16lib!!! You solved my problem and my head pain at the same time!!

Thanks so much!

I tried with my short file and worked, but i also tried with a 7 Mb lng txt file and it worked as well as with an small one!

So SOLVED! Thank you!
Logged

Pages: [1]   Go Up
Jump to: