Hi guys. I'm new to Arduino and I'm trying to do the folllowing:
Read a file from SD with this format (example)
0,0,0,0
1,1,1,1
2,2,2,2
...
create an array from those values
Read another file from SD with this format (example)
0,0,0
1,1,1
2,2,2
...
create an array from those values.
I'm using this code that I saw here in the forum, combined with the "filedump" example
/*
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
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
int Main_Array[1][3];
int Main_Array2[1][3];
int Main_Array3[1][3];
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// 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 myFile2 = SD.open("modem.txt");
while (myFile2.available()){
for (int e=0; e<=3; e++){
for(int r=0; r<=3; r++){
Main_Array2[e][r] = myFile2.parseInt();
Serial.println(Main_Array2[e][r]);}
}
}
myFile2.close();
Serial.print("A test Value is:");
Serial.println(Main_Array2[1][1]);
// 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 myFile = SD.open("patchm.txt");
while (myFile.available()){
for (int q=0; q<=5; q++){
for(int w=0; w<=2; w++){
Main_Array[q][w] = myFile.parseInt();
Serial.println(Main_Array[q][w]);}
}
myFile.close();}
Serial.print("A test Value is:");
Serial.println(Main_Array[1][1]);
}
void loop()
{
}
The issue is, it only works for one of the files. If I comment the code concerning one of the the files,the other one works OK.
Can you help, please?
Best regards