SD Card Shield configuration on Arduino mega 2560 REV3?

I thought I had done everything that the post told me to but apparently I have not. Please let me know if you see the mistake. I appreciate your time.

I suspect you have done too much. The forum post is from 2011 and out of date.

Don't modify any code in the Adafruit version of Sd2Card.h. Just make the changes to CardInfo described here Older Datalogger Shield Leonardo & Mega Library | Adafruit Data Logger Shield | Adafruit Learning System.

Sadly the Adafruit logger is also out of date since it does not connect to the ISP/SPI header. It is a good product for 328 Arduinos but not for other Arduino boards. The Adafruit software SPI is very slow but will work if you don't need much performance.

Here is a test with Adafruit software SPI:

Buffer size 100 bytes
Starting write test. Please wait up to a minute
Write 49.78 KB/sec
Maximum latency: 107868 usec, Minimum Latency: 84 usec, Avg Latency: 2002 usec

Starting read test. Please wait up to a minute
Read 55.07 KB/sec
Maximum latency: 17232 usec, Minimum Latency: 80 usec, Avg Latency: 1809 usec

Here is a test using hardware SPI with the latest SdFat and the same SD card:

Buffer size 100 bytes
Starting write test. Please wait up to a minute
Write 325.35 KB/sec
Maximum latency: 64340 usec, Minimum Latency: 84 usec, Avg Latency: 302 usec

Starting read test. Please wait up to a minute
Read 354.38 KB/sec
Maximum latency: 2008 usec, Minimum Latency: 80 usec, Avg Latency: 276 usec

The newest SdFat has a slightly faster software SPI. Here is a test of SdFat software SPI with the above SD card:

Buffer size 100 bytes
Starting write test. Please wait up to a minute
Write 106.60 KB/sec
Maximum latency: 67568 usec, Minimum Latency: 84 usec, Avg Latency: 932 usec

Starting read test. Please wait up to a minute
Read 143.79 KB/sec
Maximum latency: 6108 usec, Minimum Latency: 80 usec, Avg Latency: 689 usec

I am attempting to create a data logger that will sniff both sides of a UART bus and log the data to the SD so I have a record of the messages that were sent back and forth. The Baud rate for the UART connection is 115200. I was going to run the RX to one of the serial inputs on the mega and the TX to another. What data logger would you suggest for such a task? Would this adafruit logger get the job done at that baud rate?

Thanks for the heads up on the change to cardinfo. I missed that change. Just to be clear I don NOT need to set the MEGA_SOFT_SPI to 1 inside the Sd2Card.h. I currently have it set to 0 and the card info seems to work like it should.

I appreciate the help.

The Baud rate for the UART connection is 115200.

This is really hard on Arduino.

I don't think the Adafruit shield will work in software SPI mode. Adafruit software SPI is a CPU hog on Mega.

Hardware Serial on Arduino is also CPU intensive.

I have logged serial data at 115200 to an SD on a Mega but I used my latest version of SdFat on Mega with hardware SPI and my version of Serial.

I wrote a replacement for Arduino Serial that has more buffering options greiman (Bill Greiman) · GitHub. SerialPort has an example serial to SD logger.

SdFat is here Google Code Archive - Long-term storage for Google Code Project Hosting. but I will soon move it to github.

You need to either use a shield like the Ethernet/SD shield that connects to the ISP/SPI header or connect a module like this MicroSD card breakout board+ : ID 254 : Adafruit Industries, Unique & fun DIY electronics and kits to pins 50 - 53.

What about using the adafruit data logger and wiring it to the the 50's pins? Could I then use your serial lib and sdfat lib to get that to work or no? Wouldn't wiring it like that be the same as Adafruit MicroSD breakout you mentioned? Again, I really appreciate the help. Thanks.

You can wire the Adafruit shield to pins 50-53. You need to make sure the wiring is reliable.

I have used a Mega prototype board and soldered the SD module to the prototype board.

I am not sure you can accomplish what you want with two 115200 serial streams. Capturing one 115200 stream is about the limit for an Mega.

@fat16lib
Thanks so much for the guidance. I have made the HW wiring changes to the shield and wired up the LED to run the data logger example you had mentioned. I am able to create the Serial file on the card and the LEDs blink as stated in the readme file but the Serial file is empty. I changed it to a .txt with if (!file.open("SERIAL.txt", O_WRITE | O_CREAT | O_AT_END)) to see if that made a difference or not which it did not. I also changed the serial port on the logger to NewSerial1. I don't think that should matter should it? I have a wire from Sender board pin 1(TX0) to Logger board pin19 (RX1). The grounds are also tied together. I put a scope on the output of the sender and there is definitely data there. Not sure what to do next.

I have to make a little correction, actually the pin 53 HAS TO be defined OUTPUT.

In conclusion, for a Mega with Ethermet Shield:

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

I have read of many who have had problems with Mega + Ethernet + SD, like me.
All of them were upgrading from One to Mega, and the same sketch wasn't working anymore.
After so many attempts and failures, I considered that:
-One uses pin 10, 11, 12, 13 and ICSP;
-Mega uses only ICSP.

Try to push the ICSP connectors, neglecting the laterals.
If it does, shorten the lateral pins.

Ciao,
Dritan

I don't see that there was ever a resolution to this thread. I was having the same problem. My SD card would not initialize when I switched to using the mega 2560 R3. I tried pin 53 and still nothing. According to http://arduino.cc/en/Hacking/PinMapping2560 the SS pin is pin 19 on the mega? I used pin 19 and that worked for me, my SD card works now.

