Problema con TFT y ESP32

buenas tardes a todos, estoy probando un esp32 dev module para meterlo en una cajita y ponerle gifs esta casi todo listo pero el codigo se me resiste, modifique hasta donde llego pero hay una parte que no entiendo(puse los pines correctos para conectarlo a un st7735 128*160) pero la siguiente linea , expone otras conexiones o definiciones :

Adafruit_ST7735 tft = Adafruit_ST7735(tft8bitbus, TFT_D0, TFT_WR, TFT_DC, TFT_CS, TFT_RST, TFT_RD); 
//esta es la parte donde no me entero muy bien D0,wr,DC,CS,RST,RD no lo acabo de entender

en el .ino lo puse asi

//ESP32-WROOM a tft 1.77" ST7735
#define TFT_DC 12 //A0 6 tft
#define TFT_CS 13 //CS 7 tft
#define TFT_MOSI 14 //SDA 4 tft
#define TFT_CLK 27 //CLK 3 tft
#define TFT_RST 15 //res 5 tft

Parece que estas son definiciones que no son para esta biblioteca.
Por favor muestra el código completo

Por cierto, ¿qué tipo de pines son tan extraños - G18, G4?

La pantalla se puede conectar tanto a HARD SPI como a SOFT SPI. ¿Cómo lo necesitas?

HARD SPI:

#define HSPIs             // Дисплей на HSPI )SPI1)
#if defined(HSPIs)         // для ESP32 HSPI
#define TFT_CS        15  // GP13 - CS
#define TFT_RST       16  // GP14 - RESET
#define TFT_DC        17  // GP15 - A0
#define TFT_MISO      12  // GP12 - MISO (MISO, RX)
#define TFT_MOSI      13  // GP11 - SDA  (MOSI, TX)
#define TFT_SCLK      14  // GP10 - SCK
#else                     // для ESP32 VSPI (SPI0)
#define TFT_CS        5   // GP5  - CS
#define TFT_RST       20  // GP20 - RESET
#define TFT_DC        21  // GP21 - A0
#define TFT_MISO      19  // GP19 - MISO (MISO, RX)
#define TFT_MOSI      23  // GP23 - SDA  (MOSI, TX)
#define TFT_SCLK      18  // GP18 - SCK
#endif

OP nessesita "tft8bus", como puedo ver

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); // Via Soft SPI
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); // via hard SPI0
Adafruit_ST7735 tft = Adafruit_ST7735(&SPI1, TFT_CS, TFT_DC, TFT_RST); //via hard SPI1

#ifdef ESP_PLATFORM
#include <M5Core2.h>
#define tft M5.Lcd
#endif

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <AnimatedGIF.h>

// animated digit images
#include "digit_0.h"
#include "digit_1.h"
#include "digit_2.h"
#include "digit_3.h"
#include "digit_4.h"
#include "digit_5.h"
#include "digit_6.h"
#include "digit_7.h"
#include "digit_8.h"
#include "digit_9.h"

// Display settings for ST7735 tft
#define TFT_RST  4 //pin 5 tft
#define TFT_MOSI 23 //pin 4 tft
#define TFT_CLK  18 // pin 3 tft
#define TFT_CS   15 // pin 7 tft
#define TFT_DC   2 // pin 6 tft

#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 160
#ifndef ESP_PLATFORM
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);
#endif
AnimatedGIF gif[4]; // we need 4 independent instances of the class to animate the 4 digits simultaneously
typedef struct my_private_struct
{
  int xoff, yoff; // corner offset
} PRIVATE;

