Help with SD Card.

Not open for further replies.


Well-known member
#include "Arduino.h"
#include <SD.h>
#include <SPI.h>

const int chipSelect = BUILTIN_SDCARD;

File f1, f2;

void setup()
    while (!Serial) {
        ; // wait for serial port to connect.

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

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
        Serial.println("Card failed, or not present");
        // don't do anything more:
    } else {
    f1 ="File1", FILE_WRITE);
    f2 ="File2", FILE_WRITE);
    Serial.print("File1 = ");  Serial.println(f1);
    Serial.print("File2 = ");  Serial.println(f2);


// Add the main program code into the continuous loop() function
void loop()

I have been doing some work with Records on SD Card but was getting peculiar results.
I thought that it was possible to have more than one SD card file open at the same time but indications indicated that that might not be so.
As a quick test I wrote the above small program and the file identifiers f1 and f1 are returning the same value.
What might be going wrong? I am using Teensyduino 1.54b11.

Below is the output from the above sketch. Both files are created on the SD cards, but with the same identifiers I can only access 1.
Initializing SD Card...
File1 = 1
File2 = 1
PS I should have added that I am using a Teensy 3.5
Last edited:
AFAIK, the return value of is a class (check File in FS.h), which inside contains as private data
	union {
		// instances of base File class use this pointer
		File *f;
		// instances of derived classes (which actually access media)
		// use this reference count which is managed by the base class
		unsigned int refcount;
so, your printout says only that your refcounts are 1 for both files (they are open)
Don't ask me for more explanation, someone else may be able to explain
Yea it seems I might have got it all wrong. Thanks for support.
I guess I must continue trying to find my other similar problem with SD usage.
Thanks again.
Not open for further replies.