hi im curently testing project to read data from sdcard module and i have 4GB of micro sd
here is my code
`
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include <SPIFFS.h>
#include <TFT_eSPI.h> // Install this library with the Arduino Library Manager
// Don't forget to configure the driver for the display!
#include <AnimatedGIF.h> // Install this library with the Arduino Library Manager
#define SD_CS_PIN 5 // Chip Select Pin (CS) for SD card Reader
AnimatedGIF gif;
File gifFile; // Global File object for the GIF file
TFT_eSPI tft = TFT_eSPI();
const char *filename = "/x_wing.gif"; // Change to load other gif files in images/GIF
void setup()
{
Serial.begin(115200);
if (!SD.begin(SD_CS_PIN)) {
Serial.println("Card Mount Failed");
return;
}
Serial.println("Card initialized.");
// List files in root directory
//listFiles("/");
tft.begin();
tft.setRotation(2); // Adjust Rotation of your screen (0-3)
tft.fillScreen(TFT_BLACK);
// Initialize SD card
// Serial.println("SD card initialization...");
// SD.begin(SD_CS_PIN);
// Initialize SPIFFS
Serial.println("Initialize SPIFFS...");
if (!SPIFFS.begin(true))
{
Serial.println("SPIFFS initialization failed!");
}
// Reformmating the SPIFFS to have space if a large GIF is loaded
// You could run out of SPIFFS storage space if you load more than one image or a large GIF
// You can also increase the SPIFFS storage space by changing the partition of the ESP32
//
Serial.println("Formatting SPIFFS...");
SPIFFS.format(); // This will erase all the files, change as needed, SPIFFs is non-volatile memory
Serial.println("SPIFFS formatted successfully.");
// Open GIF file from SD card
Serial.println("Openning GIF file from SD card...");
// File sdFile = SD.open(filename);
File sdFile = SD.open(filename);
// Create a file in SPIFFS to store the GIF
File spiffsFile = SPIFFS.open(filename, FILE_WRITE, true);
if (!spiffsFile)
{
Serial.println("Failed to copy GIF in SPIFFS!");
return;
}
// Read the GIF from SD card and write to SPIFFS
Serial.println("Copy GIF in SPIFFS...");
byte buffer[512];
while (sdFile.available())
{
int bytesRead = sdFile.read(buffer, sizeof(buffer));
spiffsFile.write(buffer, bytesRead);
}
spiffsFile.close();
sdFile.close();
// Initialize the GIF
Serial.println("Starting animation...");
gif.begin(BIG_ENDIAN_PIXELS);
}
void loop()
{
}
// Callbacks for file operations for the Animated GIF Lobrary
void *fileOpen(const char *filename, int32_t *pFileSize)
{
gifFile = SPIFFS.open(filename, FILE_READ);
*pFileSize = gifFile.size();
if (!gifFile)
{
Serial.println("Failed to open GIF file from SPIFFS!");
}
return &gifFile;
}
void fileClose(void *pHandle)
{
gifFile.close();
}
int32_t fileRead(GIFFILE *pFile, uint8_t *pBuf, int32_t iLen)
{
int32_t iBytesRead;
iBytesRead = iLen;
if ((pFile->iSize - pFile->iPos) < iLen)
iBytesRead = pFile->iSize - pFile->iPos;
if (iBytesRead <= 0)
return 0;
gifFile.seek(pFile->iPos);
int32_t bytesRead = gifFile.read(pBuf, iLen);
pFile->iPos += iBytesRead;
return bytesRead;
}
int32_t fileSeek(GIFFILE *pFile, int32_t iPosition)
{
if (iPosition < 0)
iPosition = 0;
else if (iPosition >= pFile->iSize)
iPosition = pFile->iSize - 1;
pFile->iPos = iPosition;
gifFile.seek(pFile->iPos);
return iPosition;
}
void listFiles(String dirname) {
Serial.println("Listing files in directory: " + dirname);
File root = SD.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
`
and the questions is why the log shows
16:53:01.813 -> Openning GIF file from SD card...
16:53:02.304 -> [ 9200][W][sd_diskio.cpp:109] sdWait(): Wait Failed
16:53:02.351 -> [ 9204][E][sd_diskio.cpp:128] sdSelectCard(): Select Failed
16:53:02.351 -> [ 9210][E][sd_diskio.cpp:595] ff_sd_status(): Check status failed
16:53:02.825 -> [ 9716][W][sd_diskio.cpp:109] sdWait(): Wait Failed
16:53:02.825 -> [ 9720][E][sd_diskio.cpp:128] sdSelectCard(): Select Failed
16:53:03.329 -> [ 10226][W][sd_diskio.cpp:109] sdWait(): Wait Failed
16:53:03.371 -> [ 10230][E][sd_diskio.cpp:128] sdSelectCard(): Select Failed16:53:03.371 -> [ 10236][E][vfs_api.cpp:99] open(): /sd/x_wing.gif does not exist, no permits for creation
otherways i described to read " const char *filename = "/x_wing.gif"; "
and the log monitor shows "/sd/x_wing.gif "
and im already place file x_wing.gif already on root of my sdcard