// Draw a line of image directly on the LCD
void GIFDraw(GIFDRAW *pDraw)
{
    uint8_t *s;
    uint16_t *d, *usPalette, usTemp[320];
    int x, y, iWidth;
    PRIVATE *pPriv = (PRIVATE *)pDraw->pUser;
    
    iWidth = pDraw->iWidth;
    if (iWidth + pDraw->iX > DISPLAY_WIDTH)
       iWidth = DISPLAY_WIDTH - pDraw->iX;
    usPalette = pDraw->pPalette;
    y = pPriv->yoff + pDraw->iY + pDraw->y; // current line
    if (y >= DISPLAY_HEIGHT || pDraw->iX >= DISPLAY_WIDTH || iWidth < 1)
       return; 
    s = pDraw->pPixels;
    if (pDraw->ucDisposalMethod == 2) // restore to background color
    {
      for (x=0; x<iWidth; x++)
      {
        if (s[x] == pDraw->ucTransparent)
           s[x] = pDraw->ucBackground;
      }
      pDraw->ucHasTransparency = 0;
    }

    // Apply the new pixels to the main image
    if (pDraw->ucHasTransparency) // if transparency used
    {
      uint8_t *pEnd, c, ucTransparent = pDraw->ucTransparent;
      int x, iCount;
      pEnd = s + iWidth;
      x = 0;
      iCount = 0; // count non-transparent pixels
      while(x < iWidth)
      {
        c = ucTransparent-1;
        d = usTemp;
        while (c != ucTransparent && s < pEnd)
        {
          c = *s++;
          if (c == ucTransparent) // done, stop
          {
            s--; // back up to treat it like transparent
          }
          else // opaque
          {
             *d++ = usPalette[c];
             iCount++;
          }
        } // while looking for opaque pixels
        if (iCount) // any opaque pixels?
        {
          tft.startWrite();
          tft.setAddrWindow(pPriv->xoff + pDraw->iX + x, y, iCount, 1);
#ifdef ESP_PLATFORM
           tft.pushColors(usTemp, iCount, true);
#else
          tft.writePixels(usTemp, iCount, false, false);
#endif
          tft.endWrite();
          x += iCount;
          iCount = 0;
        }
        // no, look for a run of transparent pixels
        c = ucTransparent;
        while (c == ucTransparent && s < pEnd)
        {
          c = *s++;
          if (c == ucTransparent)
             iCount++;
          else
             s--; 
        }
        if (iCount)
        {
          x += iCount; // skip these
          iCount = 0;
        }
      }
    }
    else
    {
      s = pDraw->pPixels;
      // Translate the 8-bit pixels through the RGB565 palette (already byte reversed)
      for (x=0; x<iWidth; x++)
        usTemp[x] = usPalette[*s++];
      tft.startWrite();
      tft.setAddrWindow(pPriv->xoff + pDraw->iX, y, iWidth, 1);
#ifdef ESP_PLATFORM
      tft.pushColors(usTemp, iWidth, true);
#else
      tft.writePixels(usTemp, iWidth, false, false);
#endif
      tft.endWrite();
    }
} /* GIFDraw() */

const uint8_t * digits[10] = {digit_0, digit_1, digit_2, digit_3, digit_4, digit_5, digit_6, digit_7, digit_8, digit_9};
const size_t lengths[10] = {sizeof(digit_0), sizeof(digit_1), sizeof(digit_2), sizeof(digit_3), sizeof(digit_4), sizeof(digit_5),
                            sizeof(digit_6), sizeof(digit_7), sizeof(digit_8), sizeof(digit_9)};
//
// Display 4 animated digits (80 pixels wide each)
// only animate the digits which change from one iteration to the next
//
void ShowDigits(int iValue, int iOldValue)
{
int i, rc, iBusy;
PRIVATE priv;
int jn, jo, t0, t1;
long lTime;

  priv.yoff = 72; // center digits vertically  
  iBusy = 0;
  // mark digits which need to change with a single bit flag
  jn = iValue; jo = iOldValue;
  for (i=3; i>=0; i--) { // compare old and new values
    t0 = jn % 10; t1 = jo % 10;
    if (t0 != t1) {
      iBusy |= (1 << i);
      gif[i].open((uint8_t *)digits[t0], lengths[t0], GIFDraw); // prepare the right digit animated file
    }
    jn /= 10;
    jo /= 10; // next digit
  }
  while (iBusy) {
    // Draw each frame of each changing digit together so that they animate together
    lTime = millis() + 40; // play the frames at a rate of 25fps (40ms per frame)
    for (i=0; i<4; i++) {
       if (iBusy & (1 << i)) {
         // Advance this animation one frame
         priv.xoff = 80 * i; // each digit is 80 pixels wide
         rc = gif[i].playFrame(false, NULL, (void *)&priv); // draw it and return immediately
         if (!rc) { // animation has ended
            iBusy &= ~(1<<i); // clear the bit indicating this digit is busy
            gif[i].close();
         }
       }
    } // for each digit
    delay(25);
//    while ((millis() - lTime) < 0)
//    {
//      delay(1);
//    };
  } // while digits still changing
} /* ShowDigits() */

