MEGA2560 not working with Ethernet Shield 2 SD card

Hello,

I used SunFounder MEGA2560 and SunFounder Ethernet Shield 1 (w5100). I had a problem using TCP and UDP interchangeably (see https://forum.arduino.cc/index.php?topic=711850.0). I suspected that the cause for this is either the non original HW or the w5100. So I bought the original Arduino MEGA2560 and original Arduino Ethernet Shield 2 (w5500). Indeed the TCP/UDP problem disappeared, however I encountered a new problem that I cannot initialize the SD card on the shield (timeout error). I tried the SunFounder MEGA2560 with the w5500 and all is working well, TCP/UDP and SD card. I tried all combinations and the only non-working combination is both original boards. To be more clear, with the original Arduino MEGA2560 board and SunFounder w5100, the SD card can be initialized. What can be the cause for it? Should I ask for a replacement for the original Arduino MEGA2560 board?

Thanks a lot,
Boaz.

  • set SC pin of Ethernet LOW, then initialize the SD card and then the Ethernet library.
  • use Ethernet.init(10); to set the CS pin for Ethernet

If I understood you correctly, following is the code that you suggest that I'll write:

  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  if (!SD.begin(4))
    Serial.println("Failed to initialize SD card");
  Ethernet.init(10);

I'm still getting the error message.

could you please post the complete minimal test sketch you use

This is the sketch:

#include <SD.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  //pinMode(10, OUTPUT);
  //digitalWrite(10, HIGH);
  if (!SD.begin(4))
    Serial.println("Failed to initialize SD card");
  else
    Serial.println("SD card is initialized");
}


void loop() {
}

If I uncomment the two lines above the SD.begin(4); it is still working with the SunFounder MEGA2560 and not working with original Arduino MEGA2560. If I set pin 10 to LOW, it is not working with boards.

the board selected in Tools menu is "Arduino Mega or Mega 2560" for both boards?

Yes

it is a very strange problem. the SunFounder MEGA2560 is an exact clone of Arduino Mega.
and Ethernet works on both without problems?

Yes. I suspect that this is some strange HW problem with the new board that I just received. I can’t seem to find a reason to why this should happen, but I’m not enough familiar with HW.

Thanks a lot for trying to help.

you can contact Arduino support here https://www.arduino.cc/en/contact-us
select Technical Support

sorry, one more test. try the CardInfo example

OK! Problem (kind of) resolved. This problem appears to be related to the SD card itself. I replaced the SD card that I used with two other cards. With both of those other cards all boards combinations work perfectly. The problem reproduced with the first (bad) SD card. It is very strange why it is working with the SunFounder board and not with the Arduino board. I tried the bad SD card on a PC with a card reader and it works fine. Well, I guess that for me this issue is over, though it remains strange.

Again, thank you very much!