Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
1,049 Views

Saving file on SD card problem

Hello,

I'm using Intel Edison with Arduino Breakout Board and I'm trying to save file on the SD card. I run a ReadWrite example and it works perfectly but when I'm inserting the SD card to a PC, the file does not exist or is empty.

Is it possible to change SD card adapter? I have wired another adapter at connect CS pin to pin 5 on Intel Edison and change Sd.begin(4) to SD.begin(5) but it still reads SD card from adapter on the board. This is the example code:

# include

# include

File myFile;

void setup()

{

// Open serial communications and wait for port to open:

Serial.begin(9600);

while (!Serial) {

; // wait for serial port to connect. Needed for Leonardo only

}

Serial.print("Initializing SD card...");

// On the Ethernet Shield, CS is pin 4. It's set as an output by default.

// Note that even if it's not used as the CS pin, the hardware SS pin

// (10 on most Arduino boards, 53 on the Mega) must be left as an output

// or the SD library functions will not work.

pinMode(10, OUTPUT);

if (!SD.begin(4)) {

Serial.println("initialization failed!");

return;

}

Serial.println("initialization done.");

// open the file. note that only one file can be open at a time,

// so you have to close this one before opening another.

myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:

if (myFile) {

Serial.print("Writing to test.txt...");

myFile.println("testing 1, 2, 3.");

// close the file:

myFile.close();

Serial.println("done.");

} else {

// if the file didn't open, print an error:

Serial.println("error opening test.txt");

}

// re-open the file for reading:

myFile = SD.open("test.txt");

if (myFile) {

Serial.println("test.txt:");

// read from the file until there's nothing else in it:

while (myFile.available()) {

Serial.write(myFile.read());

}

// close the file:

myFile.close();

} else {

// if the file didn't open, print an error:

Serial.println("error opening test.txt");

}

}

void loop()

{

// nothing happens after setup

}

0 Kudos
3 Replies
Highlighted
Valued Contributor I
6 Views

michalt38 I'm probably missing something here. When you insert an sd card you should be able to mount it (if it is not already automounted). Then you could just write the file to the file system, no need to write to the spi. Then unmount and put it in your PC to read. Of course if your PC is running windows the sd card should be formatted as FAT.

0 Kudos
Highlighted
Novice
6 Views

I have noticed something strange. I connect to the Edison FTP server using WinSCP and I go to the /media/sdcard destination. I save there a text file and reboot Intel Edison, then go to this destination again and the file is not here. Also, when there is no SD card plugged to Intel Edison I still can go to this destination and save there files and when I reboot Intel Edison some files are still there, some not. But then when I plug an SD card and go to /media/sdcard destination it sometimes show an actual SD card content but sometimes it shows files I saved when there was no SD card plugged in.

0 Kudos
Highlighted
Novice
6 Views

Here is an answer:

0 Kudos