Cannot create files on SD Card.

Using the Adafruit Datalogging shield P1141 and UNO R3 running a program to record data to SD Card. Took it out last week and it recorded data and worked fine.

I have used the SD Formatter program program to format the cards. I have 2 8GB and 1 32GB SD Cards. Size is reported wrong – 3485 MB for the 8GB card.

I first got it to work using the SD datalogger program referred to at: Adafruit Assembled Data Logging shield for Arduino : ID 1141 : $13.95 : Adafruit Industries, Unique & fun DIY electronics and kits

The other day I was modifying the other part of the code and it quit initializing the SD card. I thought maybe it was broken so I tried a brand new datalogging shield #1141 and even a new UNO R3. No play - it will not open the file on the card. I have tried 2 or 3 of the SD reference sketches. They all fail at one point or another, now. Backing up to the examples. Example code and results below…

When it does see the card, it reports the size wrong (like 3.4GB for an 8 GB card – see printout).
That makes me think that I have something wrong in the driver calls. Maybe getting my libraries mixed up? Do I need to use a different libraey for the larger SD cards? 8 GB is the smallest I could buy new!

Call using: if (!card.init(SPI_HALF_SPEED, chipSelect)) does report the card present.
The initial call I used to int card_status = SD.begin(10) always fails.

Card.init() It initializes the card but gets the size wrong. Call to fails.

.. . . . . . . . . . . . .
OUTPUT to Serial Monitor:


Initializing SD card...At volume.init(card): Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3654471680
Volume size (Kbytes): 3568820
Volume size (Mbytes): 3485

At root.openRoot(volume) call.
Files found on the card (name, date and size in bytes):

New filename is: LOGGER00.CSV
At call to SD.exists(filename): file not there, open it.
After call to, returns: 0
0Failed - couldnt create file: LOGGER00.CSV


//Test_18b-121716 modified by Bill Allen

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

File logfile;
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 10; // was 4

