I connected everything as in the video, uploaded the code :
#include <SD.h>
#include <SPI.h>
int CS_PIN = 10;
File file;
void setup()
{
Serial.begin(9600);
initializeSD();
createFile("test.txt");
writeToFile("This is sample text!");
closeFile();
openFile("prefs.txt");
Serial.println(readLine());
Serial.println(readLine());
closeFile();
}
void loop()
{
}
void initializeSD()
{
Serial.println("Initializing SD card...");
pinMode(CS_PIN, OUTPUT);
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
}
int createFile(char filename[])
{
file = SD.open(filename, FILE_WRITE);
if (file)
{
Serial.println("File created successfully.");
return 1;
} else
{
Serial.println("Error while creating file.");
return 0;
}
}
int writeToFile(char text[])
{
if (file)
{
file.println(text);
Serial.println("Writing to file: ");
Serial.println(text);
return 1;
} else
{
Serial.println("Couldn't write to file");
return 0;
}
}
void closeFile()
{
if (file)
{
file.close();
Serial.println("File closed");
}
}
int openFile(char filename[])
{
file = SD.open(filename);
if (file)
{
Serial.println("File opened with success!");
return 1;
} else
{
Serial.println("Error opening file...");
return 0;
}
}
String readLine()
{
String received = "";
char ch;
while (file.available())
{
ch = file.read();
if (ch == '\n')
{
return String(received);
}
else
{
received += ch;
}
}
return "";
}
I formated the MicroSD in to NTFS, created a file as in the video " openFile("prefs.txt");"
and pluged everything and uploaded the code: I got In the serial monitor that file can't be created
and the 2nd file can'd be opened so I thought that the module is bad and i changed with the 2nd one
same thing.
Well i thought Im not doing something good so i uploaded and pluged the wires as in the
SD.h lib Example_SD_ReadWrite.
Done same as above and again i don't have any comunication, opened the serial monitor and
said "initialization failed!".
Im i doing something wrong? or my totally new modules are not working?
It's hard to believe that the totally new modules not working so that's why i came here.
I formated the microSD with the website software you gave me and i downloaded the
SDFat.h lib, I opened the Example ReadWriteFat, uploaded the code and got this:
" Type any character to start
Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0X0 "
Im not sure exactly what's wrong, new module, good microSD card, all connected right but it's not working O_o
I use that picture alot, but my SD card is still chipselected on PD4 even though the pin definition says PB4
I have decided to ignore the problem and move other pins around leaving CS on PD4 (I dont like not solving problems like this as they always come back to bite me one day !!)
Although it's possible, it's unlikely that something so obvious is wrong with the core. I am inclined to believe that you've done something to cause this. Whether it's a hardware oversight or a software one I can't say. But I like these kinds of bugs. I wish it were mine to solve.
jboyton:
I am inclined to believe that you've done something to cause this.
I totally agree with you, whether it be installation of cores, version of IDE or perhaps the way I sometimes have to knife and fork bits of code to get it to work
I didnt have these kind of problems with 328/t85/t13 etc etc, maybe I might change the 1284 cores...