Connecting a LCD IIC/I2C, a wifi shield and a SD card, and SD don't work HELP

Dear Arduino Community
I have the next project
I am connecting an arduino ATMEGA 2560, with an arduino WIFI shield:

with a LCD:

With a SD card module:

In order to take dust, temperature and humidity measurements from the environment and send them to a mysql data base.

At the beginning I had problems with the SD card module I had this one:

That worked perfectly in arduino UNO but not in the arduino 2560, therefore I change to the other one that I showed in the beginning and it worked in the arduino 2560

My problem is that when I connect the arduino wifi shield and the sd card module the sd card module doesn’t work, but when I connect just the SD card module with the arduino 2560 it works reading and writing data in the sd

Can anybody please help me and tell me what should I do?
Best regards,

This is the example code that I was running in order to verify that the program works:

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

 *                  correct
 * MISO - 50 - 12 - 51
 * SCK - 52 - 13 - 52
 * MOSI - 51 - 11 - 50
 * CS - 53 - 10 - 53
const int chipSelect = 53;
int contador = 0;
int i = 0;
Sd2Card card;

void setup() {
  // put your setup code here, to run once:
  Serial.print("Inicializando sd card...");
  //if (!card.init(SPI_QUARTER_SPEED, chipSelect)) 
  if (!SD.begin(chipSelect))
    Serial.print("fallo lectura de tarjeta");
  Serial.print("SD card inicializada ok");

void loop() {
  // put your main code here, to run repeatedly:
  //for(i=0; i<100; i++)
    contador ++;

void sdcard() {
  String dataString = "";
  dataString += String("Contador");
  dataString +=",";
  dataString += String(contador);
  dataString +=",";
  File dafile ="datalog.txt",FILE_WRITE);
  if (dafile) {
  else {
    Serial.println("error al abrir datalog.txt");

So that code is working to read and write the SD card? Post the non-working code that incorporates the wifi shield code (the LCD doesn’t matter right now*). Why are you using an external SD module when there is an SD slot on the shield? Do you, perhaps, have a chip select conflict between the two SD slots and the wifi shield chip select?

  • That can be its own can of worms.

A problem with some SD card modules is that level shifting circuitry drives the MISO (Master In/Slave Out) line even when the SD card is not selected. This prevents the SPI bus from being used by any other chip, like the WiFi chip.

I think with some modules it may be a lack of buffered level shifting that lets unbuffered MISO out when the card is not selected.
Having one gate of a 74HC125 or similar that lets MISO out only when the cards CS is active (low) solves the problem.

As shown in the schematic on Random Stuff: Interfacing a Serial SD Card Logger with RaspberryPi. the CATALEX SD Card Adapter leaves the MISO line driven at all times (all four /OE pins are grounded). This makes it impossible to use this adapter with other SPI devices.

It looks like you could fix the hardware by lifting pin 13 (/4OE) of the buffer chip and connecting it over to pin 8 (3Y, /CS_CARD). That would enable the MISO output only when the active-low CS_CARD was low.

Hi @groundfungus I am using the same code when I enable the WIFI shield in the arduino ATMEGA 2560, it just for trying if it works with the WIFI shield enabled and it doesn't. I didn't use the SD module of the wifi shield for two reasons, I need the device to be accesible because I need to create a housing for my project and unfortunately that is not possible with the wifi shield, and the other because the connection pins for the SD module are 50, 51, 52 and 53 for the mega 2560 and the WIFI shield does not connect in these pins.

Hi @CrossRoads what is the 74HC125, I didn't understand what would be my solution?

Hi @johnwasser pin 13 is SCK (for Arduino uno) so I have to connect it to pin 8?

Best regards,

Thanks for your answers

Hi @johnwasser pin 13 is SCK (for Arduino uno) so I have to connect it to pin 8?

Pin 13 "OF THE BUFFER CHIP" (you missed those words) should be connect to pin 8 of the buffer chip instead of being grounded.
Note: The WiFi Shield, like the Ethernet Shield, connect to the SPI bus through the 6-pin ICSP connector. That way they will work on the the UNO and MEGA.