void setup() {
while (!Serial) {

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

Serial.print("At volume.init(card): ");
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
} else {
Serial.println("Wiring is correct and a card is present.");

Serial.print("\nCard type: ");
switch (card.type()) {

if (!volume.init(card)) {
Serial.print("At volume.init(card): ");
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");

uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);

volumesize = volume.blocksPerCluster();
volumesize *= volume.clusterCount();
volumesize *= 512;
Serial.print("Volume size (bytes): ");
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;

Serial.println("\nAt root.openRoot(volume) call. \nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume); | LS_DATE | LS_SIZE);

char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i / 10 + '0';
filename[7] = i % 10 + '0';
Serial.print("\nNew filename is: ");
Serial.print("At call to SD.exists(filename): ");
if (!SD.exists(filename)) {
// only open a new file if it doesn't exist
Serial.println("file not there, open it.");
logfile =, FILE_WRITE);
Serial.print("After call to, returns: ");
break; // leave the loop!
if (!logfile) {
Serial.print("Failed - couldnt create file: ");
Serial.print("File successfully opened: ");

// Yes this should be behind other code but let's see if it will write?
for(int i=0; i<10; i++) {

// logfile.close(); // When do I need to Close the file or does flush take care of the data?

void loop(void) {

Why don't you just use the standard SD library and the standard SD read/write example included in the IDE? That way, you might see if you actually have a problem.
I understand the maximum file size is 4Gb but you can have more than one.

Thanks - That's what I have been doing for 2 days - trying all the examples I can find, but none of them work. ReadWrite example uses the SD.begin(), which as I say, has stopped working. That is the routine I started with that did work. Other than the computer, the cable is the only thing left to change. Well, maybe reload the IDE but that's extreme. That is why I am looking at other methods of following the rabbit hole.

Here is the output of ReadWrite - it won't even get so far as to open the file in line 36, much less write anything! Have I mixed up my LIB's or what! I am going to try a different cable but I am pretty sure this one is good. But now the IDE & Board won't run any of the sketches with the SD cards. It just quit a few days ago and is driving me nuts!

I'm going to empty the \Temp folder. The board and Ardiono are both new as of yesterday and won't talk to the cards. Using card.init() I can at least get to that step. When it does recognize the card it says it is the wrong size (3.4GB instead of 8 GB (7.9 or something, really)).
Also going to try turning on pin 10. Did that once, though.

Here's the output and sketch.

Output of ReadWrite:
Initializing SD card...initialization failed!

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 10

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:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only

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

if (!SD.begin(10)) { // was 4 CS is pin 10.
Serial.println("initialization failed!");
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 ="test.txt", FILE_WRITE);

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

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

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

void loop() {
// nothing happens after setup

Well, maybe reload the IDE but that's extreme. the rabbit hole.

It might sound extreme, but it doesn't cost anything and can be done immediately.

Here is the output of ReadWrite - it won't even get so far as to open the file in line 36, much less write anything! Have I mixed up my LIB's or what!

Quite possibly and, since the standard library is included with the IDE, re-installing it is starting to look increasingly like a good idea. The clunky-looking original code gives further thought in this direction - hence my comment - and there may well be a mis-match between code and library. There may be more than one SD library called SD.h, but I don't know of any. At least, by re-installing, you will have no doubt about what you've got.

I had similar problem. I made a change in an old project using SD-card. I run Arduino version 1.8.0 on Windows.
Result was that I no longer could communicate with SD-card.

Downgrading to 1.6.12 made no difference.

Downgrading to 1.6.3 gave this error:

Multiple libraries were found for "SD.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\SD
Not used: K:\Dur2k_D\Download\Programmering\Arduino\ArduinoIDE\libraries\SD
Error compiling.

I removed the library on C: and after doing so I regained access to the card. Great, but I want it to work with 1.8.0.

Other differences 1.8.0 vs 1.6.3 are that the old compiler use 55974 bytes of program storage space and 6302bytes of global variables. The newer use 52000, 6397. The newer also warns about deprecated conversion from string constant to 'char*'.

I am pretty new to SD Card handling with Arduinos, but for my next bigger project SD card is essential.

So I started testing with some cards I had in my stock. With all of them I ran into the same problem that even when the card was detected by Arduino (either using the SD library which comes with IDE or with SdFat which has to be installed from GitHub) - after a few other tests or drawing / re-inserting the card (power off of course) none of the cards (I used 3 different ones with 1GB, 2GB and 4GB) could be initialized (=not mounted) in the Arduino again.

What got me back in the race: SDFormatter as the tool which is strongly recommended (see very first thread in this subsection "Storage" of the forum) when it comes to format SD Cards. SDFormatter v4.0 is available for Mac (I use OSX Yosemite) and for Windows.

First I also failed with the SDFormatter - same problems as before when I had formatted them in my Mac.
But then - by chance I set the format option "Interoperability" ON - that did the trick! Now I can use all my cards in the SD examples and SdFat examples.

Instead of "interoperability" the menu in Windows talks about "Format Size Adjustment" -> this should be checked "ON".

Hope that will help you as well.

To be honest, none of my microSD cards would work (4GB, 8GB, 16GB) apart from a very old 128MB card (reformatted them with the SD utility, etc). I was using IDE v 1.8.0. I tried this in my office. I went home where on my laptop I had v1.6.9, and there after recompiling and uploading, everything worked!. It's definitely a problem with the 1.8.0 distro - the SD library apparently has problems at least on my setup. I didn't upgrade anything on my work PC as it was a clean install of 1.8.0 so no mixture of different libs. In any case I reverted to using the sdfat library which works.
Just my 2 cents.

FYI I got it to work on 1.8.2. So it was a bug after all...

ARDUINO 1.8.1 - 2017.01.09

* Fixed font rendering not anti-aliased on Windows (regression)
* Increased number of colors on serial plotter to 8, thanks @cousteaulecommandant

* Fixed regression in SD library. Thanks @greiman