1 year ago
#364264
Adam
ESP32 - fs.open is slower as filename increments
ESP32 using VScode platformio. Adafruit sd card module connected using spi and standard SD library for ESP32. I have files stored on SD card and they are named as follows:
1, 2, 3, ... 253, 254.
All files are 3kb in size and contain ascii characters, and alternate files are exact copies.
I noticed that as the code continued to open and close files for reading (Starting from 1, incrementing by 1, finishing at 254), the output to my RGB display was becoming slower and slower.
I pinpointed the exact cause by measuring the time taken to execute some lines for file 1 and file 254. This line was causing the issue:
for (byte x=1; x<=254; x++) { // Iterate for all images on sd card
fname = "/" + String(x); // Form image file name
unsigned long t1 = millis();
image = fs.open(fname, FILE_READ); //LINE CAUSING DELAY
unsigned long t2 = millis();
unsigned long time = (t2-t1);
Serial.println("Time = " + (String) time);
Where fname is a number ranging from 1 - 254. It seems as the number increases it takes longer to open the file:
Time for file 254 = 74ms Time for file 1 = 1ms
The time decreases in a uniform maner as file goes to 1. It is not caused by the filename length (ie. 254 is 3 digit, 1 is 1 digit), file 101 had a proportionate increase in open time than file 200, they were not the same.
Anyone have any idea why this is happening? It is a crucial issue in my code as the output needs to be at a constant speed and not decrease as the file increments.
arduino
esp32
sd-card
0 Answers
Your Answer