Adafruit 1.44" Color TFT mit Micro SD Sockel

hallo , ich bin neu hier und habe schon einige Sachen in Arduino realisiert.
Ich möchte für meine Modellbahn ein Werbedisplay integrieren, welches selbstständig Bilder , die ich eingetragen habe anzeigt.
Nun stolpere ich über oben genanntes Display, deren Sketch ich noch nicht verstehe.
Ich habe den Sketch von der Arduino-Seite geladen. Ich benutze den Uno und habe das Display angeschlossen, Bilder von der SD karte kann ich laden und ansehen.
Jetzt das Problem: Die Bilder kommen ohne Pause nach einander , nach dem letzten Bild ist das Display leer. das heißt, ich muss irgendwo ein Loop Funktion einbauen und weiß nicht wie und wo, Ich würde mich sehr freuen, wenn mir jemand dabei hilft.
Hier mein Sketch:



// Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino.
// Demonstrates loading images from SD card or flash memory to the screen,
// to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card:
// rgbwheel.bmp, miniwoof.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen
// (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno,
// MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.


#include <Adafruit_GFX.h>         // Core graphics library
#include <Adafruit_ST7735.h>      // Hardware-specific library
#include <SdFat.h>                // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h>    // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions

// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD

// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.

#define SD_CS    4 // SD card select pin
#define TFT_CS  10 // TFT select pin
#define TFT_DC   8 // TFT display/command pin
#define TFT_RST  9 // Or set to -1 and connect to Arduino RESET pin

#if defined(USE_SD_CARD)
  SdFat                SD;         // SD card filesystem
  Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
#else
  // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive)
  #if defined(__SAMD51__) || defined(NRF52840_XXAA)
    Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS,
      PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
  #else
    #if (SPI_INTERFACES_COUNT == 1)
      Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
    #else
      Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
    #endif
  #endif
  Adafruit_SPIFlash    flash(&flashTransport);
  FatFileSystem        filesys;
  Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys
#endif

Adafruit_ST7735      tft    = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image       img;        // An image loaded into RAM
int32_t              width  = 0, // BMP image dimensions
                     height = 0;

void setup(void) {

  ImageReturnCode stat; // Status from image-reading functions

  Serial.begin(9600);
#if !defined(ESP32)
  while(!Serial);       // Wait for Serial Monitor before continuing
#endif

  tft.initR(INITR_144GREENTAB); // Initialize screen

  // The Adafruit_ImageReader constructor call (above, before setup())
  // accepts an uninitialized SdFat or FatFileSystem object. This MUST
  // BE INITIALIZED before using any of the image reader functions!
  Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
  // SD card is pretty straightforward, a single call...
  if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
    Serial.println(F("SD begin() failed"));
    for(;;); // Fatal error, do not continue
  }
#else
  // SPI or QSPI flash requires two steps, one to access the bare flash
  // memory itself, then the second to access the filesystem within...
  if(!flash.begin()) {
    Serial.println(F("flash begin() failed"));
    for(;;);
  }
  if(!filesys.begin(&flash)) {
    Serial.println(F("filesys begin() failed"));
    for(;;);
  }
#endif
  Serial.println(F("OK!"));

  // Fill screen blue. Not a required step, this just shows that we're
  // successfully communicating with the screen.
  tft.fillScreen(ST7735_BLUE);



  // Load full-screen BMP file 'rgbwheel.bmp' at position (0,0) (top left).
  // Notice the 'reader' object performs this, with 'tft' as an argument.
  Serial.print(F("Loading rgbwheel.bmp to screen..."));
  stat = reader.drawBMP("/lily128.bmp", tft, 0, 0);
  stat = reader.drawBMP("/italy128.bmp", tft, 0, 0);
  stat = reader.drawBMP("/italyi128.bmp", tft, 0, 0);
  stat = reader.drawBMP("/Blume128.bmp", tft, 0, 0);
  stat = reader.drawBMP("/seerose.bmp", tft, 0, 0);
  reader.printStatus(stat);   // How'd we do?

  // Query the dimensions of image 'miniwoof.bmp' WITHOUT loading to screen:
  Serial.print(F("Querying miniwoof.bmp image size..."));
  stat = reader.bmpDimensions("/miniwoof.bmp", &width, &height);
  reader.printStatus(stat);   // How'd we do?
  if(stat == IMAGE_SUCCESS) { // If it worked, print image size...
    Serial.print(F("Image dimensions: "));
    Serial.print(width);
    Serial.write('x');
    Serial.println(height);
  }

  // Load small BMP 'wales.bmp' into a GFX canvas in RAM. This should fail
  // gracefully on Arduino Uno and other small devices, meaning the image
  // will not load, but this won't make the program stop or crash, it just
  // continues on without it. Should work on Arduino Mega, Zero, etc.
  Serial.print(F("Loading wales.bmp to canvas..."));
  stat = reader.loadBMP("/wales.bmp", img);
  reader.printStatus(stat); // How'd we do?

  delay(3000); // Pause 3 seconds before moving on to loop()
}

