it runs fine but I just wont write anything on my file as I confirm using this code:
#include <SPI.h>
#include <SD.h>
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 native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// 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());
}
delay(1000);
// 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
}
Need more information: which Arduino are you using, which SD card, which SD card module?
Please post a hand drawn wiring diagram.
Your last comment suggests that you have connected a 5V Arduino to a 3.3V SD module without using level shifters, in which case the SD module may already have been destroyed.
That may also explain the problem in your other thread on this topic.
In addition to the above suggestions, if things don't appear to work as expected, it's a good idea to see if there are any known working example sketches that you can use to assist in narrowing down the problem.
Have a look for the SD example sketch called ReadWrite in the IDE.
And as I suggested in your previous thread, make sure that you are formatting the SD card correctly.
hello, thank you for your answer.
I'm using a transcend sd 2gb
I got exacly this (except is not micro sd module, but MH-SD card module, but connections are the same):
regarding my last comment, I meant that I read that all arduino board pins have a 5 V input (from power source to arduino board), and one of those pins that I connect to my sd card module is 3.3 V (from arduino to sd card module). It's like there was some incompatibility a board using 5V and having an output to 3.3 V. I think the ideia was to turn the arduino board all to 3.3V with that shift lever.. I heard some people saying it did the trick, but before I buy something I would like to know more opinions
I doubt my card is destroyed becouse I can insert it on my computer and format it. I doesn't seem burn.. Also, I manualy wrote a couple numberes on my txt and the code that I use to read works and shows in arduino console what txt file has.
also sample code from arduino about card info works nicely as you can see in the following image:
Yes I tried to use the arduino inbuilt example ReadWrite as follows:
/*
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 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
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 native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
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
}
and was in this phase that I got a sd card full of those files with strange caracters.. Then I decided to create manually the txt file with the same name on the code and, despite not writting anything, at least it didn't give me all those strange files.
You MAY NOT CONNECT 5v to 3.3V devices and expect them to survive. Use a 3.3V Arduino with a 3.3V SD or with a 5V Arduino, use level shifters like this one.