SD card not working properly along with an LCD display

hey guys! please help me out...i'm working on a project where the readings of temperature and vibration are taken every two minutes and are recorded on an SD card as well as displayed on the lcd (im using the mega 2560 with the ethernet shield), ive used pins 4 and 53 for the SD card and pins...LiquidCrystal lcd(7, 8, 9, 10, 11, 12); for the LCD...the problem is the sd card just records some readings of vibration and just the first reading of the temperature not sure what going on?!

btw im quite new to the arduino..just started it a couple of months ago

thanks for all the help in advance :slight_smile:

A couple things wrong there. Don't use D10 for the LCD. That is the slave select for the w5100.
edit: Avoid D4 also. That is the slave select for the SD card.

I have trouble with the SD card if I do not disable the w5100 SPI before calling SD.begin(4).
edit: Apology for the delay, but I had some work stuff I had to do. Here is how you disable it:

pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

Omg! it works thank you so much :D...what is the w5100 btw? i thought the mega uses only pin 53 and not pin 10 for communicating with the SD card..please explain?

Good question! :slight_smile: Most don't even question that. D10 is not used by the SPI on the Mega. That is also why you can use D11-D13 for your LCD. You couldn't do that on an Uno. Those are SPI pins.

You can't use D10 because it is the w5100 (ethernet) slave select. That doesn't vary with most Aduino models. If the LCD uses that pin, when the LCD library sets that pin LOW, the w5100 SPI is active. It will assume all communication on the SPI is directed at it. All SPI devices will be confused if you are talking to a SD card, and the w5100 thinks that is for it. Then both devices will respond, normally producing garbage. :frowning:

ahh i see :relaxed: ..Thank you very informative!