SD Card configuration in Arduino Mega + GPS Shield

Hello everyone.

I’m trying to use a SD Card on GPS Shield. The GPS Shield are linked in Arduino Mega.
But when i try to write, he doesn’t start.

Bellow, i’m using following code:

#include <SD.h>

File fileTXT;

void setup()
{
Serial.begin(9600);
SD.begin(53);

fileTXT = SD.open(“text.txt”, FILE_WRITE);
if (arquivoTXT) {
fileTXT.println(“I can write in SD Card”);
fileTXT.close();
Serial.println(“OK.”);
} else {
Serial.println(“Error opening file!”);
}
}

void loop(void) {
//nothing here
}

Someone can help me?

Thank you for your attention.

lucaaasxd:
Hello everyone.

I’m trying to use a SD Card on GPS Shield. The GPS Shield are linked in Arduino Mega.
But when i try to write, he doesn’t start.

Bellow, i’m using following code:

#include <SD.h>

File fileTXT;

void setup()
{
  Serial.begin(9600);
  SD.begin(53);
 
  fileTXT = SD.open(“text.txt”, FILE_WRITE);
  if (arquivoTXT) {
    fileTXT.println(“I can write in SD Card”);
    fileTXT.close();
    Serial.println(“OK.”);
  } else {
    Serial.println(“Error opening file!”);
  }
}

void loop(void) {
  //nothing here
}



Someone can help me?

Thank you for your attention.

The UNO and the MEGA use different pins for the SPI Interface. On the UNO Pins 10…13 on the MEGA 50…53, Unless your GPS/SD shield uses the ISP connector, you will have to correct the wiring.

Verify your GPS/SD shield uses Either the ISP connector for SPI or your GPS/SD shield is designed for the MEGA.

Chuck.