Description
What MCU/Processor/Board and compiler are you using?
Waveshare ESP32-S3-Touch-LCD-5; TF-Card Slot is directly on the board ; Arduino IDE
What do you want to achieve?
Loading an Image from the TF Card so that it is displayed on the screen
What have you tried so far?
Displaying an Image, which is stored as C-Array on the ESP32. → worked
But because the storage is maxxed out, i tried to extend the Waveshare SD Card Demo project. But this didn’t work. Even Chatgpt couldn’t solve my problem.
I would be so grateful if sombody would help me or even has a code for me which work
Code to reproduce
This is the original demo project for a sd card.
When i compile this one, i can see the txt files on the computer when I insert the sd card.
#include "waveshare_sd_card.h"
// Initial Setup
void setup(){
Serial.begin(115200);
Serial.println("Initialize IO expander");
/* Initialize IO expander */
ESP_IOExpander *expander = new ESP_IOExpander_CH422G((i2c_port_t)I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO);
expander->init();
expander->begin();
expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
expander->multiDigitalWrite(TP_RST | LCD_BL | LCD_RST, HIGH);
// Use extended GPIO for SD card
expander->digitalWrite(SD_CS, LOW);
// Turn off backlight
expander->digitalWrite(LCD_BL, LOW);
// When USB_SEL is HIGH, it enables FSUSB42UMX chip and gpio19, gpio20 wired CAN_TX CAN_RX, and then don't use USB Function
expander->digitalWrite(USB_SEL, LOW);
// Initialize SPI
SPI.setHwCs(false);
SPI.begin(SD_CLK, SD_MISO, SD_MOSI, SD_SS);
if (!SD.begin()) {
Serial.println("Card Mount Failed"); // SD card mounting failed
return;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached"); // No SD card connected
return;
}
Serial.print("SD Card Type: "); // SD card type
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN"); // Unknown Type
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize); // SD card size
// Testing file system functionality
listDir(SD, "/", 0);
createDir(SD, "/mydir");
listDir(SD, "/", 0);
removeDir(SD, "/mydir");
listDir(SD, "/", 2);
writeFile(SD, "/hello.txt", "Hello ");
appendFile(SD, "/hello.txt", "World!\n");
readFile(SD, "/hello.txt");
deleteFile(SD, "/foo.txt");
renameFile(SD, "/hello.txt", "/foo.txt");
readFile(SD, "/foo.txt");
testFileIO(SD, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); // Total space
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); // Used space
}
// Main Loop
void loop() {
}
This is the waveshare_sd_card.h:
#ifndef __SD_CARD_H
#define __SD_CARD_H
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include <ESP_IOExpander_Library.h>
// Extension IO pin definition
#define TP_RST 1 // Touch screen reset pin
#define LCD_BL 2 // LCD backlight pinout
#define LCD_RST 3 // LCD reset pin
#define SD_CS 4 // SD card select pin
#define USB_SEL 5 // USB select pin
// I2C pin definitions
#define I2C_MASTER_NUM I2C_NUM_0 // I2C Master Number
#define I2C_MASTER_SDA_IO 8 // I2C data line pins
#define I2C_MASTER_SCL_IO 9 // I2C clock line pin
#define SD_MOSI 11 // SD card master output slave input pin
#define SD_CLK 12 // SD card clock pin
#define SD_MISO 13 // SD card master input slave output pin
#define SD_SS -1 // SD card select pin (not used)
void listDir(fs::FS &fs, const char * dirname, uint8_t levels);
void createDir(fs::FS &fs, const char * path);
void removeDir(fs::FS &fs, const char * path);
void writeFile(fs::FS &fs, const char * path, const char * message);
void appendFile(fs::FS &fs, const char * path, const char * message);
void readFile(fs::FS &fs, const char * path);
void deleteFile(fs::FS &fs, const char * path);
void renameFile(fs::FS &fs, const char * path1, const char * path2);
void testFileIO(fs::FS &fs, const char * path);
#endif