Go Down

Topic: Micro SD failed  (Read 309 times) previous topic - next topic


Hello, I'm doing a project in which I intend to read data from a sensor and store it into a micro SD card.

I was trying some basic comands on the micro SD but it work ramdomly.

For example this kind of code works:
Code: [Select]
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

File myFile;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;

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

  SerialUSB.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    SerialUSB.println("initialization failed. Things to check:");
    SerialUSB.println("* is a card inserted?");
    SerialUSB.println("* is your wiring correct?");
    SerialUSB.println("* did you change the chipSelect pin to match your shield or module?");
  } else {
    SerialUSB.println("Wiring is correct and a card is present.");

but other basic examples as this one don't work:
Code: [Select]

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

File file;

void setup() {
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
 SerialUSB.begin(9600); // Initialize Serial Monitor USB
  Serial1.begin(9600); // Initialize hardware serial port, pins 0/1

  while (!SerialUSB) ; // Wait for Serial monitor to open

  // Send a welcome message to the serial monitor:

 SerialUSB.println("Initialising SD Card...");


 if(!SD.begin(10)) {
  SerialUSB.println("Initialising SD Failed");
 SerialUSB.println("Initialising SD Succesful!");

//create file
 SerialUSB.println("Creating File..");

SerialUSB.println("File Created!");



void loop() {
  // put your main code here, to run repeatedly:


And in any case I have been able to create the file and write on it.

I'm using an Sparkfun SAMD21 Mini Breakout board (similar to Arduino Nano) and an Arduino MicroSD Card Adapter.

Any advice is welcome.


Please provide a link to the exact microSD card adapter.


Go Up