1

Micro-SD breakout] [Connection to MEGAI am having quite a bit of trouble trying to get my Arduino MEGA 2560 to read my micro-SD card. My wiring is as follows:

Breakout    Arduino
5v            5v
Gnd           Gnd
CLK           52
DO            50
DI            51
CS            53
CD            Was not connected and then connected to 47 (neither worked)

Here is my code:

#include <Wire.h> //library necessary to use I2C communications bus
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
#include <SD.h>
#include <SPI.h>

const uint8_t chipSelect = 53; //chipSelect pin for the SD card Reader
const uint8_t cardDetect = 47;

File CO2Data; //Data object you will write your sensor data to

void setup() {
Serial.begin(115200);//"begins" the serial monitor so you can print stuff out when connected to the computer (set baud rate to 115200)
Wire.begin ();//begins the I2C communications bus so it can talk to the K33

Serial.print("Initializing SD car...");
pinMode(53, OUTPUT); 

if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1) ;
}
Serial.println("card initialized.");
File CO2data = SD.open("datalog.txt", FILE_WRITE);
if (! CO2data) {
Serial.println("error opening datalog.txt");
// Wait forever since we cant write data
 while (1) ;
}}

The SD card is formatted to FAT32.

Thank you for any help!

  • try the CardInfo example – Juraj Jun 10 at 18:48
  • I did try to cardinfo example and came up with the following message:Initializing SD card...initialization failed. Things to check: * is a card inserted? * is your wiring correct? * did you change the chipSelect pin to match your shield or module? – CMil Jun 10 at 19:28
  • Update: I set chipselect to 10 in the Cardinfo example and card is found and present. However, it still won't run in my sketch. I have gone through trying different pin combinations. – CMil Jun 10 at 21:54
  • do you have some shield on the Mega or some other devices wired to it? – Juraj Jun 11 at 14:15
  • I do, I have a couple of things wired to the MEGA: Adafruit BME680 (temp pressure) using the I2C interface (SCL wired to 21 and SDA wired to 20) and a KC-30 CO2 sensor wired to pins 10 and 9. – CMil Jun 11 at 21:45
0

SOLVED: The non-analog ground line attached to the micro-SD was pulling down my voltage. Just hardwired to different ground and problem solved! (Check your voltages).

From what I could gather. the ground pin on the MEGA inline with the digital pins was a different ground source (digital ground). I literally took the ground lead from the SD board and just touched it to the housing of the USB connector on the MEGA and my voltage came back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.