Bodmer / TFT_eSPI

Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips
Other
3.44k stars 1.01k forks source link

No output on ESP32-S2 MINI + GC9A01 #3290

Closed DragarX closed 1 month ago

DragarX commented 1 month ago

So I'm having issues getting anything to show up on this display. When using HSPI via lovyan the screen works fine, but using the same settings on TFT_eSPI the screen shows nothing.

This my my header.

// Setup for ESP32 S2 with GC9A01 display
#define USER_SETUP_ID 9090
#define GC9A01_DRIVER

#define ESP32_S2

#define TFT_WIDTH  240
#define TFT_HEIGHT 240

#define TFT_MISO -1
#define TFT_MOSI 35
#define TFT_SCLK 36
#define TFT_CS   34
#define TFT_DC   7
#define TFT_RST  9

#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF

#define SMOOTH_FONT

#define USE_HSPI_PORT

#define SPI_READ_FREQUENCY  20000000
#define SPI_FREQUENCY  40000000

and my test source.

// https://github.com/OpenHDZ/Arduino-experimentation
// Adapted for TFT_eSPI library

// Note: a high number of floating point calculations are needed
// for each pixel so rendering will be quite slow.
// For best performance use a Teensy 4.x (600MHz CPU clock).
#include <../TFT_eSPI_Setups/S2ROUND.h>
#include <TFT_eSPI.h>       // Hardware-specific library

TFT_eSPI tft = TFT_eSPI();  // Invoke custom library

const uint16_t MAX_ITERATION = 300; // Nombre de couleurs

#define SCREEN_WIDTH  tft.width()  // 
#define SCREEN_HEIGHT tft.height() // Taille de l'écran

static float zoom = 0.5;

void draw_Julia(float c_r, float c_i, float zoom);

/* Fonction setup */
void setup() {
/* Initialise l'écran LCD */
  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
  tft.setFreeFont(&FreeMono9pt7b);
  Serial.begin(115200);
}

/* Fonction loop() */
void loop() {
  /* Dessine la fractale */
  Serial.println("Drawing Julia set");
  draw_Julia(-0.8,+0.156,zoom);
  tft.fillRect(0, 0, 150, 20, TFT_BLACK);
  tft.setCursor(0,15);
  tft.setTextColor(TFT_WHITE);
  tft.print(" Zoom = ");
  tft.println(zoom);
  delay(2000);
  zoom *= 1.5;
  if (zoom > 100) zoom = 0.5;
}

/* 
  Dessine une fractale de Julia
 */

void draw_Julia(float c_r, float c_i, float zoom) {

  tft.setCursor(0,0);
  float new_r = 0.0, new_i = 0.0, old_r = 0.0, old_i = 0.0;

  /* Pour chaque pixel en X */

  for(int16_t x = SCREEN_WIDTH/2 - 1; x >= 0; x--) { // Rely on inverted symmetry
    /* Pour chaque pixel en Y */
    for(uint16_t y = 0; y < SCREEN_HEIGHT; y++) {      
      old_r = 1.5 * (x - SCREEN_WIDTH / 2) / (0.5 * zoom * SCREEN_WIDTH);
      old_i = (y - SCREEN_HEIGHT / 2) / (0.5 * zoom * SCREEN_HEIGHT);
      uint16_t i = 0;

      while ((old_r * old_r + old_i * old_i) < 4.0 && i < MAX_ITERATION) {
        new_r = old_r * old_r - old_i * old_i ;
        new_i = 2.0 * old_r * old_i;

        old_r = new_r+c_r;
        old_i = new_i+c_i;

        i++;
      }
      /* Affiche le pixel */
      if (i < 100){
        tft.drawPixel(x,y,tft.color565(255,255,map(i,0,100,255,0)));
        tft.drawPixel(SCREEN_WIDTH - x - 1,SCREEN_HEIGHT - y - 1,tft.color565(255,255,map(i,0,100,255,0)));
      }if(i<200){
        tft.drawPixel(x,y,tft.color565(255,map(i,100,200,255,0),0));
        tft.drawPixel(SCREEN_WIDTH - x - 1,SCREEN_HEIGHT - y - 1,tft.color565(255,map(i,100,200,255,0),0));
      }else{
        tft.drawPixel(x,y,tft.color565(map(i,200,300,255,0),0,0));
        tft.drawPixel(SCREEN_WIDTH - x - 1,SCREEN_HEIGHT - y - 1,tft.color565(map(i,200,300,255,0),0,0));
      }
    }
  }
}

Any help would be awesome.

DragarX commented 1 month ago

Looks like I didn't include the header properly, but now that the display is initializing, its just a bunch of random vertical lines with the previous image from lovyan slightly still visible.

DragarX commented 1 month ago

This is my output from Read_User_Setup

TFT_eSPI ver = 2.5.43
Processor    = ESP32
Frequency    = 240MHz
Transactions = Yes
Interface    = SPI
Display driver = 9A01
Display width  = 240
Display height = 240

MOSI    = GPIO 35
SCK     = GPIO 36
TFT_CS   = GPIO 34
TFT_DC   = GPIO 7
TFT_RST  = GPIO 9

Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled

Display SPI frequency = 40.00
DragarX commented 1 month ago

Ok got it working. This was the setup I ended up using in replacement of User_Setup.h

#define USER_SETUP_INFO "User_Setup"

#define ESP32_S2

#define GC9A01_DRIVER

#define TFT_SDA_READ      
#define TFT_WIDTH  240 
#define TFT_HEIGHT 240 
#define TFT_INVERSION_ON

#define TFT_MISO 37
#define TFT_MOSI 35
#define TFT_SCLK 36
#define TFT_CS   34
#define TFT_DC   7
#define TFT_RST  9

#define LOAD_GLCD
#define LOAD_FONT2  
#define LOAD_FONT4  
#define LOAD_FONT6  
#define LOAD_FONT7  
#define LOAD_FONT8  
#define LOAD_GFXFF  
#define SMOOTH_FONT

#define SPI_FREQUENCY  40000000
#define SPI_READ_FREQUENCY  20000000
#define SPI_TOUCH_FREQUENCY  2500000

#define USE_HSPI_PORT