Having problems with Arduino nano every and sd card

  • I'm using the Arduino nano every and micro SD card adapter.
  • I'm using the example code for reading and writing to the SD card.

The problem is that I only see when it fails and if it works i get nothing when it is supposed to tell me it has worked and also display all previous entries.

here is the code just in case

/*
  SD card read/write

  This example shows how to read and write data to and from an SD card file
  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

  created   Nov 2010
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

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

File myFile;

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


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

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

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("sd test");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

if you have more questions I'll be happy to answer them

the CardInfo test sketch from Examples works?

Make sure that the Micro SD Card is formatted FAT16 or FAT32 (Google for it).

You can see more detailed on this tutorial:

The Nano Every is a 5V processor, while SD cards are 3.3V.

Does the micro SD card adapter have the required I/O voltage level shifters?

im using this one https://www.amazon.com/HiLetgo-Adater-Interface-Conversion-Arduino/dp/B07BJ2P6X6/n and if it is the same as in here then yes it has it In-Depth Tutorial to Interface Micro SD Card Module with Arduino

it works gave me this
13:22:51.741 -> LIVE~270.IND 2023-08-31 16:17:42 16384
13:22:51.773 -> TMPSPO~1.LOC 2023-08-02 19:07:42 9966
13:22:51.838 -> LIVE~276.SHA 2023-08-31 16:17:34 10312
13:22:51.869 -> LIVE~3.IND 2023-08-31 16:17:42 65536
13:22:51.934 -> LIVE~1.SHA 2023-08-31 16:17:34 65536
13:22:51.966 -> LIVE
~4.IND 2023-08-31 16:17:42 4096
13:22:52.029 -> LIVE~288.IND 2023-08-31 16:17:38 65536
13:22:52.061 -> LIVE~5.SHA 2023-08-31 16:17:34 30
13:22:52.126 -> LIVE
~5.IND 2023-08-31 16:17:40 32768
13:22:52.157 -> LIVE~4.SHA 2023-08-31 16:17:34 4096
13:22:52.222 -> LIVE
~3.SHA 2023-08-31 16:17:34 8
13:22:52.254 -> LIVE~315.SHA 2023-08-31 16:17:34 10312
13:22:52.318 -> LIVE~~2.SHA 2023-08-31 16:17:34 2056
13:22:52.350 -> LIVE0D~1.SHA 2023-08-31 16:17:34 1088
13:22:52.414 -> VOLUME~1.PLI 2022-02-17 14:04:54 4283
13:22:52.446 -> _TIME~1.TXT 2023-08-31 15:58:54 4096
13:22:52.479 -> TEST.TXT 2000-01-01 01:00:00 120
13:22:52.543 -> TRASHE~1/ 2023-08-02 19:07:32
13:22:52.574 -> 501/ 2023-08-02 19:07:32
13:22:52.607 -> _50~1 2023-08-02 19:07:32 4096
13:22:52.639 -> _TES~1.TXT 2023-08-31 16:17:36 4096

it is formated as fat 32

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