SD Card handling

This commit is contained in:
Stefan Ostermann 2024-09-10 22:35:06 +02:00
parent 2326cd7eab
commit dfea791a2f
2 changed files with 37 additions and 10 deletions

View File

@ -2,6 +2,16 @@
The HannaBox is a Wifi enabled music player for toddlers and small children. It features an sd card reader, three buttons, a speaker up to 3 watts and an RFID reader. It is powered by a ESP32 microcontroller module.
## Preparation
The library https://github.com/schreibfaul1/ESP32-audioI2S is not available for Platformio in a working version. It is linked into the `lib` folder as a git submodule.
Init and pull the submodule before continuing:
```
git submodule update --init
```
## Microcontroller
We are using an ESP-WROOM-32 module. For the mp3 decoding we need a multicore CPU, be careful, there are some ESP32 with only one core.

View File

@ -90,6 +90,10 @@ bool asyncNext = false;
bool asyncPrev = false;
bool SDActive = false;
bool RFIDActive = false;
uint16_t voltage_threshold_counter = 0;
size_t free_heap = 0;
@ -102,22 +106,35 @@ std::map<String, String> rfid_map{{"67 152 204 14", "01-The_Box_Tops-The_Letter.
void activateSD()
{
if (SDActive)
return;
digitalWrite(CS_SDCARD, LOW);
if (!SD.begin(CS_SDCARD))
{
Serial.println("SD initialization failed!");
while (1)
;
}
SDActive = true;
}
void deactivateSD()
{
//SD.end();
digitalWrite(CS_SDCARD, HIGH);
SDActive = false;
}
void activateRFID()
{
digitalWrite(CS_RFID, LOW);
RFIDActive = true;
}
void deactivateRFID()
{
digitalWrite(CS_RFID, HIGH);
RFIDActive = false;
}
// Make size of files human readable
@ -508,25 +525,24 @@ void setup()
pinMode(CS_SDCARD, OUTPUT);
deactivateRFID();
Serial.print("Initializing SD card...");
activateSD();
Serial.println("SD initialization done.");
//deep sleep wakeup
esp_sleep_enable_ext0_wakeup((gpio_num_t)BTN_START_STOP, LOW);
Serial.print("Initializing SD card...");
if (!SD.begin(CS_SDCARD))
{
Serial.println("SD initialization failed!");
while (1)
;
}
Serial.println("SD initialization done.");
rootNode.buildDirectoryTree("/");
rootNode.printDirectoryTree();
readDataFromFile(mapping_file.c_str());
String progressPath = "/"+sys_dir+"/"+progress_file;
@ -710,6 +726,9 @@ String getStartupSoundDir() {
void loop()
{
deactivateRFID();
activateSD();
if (audio.isRunning())
{
if (asyncStop)
@ -717,8 +736,6 @@ void loop()
asyncStop = false;
stop();
}
deactivateRFID();
activateSD();
audio.loop();
if (currentNode != nullptr && !prepareSleepMode)
{