The solutions:

  1. Use an SD card shield that connects the SD card (via voltage converter) to the ICSP header, instead of pins 10-13. All Arduino official shields (wifi,ethernet,wireless etc.) work this way
  2. In case your shield is hardwired to pins 10-13, enable software SPI mode by setting #define MEGA_SOFT_SPI 1 from #define MEGA_SOFT_SPI 0, or rewire it to MEGA's SPI pins.

Method 2, part 1 or 2 isn't as clean-cut as 1 since you are responsible for finding the line and changing it or wiring the pins.

I've been using sd cards with MEGA and arduino uno compatible boards I made myself for the past few years, Solution 1 works fine. I use arduino official shields.

@ liudr

Thank you very much.

Method 2 works great.

I have been trying to get the SD card work with my Uno Ethernet+SD shield, but unfortunately to no avail. When I use it with the Uno by placing it on top of it as it's supposed to, it works fine. However, when I connect it by wires to even the Uno, it doesn't work as well.

I would like to confirm that I'm doing everything correctly.

So, I use 6 wires in total for connecting the shield to the Mega:
gnd->gnd
5v->5v
4->53
11->51
12->50
13->52

I have tried both original SD library and the Adafruit one, but both didn't work.
The beginning of code, in the case of the Adafruit library, looks like this.

...
const int chipSelect = 4;    

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  pinMode(53, OUTPUT);


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  while (!card.init(SPI_HALF_SPEED, 53,51,50,52 )) {
...

Every time I open the serial monitor, it says that the initialization failed. However, if I let the Arduino function for a while and it spits out multiple failures, then occasionally it gives the following:

Card type: SD1
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

Of course, I have tried formatting the card. I feel that this partial progress might be an error in the library since it has given the same message even if the chipSelect pin assigned in the code is completely wrong.
I tried commenting out the lines about pin 10 as well. Is everything correct? Should I physically connect a wire to the pin 10 of the ethernet shield, since it's not connected to anything (I tried that as well, didn't work but suppose it doesn't hurt to ask)?

Which SD shield are you using? A link to the hardware might help.

growqx:
I have been trying to get the SD card work with my Uno Ethernet+SD shield, but unfortunately to no avail. When I use it with the Uno by placing it on top of it as it's supposed to, it works fine. However, when I connect it by wires to even the Uno, it doesn't work as well.

So, I use 6 wires in total for connecting the shield to the Mega:

So it works on the Uno when you place it on top. it doesn't work on the Uno when you use jumpers. Now you're trying to use jumpers on the MEGA?

What happens when you place it on top of the MEGA and only jump pins 11-13 to their 51-53 equivalents?

Also, if you ever do need to format the card, make sure you don't use quick format.

Hi, I am new to Arduino and I need the library SD, SPI for ATMega2560 R3, could someone give me a link to download and tutorial where download? Thank.

I try to use a 2560 R3 Arduino with a shield Data Logging V1.0. as follows:

I use 4 wires as follows:
Shield Mega
SD_CS D10 53
MOSI D11 51
MISO D12 50
SCK D13 52

I use the .h .cpp CardInfo.ino files from Adafruit dated 10.11.2014

https://github.com/adafruit/SD/archive/master.zip

The only changes made in Cardinfo.ino are:

// const int chipSelect = 4;
chipSelect const int = 53;

// pinMode (SS, OUTPUT);
pinMode (53, OUTPUT);

I don't understand this lines because, I don't use it!

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

The shield is plugged MEGA2560r3 it and it does not work.

It never recognizes the memory card (I have tried 3 differents)
Finally, is someone he managed to run it ? and what is the way???

Please, sorry for my bad english :-[

Hi friends
Does sombody knows why I getting wrong data saved on my SD?
I am working with uno and mega
and botch has same error
take a shot look in this video

this is the code I am using.
tks and best regards

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

const int chipSelect = 10;
String dataString = "";

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("Initializando 'SD card'...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(chipSelect, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Falla SD, o no está presente");
    // don't do anything more:
    return;
  }
  Serial.println("SD Ok.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int I = 1; I <= 10; I++) {
    dataString += String(I);
    if (I < 10) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

hello frnds....this is rahul i am a student of robotics. i want tell u that if u also student of
The coding will be easier. If it is just 8051, external ADC will be needed while arduino mega has its own ADC. More pins on arduino means more options to attach other peripherals, as in a LCD, wireless control etc. Clock Speed for mega is more than that of 8051.
guys if u want any type help about this

this site will make sure help u more and more

Hi,

I know this is an old topic - but still relevant.

I have been trying to get my gsm/sd shied to work with my mega 2560 with no luck.

This is the number one hit when searching - so I will post my solution here.

I turned out my problem was the power connection.

If you are using jumperwires to connect the shield - make sure to connect the 3.3v power supply.

I have only connected the 5v. supply.

And the make sure you connect the SPI correct

SPI Uno Mega
SS 10 53
MOSI 11 51
MISO 12 50
SCK 13 52

The pins noted above are what I thought would be the case.
However when the shield is also for a 5" or 7" display that does not seem to be the case because none of the 4 shield I have from different manufactures can access the SD card and nor can the SD card slot on the display itself.
The only other thing I can think is that the driver chip is missing even though when I ordered the shields I specified I needed access to the SD card and I was assured that it was correct.