0

I am currently facing a problem that I run out of idea. I have a waveshare ESP32-S3-Touch-LCD-2 (https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-2) that features a display, SD cardslot and camera. My goal is to display a livefeed from the camera on the display and be able to store an image once a button is pressed. However I can not get the display and SD card work together. One of them fails. Individually they work fine.

I suppose there is a problem with the SPI not being able to handle the ressources but I don't know how to fix is.

Any hint is very apprechiated! Thanks in advance!

My code:

Only SD Card:

#include "FS.h"
#include "SD.h"
#include "SPI.h"

// Pin-Konfiguration für SD-Karte (SPI)
#define SD_CS    41
#define SD_SCK   39
#define SD_MOSI  38
#define SD_MISO  40

void setup() {
  Serial.begin(115200);
  delay(2000); 
  Serial.println("\n--- Minimaler SD-Karten-Test ---");

  // Den SPI-Bus explizit für die SD-Karte initialisieren
  SPI.begin(SD_SCK, SD_MISO, SD_MOSI, -1);
  
  Serial.println("Versuche, die SD-Karte zu initialisieren...");
    if (SD.begin(SD_CS)) {
    Serial.println("\nERFOLG! Die SD-Karte wurde erkannt!");
    Serial.print("Kartentyp: ");
    uint8_t cardType = SD.cardType();
    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");
    }
    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
    Serial.printf("Kartengroesse: %llu MB\n", cardSize);
  } else {
    Serial.println("\nFEHLER: Die SD-Karte konnte nicht initialisiert werden.");

  }
}

void loop() {
  // Bleibt leer.
}

Only display:

#include <Arduino_GFX_Library.h>
#include "SPI.h"

// Pin-Konfiguration für Display (SPI)
#define GFX_BL   1
#define GFX_CS   45
#define GFX_SCK  39
#define GFX_MOSI 38
#define GFX_MISO 40 // Oft nicht zwingend notwendig, aber zur Sicherheit anschließen
#define GFX_DC   42
Arduino_DataBus *bus = new Arduino_ESP32SPI(GFX_DC, GFX_CS, GFX_SCK, GFX_MOSI, GFX_MISO);
Arduino_GFX *gfx = new Arduino_ST7789(bus, -1, 2, true, 240, 320);

void setup() {
  Serial.begin(115200);
  delay(2000); 
  
  pinMode(GFX_BL, OUTPUT);
  digitalWrite(GFX_BL, HIGH);
  
  gfx->begin();
  
  // Wenn der Code hier ankommt, ist die Initialisierung erfolgreich.
  Serial.println("gfx->begin() wurde ausgefuehrt.");

  gfx->fillScreen(GREEN); // Eindeutiger Test mit einer Farbe
  gfx->setCursor(10, 10);
  gfx->setTextColor(BLACK);
  gfx->setTextSize(3);
  gfx->println("Display");
  gfx->println("FUNKTIONIERT!");
  
  Serial.println("Display-Test beendet. Sie sollten jetzt einen grünen Bildschirm mit schwarzem Text sehen.");
}

void loop() {
  // Bleibt leer.
}

Display and SD Card

#include <Arduino_GFX_Library.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"

// Pin-Konfiguration für Display (SPI)
#define GFX_BL   1
#define GFX_CS   45
#define GFX_SCK  39
#define GFX_MOSI 38
#define GFX_MISO 40
#define GFX_DC   42
Arduino_DataBus *bus = new Arduino_ESP32SPI(GFX_DC, GFX_CS, GFX_SCK, GFX_MOSI, GFX_MISO);
Arduino_GFX *gfx = new Arduino_ST7789(bus, -1, 2, true, 240, 320);

// Pin-Konfiguration für SD-Karte (SPI)
#define SD_CS    41
// SCK, MOSI, MISO werden mit dem Display geteilt

void setup() {
  Serial.begin(115200);
  // Warten Sie einen Moment, damit der Serielle Monitor verbunden werden kann
  delay(2000); 
  Serial.println("\n--- Minimaler SD-Karten & Display Test ---");

  // 1. Manuelle Steuerung der CS-Pins: Beide Geräte deaktivieren (HIGH)
  pinMode(GFX_CS, OUTPUT);
  pinMode(SD_CS, OUTPUT);
  digitalWrite(GFX_CS, HIGH);
  digitalWrite(SD_CS, HIGH);
  Serial.println("Schritt 1: Beide CS-Pins auf HIGH gesetzt.");
  delay(100);

  // 2. SPI-Bus initialisieren
  SPI.begin(GFX_SCK, GFX_MISO, GFX_MOSI, -1);
  Serial.println("Schritt 2: SPI-Bus initialisiert.");

  // 3. Display als ERSTES initialisieren und testen
  pinMode(GFX_BL, OUTPUT);
  digitalWrite(GFX_BL, HIGH);
  gfx->begin();
  gfx->fillScreen(BLACK);
  gfx->setCursor(10, 10);
  gfx->setTextColor(WHITE);
  gfx->setTextSize(2);
  gfx->println("Display OK");
  Serial.println("Schritt 3: Display scheint OK zu sein.");
  
  // 4. SD-Karte als ZWEITES initialisieren
  gfx->println("Initialisiere SD...");
  Serial.println("Schritt 4: Versuche SD.begin()...");
  
  if (!SD.begin(SD_CS)) {
    Serial.println("FEHLER: SD.begin() ist fehlgeschlagen!");
    gfx->setTextColor(RED);
    gfx->println("SD Fehler!");
    // Der Code stoppt hier, damit Sie die Fehlermeldung sehen können
    while(1); 
  }
  
  Serial.println("Schritt 5: SD-Karte erfolgreich initialisiert.");
  gfx->setTextColor(GREEN);
  gfx->println("SD-Karte OK!");
  
  // 5. Kartengröße auslesen und auf dem Display anzeigen
  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("Schritt 6: SD Kartengroesse: %llu MB\n", cardSize);
  
  gfx->setTextColor(WHITE);
  gfx->println("Groesse:");
  gfx->printf("%llu MB", cardSize);
}

void loop() {
  // Bleibt für diesen Test absichtlich leer.
}

But the output is just:

Schritt 1: Beide CS-Pins auf HIGH gesetzt. Schritt 2: SPI-Bus initialisiert.

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.