Can't open new .txt file on sd shield

This is code that works on copying data from .txt file to char array but i found out that the maximum size of char array is 731 so i needed to open another txt file from sd shield.

#include <SD.h>

File myFile;

char all[731];

char inputChar;
int stringIndex = 0;

void setup()
{

Serial.begin(9600);
while (!Serial) {
;
}

Serial.print(“Initializing SD card…”);

if (!SD.begin(4)) {
Serial.println(“initialization failed!”);
return;
}
Serial.println(“initialization done.”);

myFile = SD.open(“test.txt”);
if (myFile) {
Serial.println(“test.txt:”);

while (myFile.available()) {

inputChar = myFile.read();
if(inputChar != ‘G’)
{
all[stringIndex] = inputChar;
stringIndex++;
}
else{
Serial.println("test: ");
Serial.println(all);
delay (1000);
stringIndex = 0;
}

}

myFile.close();

} else {

Serial.println(“error opening test.txt”);
}

Serial.println(all);
}

void loop()
{

//do nothing
}

this the code that i don’t know how it didnt work…

#include <SD.h>

File myFile;
File myFile2;

char all[731];
char all2[731];

char inputChar2
char inputChar;

int stringIndex = 0;
int stringIndex2 = 0;

void setup()
{

Serial.begin(9600);
while (!Serial) {
;
}

Serial.print(“Initializing SD card…”);

if (!SD.begin(4)) {
Serial.println(“initialization failed!”);
return;
}
Serial.println(“initialization done.”);

myFile = SD.open(“test.txt”);
if (myFile) {
Serial.println(“test.txt:”);

while (myFile.available()) {

inputChar = myFile.read();
if(inputChar != ‘G’)
{
all[stringIndex] = inputChar;
stringIndex++;
}
else{
Serial.println("test: ");
Serial.println(all);
delay (1000);
stringIndex = 0;
}

}

myFile.close();

myFile2 = SD.open(“test2.txt”);
if (myFile2) {
Serial.println(“test2.txt:”);

while (myFile2.available()) {

inputChar = myFile2.read();
if(inputChar2 != ‘G’)
{
all[stringIndex2] = inputChar2;
stringIndex2++;
}
else{
Serial.println("test2: ");
Serial.println(all2);
delay (1000);
stringIndex2 = 0;
}

}

myFile.close();

} else {

Serial.println(“error opening test.txt”);
}

Serial.println(all);
}

void loop()
{

//do nothing
}

any ideas?

You have no limit on the SD read. You could overflow the character arrays if the file size is more than 730 characters.

Is this a Mega2560 or better? If you are using an Uno, you are probably running out of SRAM.

You don't know how arrays work and you want to mess with large text files? That is a real quick route to buying hardware you probably don't need as well.

What are you trying to DO with the text and how many characters do you NEED to see at a time?

It looks like you just buffer everything until you read the letter G and then print the buffer. You could do that without storing anything. Just read each character 1 at a time and if it's not a G, print it.

You don't have to print serial all at once. It only gets sent over the line 1 bit at a time, 1 char at a time.

Im planning to make a LED light Show that can groove with music. i make a 0's 1's from text file that serves like on/off of LED. I also want to try .csv files from sd to array. it will take a lot of 0's and 1's so i need a large storage. im trying to run 5 led's.

Here is how I read a SD file with my web server code. I use a 64 byte buffer to hold sections of the file. It will transfer a large file.

                  while(myFile.available()) {
                    tBuf[clientCount] = myFile.read();
                    clientCount++;
                    tBuf[clientCount] = 0;

                    if(clientCount > 63) {
                      client.write((byte*)tBuf,64);
                      clientCount = 0;
                    }

                  }
                  if(clientCount > 0) {
                    client.write((byte*)tBuf,clientCount);
                  }

What are you trying to DO with the text and how many characters do you NEED to see at a time?

It looks like you just buffer everything until you read the letter G and then print the buffer.
You could do that without storing anything. Just read each character 1 at a time and if it’s not a G, print it.

You don’t have to print serial all at once. It only gets sent over the line 1 bit at a time, 1 char at a time.

i need characters up to 2 thousand. that’s how i start for my project.
i need to store it to serial to play 5 led’s like “for(int i = 0; i<maxsize;i+=5)”

btw thanks for ideas…

i need to store it to serial to play 5 led’s like “for(int i = 0; i<maxsize;i+=5)”

Then use my code in reply #4, but set the buffer to 5 instead of 64. Then go to town.

Then use my code in reply #4, but set the buffer to 5 instead of 64. Then go to town.

thanks man i will post the progress here.

jsquare, please read #7 below on how to use code "tags" to put your code in a code box. It keeps the post from being loooooooong.

http://forum.arduino.cc/index.php/topic,148850.0.html

jsquare: Im planning to make a LED light Show that can groove with music. i make a 0's 1's from text file that serves like on/off of LED. I also want to try .csv files from sd to array. it will take a lot of 0's and 1's so i need a large storage. im trying to run 5 led's.

Okay, so you're using the bits in the text to set 5 leds. Out of each character you are using 5 bits?

if so then you can read just 1 character at a time and use those bits to set the leds. Next character, you read into the same char variable and do the same thing, over and over. You won't ever need a buffer array or csv or converting text to data since the text is the data.

Maybe later on you can set up sound sensors and filters to drive your leds directly.