lcd and ethernet shield SD card not working together

I have an issue with my code, if I use the line "LiquidCrystal lcd(rs, en, d4, d5, d6, d7);" with "SD.begin()" the connection with SD card fails. I tried troubleshooting and found out that is the line of code causing the problem. I just want to know why. Sorry if the question is not clear.

#include <SPI.h>
#include<SD.h>
#include "MFRC522.h"
#include <virtuabotixRTC.h>
#include <LiquidCrystal.h>
#define SS_PIN A2
#define RST_PIN 9
#define SP_PIN 8
virtuabotixRTC myRTC(6, 7, 8);

const int rs = A0, en = A1, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;*/
File myFile;
int pinCS=10;
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);

// Set the current date, and time in the following format:
// seconds, minutes, hours, day of the week, day of the month, month, year

//digitalWrite(pinCS, LOW);
//digitalWrite(SS_PIN, HIGH);
if(SD.begin(10)){
Serial.println("SD card ready to use");
}else{
Serial.println("SD card initialization failed");
return;
}
myFile=SD.open("test.txt", FILE_WRITE);

if (myFile){
Serial.println("Writing to file..");
myFile.println("Testing1, 2, 3");
myFile.close();
Serial.println("Done");
}else{
Serial.println("ERROR opening");
}

Use code tags to post code!

What type of Arduino are you using?

Sorry, I am new to this. I am using an Arduino Uno and a W5100 ethernet shield.

rfid_time_stamp.ino (4.79 KB)

Ahlam_Saeed:
Sorry, I am new to this. I am using an Arduino Uno and a W5100 ethernet shield.

Dont worry, help is at hand, read the 'How to use this forum - please read' at the top of the list.

The Ethernet Shield uses D4 for the SD card and D10 for the WizNet5100 chip. If your hardware uses other pins, post schematics of all hardware and a wiring diagram (of everything not being a shield).

If you're sure that your shield uses D10 for the SD card CS, what pin is used for the WizNet5100 CS?

If you have a standard WizNet5100 shield, you have a pin collision on D4 between the SD card and your LCD.

Yes, the standard chip select for the SD library is D10. You would need to configure the Wiznet shield to use a different chip select or else you will have an SPI bus conflict. Currently you're initializing the SD library to use pin 10 so if the Wiznet is also using that, then that would cause the hang.

Yes, the standard chip select for the SD library is D10.

Bullshit.

the standard chip select for the SD library is D10.

the chip select pin, which defaults to the hardware SS pin (pin 10 on most....

A default isn't a standard.

Yes the SD library uses pin 10, which is a sensible use of pin 10 which (on Uno anyway) has to be made an output to prevent the Arduino becoming a slave by mistake, so we might as well use that pin as the selector for some slave or other.

But using it in the SD library as the SD's selector, doesn't make it any kind of "standard". It in no way precludes one from using any pin as the selector for any device; indeed, since ethernet shields hardwire the SD and Ethernet selectors into 4 and 10 respectively by the very nature of being a shield, you have no choice but to do that.