Help,Arduino problem Sd Card double use of a pin out.

Thread Starter

antonis763

Joined Mar 10, 2017
12
Guys i have stuck.
At void setup() i use SD.begin(4) to read a text file from Sd.
When the reading of Sd completes i want to play music from Sd card (SdPlay.setSDCSPin(4);) but i have already set pin(4) for reading the text.
Anyone knows how to reset the pin4 and use it again for listening music from sd?

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

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

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    myFile.close();
    Serial.println("done.");
  } else {
    Serial.println("error opening test.txt");
  }
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    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");
  }
//----------------------------------------------------------------------------------------------------------
SdPlay.setSDCSPin(4); //------>Here problem caused
}
 
Last edited by a moderator:

shteii01

Joined Feb 19, 2010
4,644
You are not making sense.

Pin 4 is a digital pin.
It is also PWM pin.

So. When you want it to output "music", it will do it as a PWM signal?
 

Thread Starter

antonis763

Joined Mar 10, 2017
12
i use this schematic for my sd card:
cs pin cannot go to pin4 and 9 (for example) because it will create short circuit. fritzing_bb.png
 
Top