So far I was always using the Arduino based SD API to access files on a SD drive. But there are plenty of existing libraries which expect to use stdio.h operations to work with files. So I was digging into the topic and to my surprise this is possible: You just need to mount the SD card:

#include <FS.h>
#include <SD_MMC.h>
#include <stdio.h>

void begin() {
    if(!SD_MMC.begin("/sdcard")){
        Serial.println("Card Mount Failed");
        return;
    }
}

The value “/sdcard” is also the default value, so you could omit it. After that, all files are accessed under this directory. So to open a file on the root of the sd card you would use File file = fopen("/sdcard/file.txt","r");

I was testing this functionality on an AIThinker Audiokit and it is working like a charm.

Categories: Arduino

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *