[Wiki][Draft]Everything there is to know about SD Card access

Troubleshooting

Something not working? Make sure your Pokitto’s battery is charged. Some cards can be picky about voltage.
Still not working? Try another card. FAT is brittle.

Available APIs

There are three ways to access the SD card from your code. Each has its pros and cons:

- PokittoDisk

Based on PetitFatFs (PFFS).
Pros: The smallest of the three libs.
Cons: Limited to one file at a time, 8-char filenames only.

#include <Pokitto.h>
void readExample(char *buffer, int length){
  pokInitSD();
  if(fileOpen("filename", FILE_MODE_READONLY) == 0)
    fileReadBytes(buffer, length);
  fileClose();
}

- SDFileSystem (SDFS)

Based on FatFs.
Pros: The most feature-complete.
Cons: The slowest, largest of the three. API is problematic.

#include <SDFileSystem.h>
...
void readExample(char *buffer, int amount){
  auto sdfs = new SDFileSystem(P0_9, P0_8, P0_6, P0_7, "sd", NC, SDFileSystem::SWITCH_NONE, 24000000 );
  auto file = sdfs->open("filename", O_RDONLY);
  if(file){
    file->read(buffer, amount);
    file->close();
  }
}

- File

Also based on FatFs.
Pros: Faster than the other two. Simple API.
Cons: Still under development, but already available in PokittoLib.

#include <File>
void readExample(char *buffer, int amount){
  File file;
  if(file.openRO("filename"))
    file.read(buffer, amount);
}
5 Likes