Accelerologger: error opening test.txt problem!!!

Now I have solved my silly mistake I have run into another problem!!!

I looked in the serial monitor and I am getting the:

error opening test.txt

Part of the code being carried out! Here is a Fritzing diagram of the Accelerologger:

The diagram is a bit messy but it’ll do to show the circuit config. I ran the default SD Card Reader code on it:

#include <SD.h>
#include <SPI.h>

File myFile;

int pinCS = 10;

void setup() {

Serial.begin(9600);
pinMode(pinCS, OUTPUT);

// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}

// Create/Open file
myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:
if (myFile) {
Serial.println("Writing to file...");
// Write to file
myFile.println("Testing text 1, 2 ,3...");
myFile.close(); // close the file
Serial.println("Done.");
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}

// Reading the file
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("Read:");
// Reading the whole file
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
}
else {
Serial.println("error opening test.txt");
}

}
void loop() {
// empty
}

With this code, it worked perfectly. Here is the response received in the serial monitor:

SD card is ready to use.
Writing to file…
Done.
Read:
Testing text 1, 2,3…
Testing text 1, 2,3…
Testing text 1, 2,3…
Testing text 1, 2,3…
Testing text 1, 2,3…
Testing text 1, 2,3…

Geez!!! all these problems! I hope I eventually get to the bottom of them all!

Thanks for everyone’s help!

EJBuilder

4 Replies to “Accelerologger: error opening test.txt problem!!!”

  1. Yeah I did, works perfectly. Here is here is the standard code:

    #include
    #include

    File myFile;

    int pinCS = 10;

    void setup() {

    Serial.begin(9600);
    pinMode(pinCS, OUTPUT);

    // SD Card Initialization
    if (SD.begin())
    {
    Serial.println(“SD card is ready to use.”);
    } else
    {
    Serial.println(“SD card initialization failed”);
    return;
    }

    // Create/Open file
    myFile = SD.open(“test.txt”, FILE_WRITE);

    // if the file opened okay, write to it:
    if (myFile) {
    Serial.println(“Writing to file…”);
    // Write to file
    myFile.println(“Testing text 1, 2 ,3…”);
    myFile.close(); // close the file
    Serial.println(“Done.”);
    }
    // if the file didn’t open, print an error:
    else {
    Serial.println(“error opening test.txt”);
    }

    // Reading the file
    myFile = SD.open(“test.txt”);
    if (myFile) {
    Serial.println(“Read:”);
    // Reading the whole file
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    myFile.close();
    }
    else {
    Serial.println(“error opening test.txt”);
    }

    }

    Here is the response in the serial monitor:

    SD card is ready to use.
    Writing to file…
    Done.
    Read:
    Testing text 1, 2 ,3…
    Testing text 1, 2 ,3…
    Testing text 1, 2 ,3…
    Testing text 1, 2 ,3…
    Testing text 1, 2 ,3…

    I hope we can figure this out!

    EJBuilder

Leave a Reply