Hola Buenos días, soy un nuevo usuario de microcontroladores, en concreto el ESP32.
Estoy empezando con estos dispositivos y me llama lo relacionado con la lectura desde SD y pantallas, así que quería empezar montando un visualizador de imágenes JPG.
Por ahora estoy haciendo uso de los ejemplos de las librerías y tutoriales de Youtube, pero he llegado a un punto en el que necesito pedir ayuda.
Primero me gustaría argumentar mi proyecto:
Estoy intentando que mediante una pantalla ILI9488 con SD, el ESP32 codifique JPG mediante la librería TJpg_Decoder.
Para ello he tirado de un ejemplo denominado SD_Jpg, que se encuentra dentro de la librería, lo he modificado para que me de información de la SD y para que lea los archivos de la misma y los pase haciendo loop cada 2s.
El problema es que si pruebo solo con el ejemplo sin hacer cambios, me muestra una imagen predeterminada, pero mi objetivo es que me de algo mas de información por el monitor serie y ademas que muestre todas las imagenes JPg que tenga en la SD.
Pero al hacer los cambios que yo necesito el Monitor serie me dice que la imagen no funciona:
12:12:26.582 -> ����SD Card Type: SDHC
12:12:26.755 -> SD Card Size: 7680MB
12:12:26.755 -> initialisation done.
12:12:27.668 -> Jpeg file not found
12:12:27.668 -> 770 ms
12:12:29.987 -> Jpeg file not found
12:12:29.987 -> 3383 ms
12:12:32.274 -> Jpeg file not found
12:12:32.274 -> 3078 ms
Como se ve en el LOG, la SD la inicializa bien, encuentra las imágenes y me da los ms, pero no muestra nada en pantalla.
Les dejo el código (siento el desastre soy bastante novato) por si alguien puede orientarme donde puede estar el problema, por que necesito entender que esta sucediendo o que estoy haciendo mal, para poder solucionarlo:
// Example for library:
// https://github.com/Bodmer/TJpg_Decoder
// Include the jpeg decoder library
#include <TJpg_Decoder.h>
#include <SD.h>
#define FS_NO_GLOBALS
#include <FS.h>
#ifdef ESP32
#include "SPIFFS.h" // ESP32 only
#endif
#define SD_CS 5
// Include the TFT library https://github.com/Bodmer/TFT_eSPI
#include "SPI.h"
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
// This next function will be called during decoding of the jpeg file to
// render each block to the TFT. If you use a different TFT library
// you will need to adapt this function to suit.
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
// Stop further decoding as image is running off bottom of screen
if ( y >= tft.height() ) return 0;
// This function will clip the image block rendering automatically at the TFT boundaries
tft.pushImage(x, y, w, h, bitmap);
// This might work instead if you adapt the sketch to use the Adafruit_GFX library
// tft.drawRGBBitmap(x, y, bitmap, w, h);
// Return 1 to decode next block
return 1;
}
void setup()
{
Serial.begin(115200);
Serial.println("\n\n Testing TJpg_Decoder library");
// Initialise SD before TFT
if (!SD.begin(SD_CS)) {
Serial.println(F("SD.begin failed!"));
while (1) delay(0);
}
Serial.println("\r\nInitialisation done.");
// Initialise the TFT
tft.begin();
tft.setTextColor(0xFFFF, 0x0000);
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true); // We need to swap the colour bytes (endianess)
// The jpeg image can be scaled by a factor of 1, 2, 4, or 8
TJpgDec.setJpgScale(1);
// The decoder must be given the exact name of the rendering function above
TJpgDec.setCallback(tft_output);
if (!SD.begin()) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("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");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
Serial.println("initialisation done.");
}
void loop()
{
tft.fillScreen(TFT_RED);
// Time recorded for test purposes
uint32_t t = millis();
File file;
File root = SD.open("/");
if(!root){
Serial.println("Failed to open root directory");
return;
}
file = root.openNextFile(); // Opens next file in root
while(file)
{
if(!file.isDirectory())
{
// Get the width and height in pixels of the jpeg if you wish
uint16_t w = 0, h = 0;
// TJpgDec.getSdJpgSize(file.name(),&w, &h, "/panda.jpg");
// Serial.print("Width = "); Serial.print(w); Serial.print(", height = "); Serial.println(h);
// Draw the image, top left at 0,0
TJpgDec.drawSdJpg(0, 0, file.name());
// How much time did rendering take
t = millis() - t;
Serial.print(t); Serial.println(" ms");
// Wait before drawing again
delay(2000);
}
file = root.openNextFile(); // Opens next file in root
}
root.close();
}
Les agradezco enormemente su ayuda.
Un saludo.