SD card intializatiom failed error (Arduino nano used)

Please help me with this I'm tired of this sd card not intialized error

#include <Keypad.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>

#define CS 10
#define SCK 13
#define MOSI 12
#define MISO 11

const int SD_CS_PIN = 10;
const int SPEAKER_PIN = 9;

const byte ROWS = 8;
const byte COLS = 5;

char keys[ROWS][COLS] = {
{'0', '1', '2', '3', '4'},
{'5', '6', '7', '8', '9'},
{'A', 'B', 'C', 'D', 'E'},
{'F', 'G', 'H', 'I', 'J'},
{'K', 'L', 'M', 'N', 'O'},
{'P', 'Q', 'R', 'S', 'T'},
{'U', 'V', 'W', 'X', 'Y'},
{'Z', '.', ',', '?', '!'}
};

byte rowPins[ROWS] = {1, 2, 3, 4, 5, 6, 7, 8};
byte colPins[COLS] = {A0, A1, A2, A3, A4};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

TMRpcm tmrpcm;

void setup() {
Serial.begin(9600);
pinMode(SPEAKER_PIN, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(CS, OUTPUT);
SPI.begin();

if (!SD.begin(CS)) {
Serial.println("SD card initialization failed!");
return;
}

tmrpcm.speakerPin = SPEAKER_PIN;
tmrpcm.setVolume(6); // Set volume (0-7)
}

void loop() {
char key = keypad.getKey();
if (key) {
int index = key - 'A';
if (index >= 0 && index < 26) {
// Key is a letter
char fileName[20];
sprintf(fileName, "audio/%c.wav", key);
tmrpcm.play(fileName);
delay(500);
} else if (key >= '0' && key <= '9') {
// Key is a number
char fileName[20];
sprintf(fileName, "audio/%c.wav", key);
tmrpcm.play(fileName);
delay(500);
}
}
}

I have moved your topic to an appropriate forum category @sagarrrrrr.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an essential part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@sagarrrrrr have you tried the SD card example sketches included within the IDE?

1 Like

@markd833 yess I have tried but same with that , sd card not intialized

the code in the cd reader looks fine. just look the connections, or send a conection diagram
Xakko

Good idea to post the basic example code you are using, if that does not work either.

Lots of other code in a sketch, which is nothing to do with the SD card, just confuses things.

2 point in your code:

  1. if your are using the port 1 for your kb, do not start the serial monitor: don't put:
    Serial.begin(9600);
  2. delete:
    const int SD_CS_PIN = 10;
    if you are using earlier:
    #define CS 10

Xakko

try this shor sketch with on the card connected to your arduino:

#include <SPI.h>
#include <SD.h>

// define select pin for SD card module
#define sssd 10//4-53

// Create a file to store the data
File myFile;


void setup()
{ 
  Serial.begin(9600);

  // Init SPI bus
  SPI.begin(); 
  pinMode(sssd, OUTPUT);
  digitalWrite(sssd,LOW); //enable the sssd to work with its slave module
  if (!SD.begin(sssd)) {
    Serial.println("SD card initialization failed");
  } else {
    Serial.println("SD card initialization done");
    read_sd();
  }
  digitalWrite(sssd,HIGH);

}

void loop() {
  //
}

void read_sd() {
  myFile = SD.open("file.txt"); 
  String texto = "";
  if (myFile) {
    Serial.println("file.txt:");
    while (myFile.available()) {
      texto += char(myFile.read());
    }
    Serial.println(texto);
    myFile.close();
  } else {
    Serial.println("Error");
  }
}

you MUST have:

  1. the sd inserted to your SD CARD READER
  2. the card MUST BE FORMATED IN FAT OR FAT32
  3. a file named "file.txt" with the text you want in it. it doesn't matter if you have other files in the card

Connections:
sd-card-reader and arduino nano

@xakko hey sir I did same as you told but still sd card not intialized problem is there

is the sd card working? is it formated in fat or fat32? if dont, you will got that error

Xakko

1 Like

@xakko sir sd card is working , thank you for helping

But I have got another problem the content in sd card is audio files so I have named the folder as audio and in it has audio files but none of them are playing on my speaker , can you help , the same code which I sent above

Sir if possible can we have a chat on mail ,

My email id :- .......

You're advised not to publush your email address on a public forum unless you want to receive more spam.

If you want a private conversation, send a PM to the person that you want to talk to. Note that most of us will not help via PM; the thought is that the whole world can benefit from public discussion / problem solving.

I've removed your email address.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.