I am testing a New SD shield using my ARDUINO UNO and the SD.h library that comes wit IDE 022, using the example sketches.
Im accessing and reading text files from a 512MB SD card withou problem.
Trouble appears when trying to write. It will create files, but no content gets added. Files keep empty.
When I try to create a new directory, it also fails, it creates just another file. =(
The contents of the SD card I´m monitoring with a Windows Vista PC. I´ve formatted the card completely, and its using 16KB sectors.
Sorry, I didn't post it because is just one of the exaple files of the library.
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
updated 2 Dec 2010
by Tom Igoe
This example code is in the public domain.
*/
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);
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());
}
Except for a couple of missing '}' braces and the missing empty loop() function, that is the Arduino SD library ReadWrite example sketch, right?
That example sketch works for me on an "official" Arduino Duemilanove with an "official" Arduino Ethernet Shield Version 5 (the one with the microSD socket), using a 4 Gigabyte micro SDHC card formatted (as it came from the factory) as "FAT32"
I can read and write the card using various card readers on my Windows XP and Linux workstations.
Originally there was no file named "test.txt" but one was created the first time I ran the sketch. The file contained the single line "testing 1, 2, 3."
Each time I run the sketch it appends another "testing 1, 2, 3." line to the file.
So...
If you are, indeed, using the ReadWrite example sketch from the Arduino SD library, the question is: What is your hardware setup? What Arduino? What Shield? Is there anything else plugged into/onto your Arduino?
What sketch(es) did you run to verify that your setup can read from the microSD card?
After running the script, the file was created, with no content
If I connect the SD card into my computer using windows vista, create a file, with content, and the I read it with this same code (just comenting the writing part) the conthent of the file is shown on the serial monitor without a problem
I've also tested the example code that make a Dump of the entire file, and it also works. The problem is allway when trying to write content.
Is there any way to debug it, or maybe search with an hex editor if the info is in the wrong place in the sd card?
They take either 3.3V or 5V. I have only run them on 5V. The power level circuits are built in and raised some eyebrows but they work. Hardest part for me was getting up nerve to try but I got a good price on 3 at eBay.
Also make sure the SD card is formatted FAT-16, the most compatible. And IMO the SD-Fat library is better.