void setup() {
  Serial.begin(9600);
//  while (!Serial);

#ifdef ESP_PLATFORM
  M5.begin(true, true, true, true);
//  if (!SD.begin()) {
//    M5.Lcd.println("Card failed, or not present");
//    while (1);
//  }
#else
  // put your setup code here, to run once:
  //pinMode(TFT_BACKLIGHT, OUTPUT);
  //digitalWrite(TFT_BACKLIGHT, HIGH);
  //pinMode(TFT_RESET, OUTPUT);
  //digitalWrite(TFT_RESET, HIGH);
  //delay(10);
  //digitalWrite(TFT_RESET, LOW);
  //delay(10);
  //digitalWrite(TFT_RESET, HIGH);
  //delay(10);
  tft.begin();
  tft.setRotation(1);
 #endif
  tft.fillScreen(ST7735_WHITE);
//  tft.setTextColor(ST7735_YELLOW);
//  tft.setTextSize(2);
  for (int i=0; i<4; i++)
     gif[i].begin(GIF_PALETTE_RGB565_LE);
} /* setup() */

void loop() {
int i, iOld;
  iOld = 9999; // force every digit to be drawn the first time
  for (i=0; i<9999; i++) {
    ShowDigits(i, iOld);
    iOld = i;
    delay(250);
  }
} /* loop() */

pues nada no doy sacado imagen en el tft que extraño

Pegale una mirada, especialmente al tema títulos y códigos.

Saludos

Lo que te digo es que tenés que corregir el título del tema y publicar correctamente el código antes que recibas la advertencia del moderador.

Saludos

No pongas "ayuda", algo como "Problema con TFT y ESP32", por ej.,, es más adecuado.
Y múevelo a la sección Microcontroladores que es la que corresponde porque no es para una placa Arduino.

Luego edita los códigos y ponlos como indica en las Normas.
Es fácil, seleccionas el código y pulsas en "</>" y listo.

Moderador:
Por favor, lee las Normas del foro y edita tu código/error usando etiquetas de código.
Ve a edición, luego selecciona todo el código que has publicado, lo cortas y click en </>


Edita post #1 y #6 antes de seguir respondiendo.

asi vale surbyte ?

Moderador
Tuve que editar tu hilo inicial porque no lucía correctamente, pero al menos ya sabes como postear los códigos.
Avancemos con la solución de tu problema.

1 Like

mil gracias :smiley: :smiley: a ver si ahora consigo alguna solucion, he estado probando un monton de sketchs de esp32 y tft y configurando el user_setup.h arregle el tema de los pins, y van algunos ejemplos pero este del gif no hay manera, podrias echarme un cablecillo surbyte ? :smiley:

La solución no es probar por probar, sino primero entender que tienes y luego ver que dice la documantación de la librería.
Estas probando cosas sin tener el mas mínimo criterio.
Debes antes que nada decirnos donde compraste tu TFT, coloca un link.
Lo identificamos y vemos como se debe configurar pero probar por probar no sirve.

bien dicho surbyte, pero no estoy probando por probar, despues de leerme toda la documentacion, ver 30 videos distintos de como hacerlos, encontrar uno que si sirve, descargar el zip con todo y estar leyendo toooodos los ejemplos, raro me parece.
este es el tft/lcd https://www.amazon.es/dp/B078JBBPXK?psc=1&ref=ppx_yo2ov_dt_b_product_details
fijate que despues de editar el user setup del TFT_eSPI_ESP32labs si funcionan sus ejemplos, pero no el del gif, extraño eh ?por lo que he leido de david prentice y @bodmer, asi que creo que si que me empape bien de documentacion antes de osar poner el post.
la placa es una esp32 WROOM-32 de AZ delivery

Bueno si ya lograste que algunos ejemplos funcionen lo demás es cuestión de seguir peléandolo.

ya en eso estoy pero el gif en esp32 no quiere ir es una pena, me tocara hacer frame a frame :frowning:

Perdonad por subir este post con casi 20 días pero creo que tocará hacerlo frame a frame...
Te paso info en italiano pero creo que se entiende bien:
https://www.fattelodasolo.it/2021/10/19/esp32-riprodurre-gif-animate-su-lyligo-ttgo/

mil gracias danx3 pero si no tengo el arduino ide 1.18.16 no va y aun asi tampoco no se porque(que conste en acta que he revisado mil y un posts en otras paginas, youtube y san google y nada no hay manera)

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