Go Down

Topic: Level shifting micro sd breakout doesn't write to file. (Read 648 times) previous topic - next topic


Hello everyone,

As you can read in the title, my sparkfun level shifting micro sd breakout doesn't write to files on the SD card. I'm using the following components:
-Arduino pro mini 3.3v ATMega328P
-Sparkfun Level shifting micro sd breakout
-Kingston 16GB micro sdhc cards

The arduino and breakout are hooked up to each other as seen in this fritzing schematic:

The breakout board does make new files, but won't write to them.

Cardinfo give the following serial data:
Code: [Select]
Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 2696937472
Volume size (Kbytes): 2633728
Volume size (Mbytes): 2572

Files found on the card (name, date and size in bytes):
SYSTEM~1/     2017-12-01 17:25:32
  INDEXE~1      2017-12-01 17:25:32 76
TEST.TXT      2000-01-01 01:00:00 0

I wrote a dummy code to demonstrate what happens, as i cannot give you the full code of my boss's project:

Code: [Select]

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

File myFile;

const int chipSelect = 8;

void setup() {
  // put your setup code here, to run once:
  if (!SD.begin(chipSelect)){
    Serial.println("SD.begin failed!");
if (!SD.open("TEST.TXT", FILE_WRITE)){
    Serial.println("SD file problem!");
  else {

void loop() {
  // put your main code here, to run repeatedly:
  if(SD.open("TEST.TXT", FILE_WRITE)){
    myFile.write("Test"); myFile.write("\r\n");
    myFile.write("1, 2, 3"); myFile.write("\r\n");
    Serial.println("SD file problem 2!");

This code returns "SD file problem 2!", which indicates that writing to the file isn't possible for some reason.

Why does it not write, and how can i solve that?

Thank you all in advance!


I solved it myself already, after some more searching on the internet (i had been searching for about 3 hours already) i found that my coding was faulty:

SD.Open() can't be called like it was, but needed to be called as myFile = SD.Open()

Go Up