SD card Troubles with Arduino Mega

Hello Everybody,

I get a problem while using a SD Card Reader at my Arduino Mega and need your help.

My SD Card Modul are this one:
https://www.conrad.de/de/p/tru-components-sd-karten-shield-2144972.html?gclid=Cj0KCQjw3v6SBhCsARIsACyrRAkKvQ6gXQxlV7zLGNfvq-EU-8-psU6sPFvmQy1K5963jkxykj4mEbEaAjsAEALw_wcB&hk=SEM&WT.srch=1&WT.mc_id=google_pla&s_kwcid=AL%21222%213%21549014662526%21%21%21u%21%21&ef_id=Cj0KCQjw3v6SBhCsARIsACyrRAkKvQ6gXQxlV7zLGNfvq-EU-8-psU6sPFvmQy1K5963jkxykj4mEbEaAjsAEALw_wcB%3AG%3As

On my Arduino UNO it works fine but the same code doesnt work on my Mega.
So it can`t be a damaged Reader or SD Card.

For my Mega I changed the SPI Pins from 10-13 -> 50-53 but it doesnt help. If I let the pins to 10-13, ist also doesnt work.
I also tried a level shifter 5V->3.3V.

I tried different things four hours but I can`t get the SD work on a Mega.

Here are the code that works on my UNO but not on MEGA:


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

void setup()
{
  Serial.begin(115200);

  //Init SD_Card

  pinMode(10, OUTPUT);    //<--- changed to 53 at Mega
  digitalWrite(10, HIGH); //<--- changed to 53 at Mega
  
  if (!SD.begin(10))
  {
    Serial.println("SD Card Init failed");
  }
  else
  {
    Serial.println("SD Card works");
  }
}

Can anybody help me please?

Regards,
Daniel

this works for me. I don't know WHY it works; I do know THAT it works:

#include <SD.h>
#include <SPI.h>
const int chipSelect = 53;

void setup()
{
  Serial.begin(115200);

  //Init SD_Card

  pinMode(chipSelect, OUTPUT);    //<--- changed to 53 at Mega
  digitalWrite(chipSelect, HIGH); //<--- changed to 53 at Mega
  
  if (!SD.begin(chipSelect))
  {
    Serial.println("SDv");
  }
  else
  {
    Serial.println("SD^");
  }
}
1 Like

изображение

I tried exactly these Pins.
Pins from 50 to 53 and also the ICSP Pins.

But ist doesn't Work for me.

once again
51, 50, 52, 53 or 50, 51, 52, 53 ?

Sorry, 51, 50, 52, 53 ^^

53 you can leave as 10 (or what you want)

Yes I tried that. But I Always get the Problem, that the SD-Card Initialization failed.

Thanks, I will try this later, when I am Back from Work.

Okay. I found my fault on the Mega.

In the past, I soldered a wire to the Pin 50 for my last Project and this one going to a resistor :see_no_evil: :speak_no_evil:

Yesterday I didn´t see that. Maybe to tired. Now it works fine.

But I thank you very much for your help and Ideas :blush:

regards,
Daniel

This might not be the most elegant solution but for SD cards (like the Adafruit Wave Shield), I keep the SD card shield on an Uno and communicate back and forth with a Mega using all the handy extra hardware Serial ports. Not sure if this is desirable option to you or possible, but it gets the job done.

Yeah, I had this also in mind, if I didn't get it to work, but now it is working.

why? what problem did you have with SD card wired to Mega?

Specifically, on the Mega, the Adafruit Wave Shield that uses the SD library, doesn't work. The SD card attaches to the SPI bus on pins 11, 12, 13 and 4 on the Uno, and 50-53 on the Mega. It can be changed by editing the necessary library and rewiring the shield to work on the Mega from what I understand. For my purposes though, I have found it easier to use the extra hardware serial ports on the Mega to send chars (I used every one available in the ASCII table for something, including a service mode) to the UNO with the Wave Shield attached as it was designed for.
In short, I guess it was more to do with the physical footprint of the SD card being used in a shield, as opposed to maybe a breakout board where I suppose it's easy to wire up as needed.

most good Arduino shields use the 2x3 SPI header

Yes, looks like the Wave Shield does indeed have that, thanks! I might consider that option in the future and just run female to male jumper wires to the SPI pins on the Mega.

Mega has the 2x3 SPI header

1 Like

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