Hi,
I try to read a file stored in this microSD shield:
http://www.cooking-hacks.com/index.php/microsd-2gb-module-for-arduino.htmlI 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:
/*
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!