void loop() {
  for(int r=0; r<4; r++) { // For each of 4 rotations...
    tft.setRotation(r);    // Set rotation
    tft.fillScreen(0);     // and clear screen

    // Load 4 copies of the 'miniwoof.bmp' image to the screen, some
    // partially off screen edges to demonstrate clipping. Globals
    // 'width' and 'height' were set by bmpDimensions() call in setup().
    for(int i=0; i<4; i++) {
      reader.drawBMP("/miniwoof.bmp", tft,
        (tft.width()  * i / 3) - (width  / 2),
        (tft.height() * i / 3) - (height / 2));
    }

    delay(3000); // Pause 3 sec.

    // Draw 50 Welsh dragon flags in random positions. This has no effect
    // on memory-constrained boards like the Arduino Uno, where the image
    // failed to load due to insufficient RAM, but it's NOT fatal.
    for(int i=0; i<50; i++) {
      // Rather than reader.drawBMP() (which works from SD card),
      // a different function is used for RAM-resident images:
      img.draw(tft,                                    // Pass in tft object
        (int16_t)random(-img.width() , tft.width()) ,  // Horiz pos.
        (int16_t)random(-img.height(), tft.height())); // Vert pos
      // Reiterating a prior point: img.draw() does nothing and returns
      // if the image failed to load. It's unfortunate but not disastrous.
    }

    delay(5000); // Pause 5 sec.
}

  
}

Kannst Du ein bißchen programmieren?
Grüße Uwe

Danke für die Antwort.
Ein bisschen ja, eher weniger, ich dachte eher an Hilfe.
ich bin nun 71 Jahre alt und dann fällt mir das etwas schwer.
Vielleicht kann man durch leichtes Einfügen der Loop Funktion machen.
Grüße Günter

Das pausieren der Bilder habe ich gelöst,
ich habe zwischen den Bildern " delay(3000);" hinein kopiert,
jetzt muß ich das Problem der Wiederholung lösen , Loop !
hast du mir einen Tipp ?

Siehst du das überhaupt? Oder nur 4 Bilder (Teile von miniwoof.bmp) ?
Eigentlich ist die permanente Wiederholung schon drin, denn am Ende von loop() wird loop() wieder neu gestartet. Das baut dir die Arduino IDE automatisch.

Danke für die Antwort,
Alle Bilder werden angezeigt, aber Loop funktioniert nicht .

Mit "alle" meinst du vermutlich die aus setup().

Siehst du auch die 4 Teile von miniwoof.bmp ?
Danach die Flagge wales.bmp ? An 50 random Positionen ? Ist das Bild anzeigen so langsam, dass Mitzählen geht?

Das erste Mittel, um Licht ins Dunkel zu bringen, sind zusätzliche Serial Testausgaben, die du auch ansehen, und bei verbleibenden Unklarheiten, hier zeigen musst.

Gehen wir erstmal davon aus, dass nach erfolgreichem Ende von setup() loop() drankommt, aber auch das kannst du mit Serial überprüfen.

Du hast Dir ein Beispiel rausgesucht, wo viele Zeilen für Dich nicht zutreffen, das kann verwirren. Daher habe ich aufgeräumt und die Anzeige nach loop() verschoben.

Getestet mit ESP32 (da hängt mein Display gerade dran), ungetestet für UNO:

#include <Adafruit_GFX.h>         // Core graphics library
#include <Adafruit_ST7735.h>      // Hardware-specific library
#include <SdFat.h>                // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h>    // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions

// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.

#define SD_CS    4 // SD card select pin
#define TFT_CS  10 // TFT select pin
#define TFT_DC   8 // TFT display/command pin
#define TFT_RST  9 // Or set to -1 and connect to Arduino RESET pin

SdFat                SD;         // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys

