Can I use this pin as a Chip select? And do I need to change settings?

I have an Arduino Unu with an SD card connected to it. For a technical reason, I needed the Chip Selectpin to be another pin than the one used in an example I found on the internet which worked fine.

The original pin was pin 4 and I wanted it to be pin 5.
In my opinion, the pins seem interchangeable, but I have my doubts.

Can pin 5 be a Chipselectpin? Or do I need to make certain changes in order to get that pin working?

Greetings,
Any pin can be used as a chip select(except your MISO and MOSI lines).

Thank you.
I thought the same.
I only have to change the setting from 4 to 5 in the code.
So no other changes like pullups, output assignment or what so ever?

#include <SD.h>

#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SPI.h>

#include "SD.h"
#define SD_ChipSelectPin 5
#include "TMRpcm.h"
#include "SPI.h"
#define next     2
int checker; 

TMRpcm tmrpcm;

void setup(){
tmrpcm.speakerPin = 9;
Serial.begin(9600);
pinMode(next,   INPUT_PULLUP);
if (!SD.begin(SD_ChipSelectPin)) {
 Serial.println("SD fail");

For some reason I have an SD fail message when booting up.
Can that only happen due to errors in that ChipSelectPin connection?
Or also for other reasons, according to the code above.

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