Adafruit_ST7735      tft    = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image       img;        // An image loaded into RAM
ImageReturnCode stat;            // Status from image-reading functions

void setup(void) {
  Serial.begin(9600);
  tft.initR(INITR_BLACKTAB); // Initialize screen
  Serial.print(F("Initializing filesystem..."));
  if (!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
    Serial.println(F("SD begin() failed"));
    for (;;); // Fatal error, do not continue
  }
  Serial.println(F("OK!"));
}

void loop() {
  uint32_t jetzt = millis();
  static uint32_t vorhin = jetzt;
  const uint32_t intervall = 2000;
  static byte schritt = 0;

  if (jetzt - vorhin >= intervall)
  {
    vorhin = jetzt;
    switch (schritt)
    {
      case 0:
        Serial.println(F("Loading lily128.bmp to screen..."));
        stat = reader.drawBMP("/lily128.bmp", tft, 0, 0);
        schritt++;
        break;
      case 1:
        Serial.println(F("Loading italy128.bmp to screen..."));
        stat = reader.drawBMP("/italy128.bmp", tft, 0, 0);
        schritt++;
        break;
      case 2:
        Serial.println(F("Loading italyi128.bmp to screen..."));
        stat = reader.drawBMP("/italyi128.bmp", tft, 0, 0);
        schritt++;
        break;
      case 3:
        Serial.println(F("Loading Blume128.bmp to screen..."));
        stat = reader.drawBMP("/Blume128.bmp", tft, 0, 0);
        schritt++;
        break;
      default:
        Serial.println(F("Loading seerose.bmp to screen..."));
        stat = reader.drawBMP("/seerose.bmp", tft, 0, 0);
        schritt = 0;
        break;
    }
  }
}

Was siehst Du?

danke für Deine Mühe.
Ich habe das mal so auf meinen Uno übertragen. Es werden aber nur 2 Bilder angezeigt,
z.B. die Lilie und Seerose und schnell hintereinander mit 5 Sekunden Pause, wird versetzt angezeigt,
wahrscheinlich legt es daran, dass es für ESP umgeschrieben wurde.
Ich werde es mal mit dem ESP32 testen, muss aber erst rausfinden, wie ich das Display anschließe

// Getestet mit ESP32
#include <Adafruit_GFX.h>         // Core graphics library
#include <Adafruit_ST7735.h>      // Hardware-specific library
#include <SdFat.h>                // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h>    // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions

// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.

#define SD_CS    5 //4 // SD card select pin
#define TFT_CS  17 //10 // TFT select pin
#define TFT_DC   2 //8 // TFT display/command pin
#define TFT_RST 14 // 9 // Or set to -1 and connect to Arduino RESET pin

SdFat                SD;         // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys

Adafruit_ST7735      tft    = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image       img;        // An image loaded into RAM
ImageReturnCode stat;            // Status from image-reading functions

void setup(void) {
  //Serial.begin(9600);
  Serial.begin(115200);
  delay(1000);

  tft.initR(INITR_BLACKTAB); // Initialize screen

  Serial.print(F("Initializing filesystem..."));
  if (!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
    Serial.println(F("SD begin() failed"));
    for (;;); // Fatal error, do not continue
  }
  Serial.println(F("OK!"));
}

void loop() {
  uint32_t jetzt = millis();
  static uint32_t vorhin = jetzt;
  const uint32_t intervall = 2000;
  static byte schritt = 0;

  if (jetzt - vorhin >= intervall)
  {
    vorhin = jetzt;
    switch (schritt)
    {
      case 0:
        Serial.println(F("Loading lily128.bmp to screen..."));
        stat = reader.drawBMP("/lily128.bmp", tft, 0, 0);
        schritt++;
        break;
      case 1:
        Serial.println(F("Loading italy128.bmp to screen..."));
        stat = reader.drawBMP("/italy128.bmp", tft, 0, 0);
        schritt++;
        break;
      case 2:
        Serial.println(F("Loading italyi128.bmp to screen..."));
        stat = reader.drawBMP("/italyi128.bmp", tft, 0, 0);
        schritt++;
        break;
      case 3:
        Serial.println(F("Loading Blume128.bmp to screen..."));
        stat = reader.drawBMP("/Blume128.bmp", tft, 0, 0);
        schritt++;
        break;
      default:
        Serial.println(F("Loading seerose.bmp to screen..."));
        stat = reader.drawBMP("/seerose.bmp", tft, 0, 0);
        schritt = 0;
        break;
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.