TRYING a simple program to test the new board

goodmorning to all. I'm really a newbie of esp32. I bought an esp32 wroom with touchscreen. i tryied a simple program to show a rainbow in the screen; it compile well but then the display stay blank. i'm doing something bad? thank you so much.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post error messages in code tags as it makes it easier to scroll through them and copy them for examination

1 Like

brisingr19931, once you have absorbed the above and edited your post, please could you provide details of the display that you are using (make, model, connections) and diagram of how you have wired everything up to the ESP32.

1 Like

When i go home i will post the correction, thank you so much!

esp32's do not have screens. It is probably a LilyGo.
Your upload looks normal. Did you click the reset switch? Double-check the baud rate on the monitor page.
I see possible errors in the code shown so far. Is that a sample? From where?

It's all integrated. It's this in the photo below

https://forum.arduino.cc/t/3-5-inch-lcd-touch-display-with-esp32/1168749/7

I found the example here, but reading well now, i think that the problem is that i don't update the user_setup.

1 Like
#include <TFT_eSPI.h>  // Graphics and font library for ST7735 driver chip
#include <SPI.h>


TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h

unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;

void setup(void) {
  tft.init();
  //pinMode(27, OUTPUT);//打钟
  //digitalWrite(27,LOW);
  tft.setRotation(1);
  //tft.fillScreen(TFT_BLACK);
  targetTime = millis() + 100;
}

void loop() {
  tft.fillScreen(TFT_RED);
  delay(1000);
  tft.fillScreen(TFT_GREEN);
  delay(1000);
  tft.fillScreen(TFT_BLUE);
  delay(1000);
  tft.fillScreen(TFT_BLACK);
  delay(1000);
  tft.fillScreen(TFT_WHITE);
  delay(1000);
  tft.fillScreen(random(0x10000));
  delay(1000);

  // LCD_Clear(0x0000);
  //delay(2000);
  // LCD_Clear(0xfffc);
  //delay(2000);
  if (targetTime < millis()) {
    targetTime = millis() + 10000;

    // Colour changing state machine
    for (int i = 0; i < 480; i++) {
      tft.drawFastVLine(i, 0, tft.height(), colour);
      switch (state) {
        case 0:
          green += 2;
          if (green == 64) {
            green = 63;
            state = 1;
          }
          break;
        case 1:
          red--;
          if (red == 255) {
            red = 0;
            state = 2;
          }
          break;
        case 2:
          blue++;
          if (blue == 32) {
            blue = 31;
            state = 3;
          }
          break;
        case 3:
          green -= 2;
          if (green == 255) {
            green = 0;
            state = 4;
          }
          break;
        case 4:
          red++;
          if (red == 32) {
            red = 31;
            state = 5;
          }
          break;
        case 5:
          blue--;
          if (blue == 255) {
            blue = 0;
            state = 0;
          }
          break;
      }
      colour = red << 11 | green << 5 | blue;
    }

    // The standard ADAFruit font still works as before
    tft.setTextColor(TFT_BLACK);
    tft.setCursor(12, 5);
    tft.print("Original ADAfruit font!");

    // The new larger fonts do not use the .setCursor call, coords are embedded
    tft.setTextColor(TFT_BLACK, TFT_BLACK);  // Do not plot the background colour

    // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
    tft.drawCentreString("Font size 2", 80, 14, 2);  // Draw text centre at position 80, 12 using font 2

    //tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2

    tft.drawCentreString("Font size 4", 80, 30, 4);  // Draw text centre at position 80, 24 using font 4

    tft.drawCentreString("12.34", 80, 54, 6);  // Draw text centre at position 80, 24 using font 6

    tft.drawCentreString("12.34 is in font size 6", 80, 92, 2);  // Draw text centre at position 80, 90 using font 2

    // Note the x position is the top left of the font!

    // draw a floating point number
    float pi = 3.14159;                                      // Value to print
    int precision = 3;                                       // Number of digits after decimal point
    int xpos = 50;                                           // x position
    int ypos = 110;                                          // y position
    int font = 2;                                            // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : a p m
    xpos += tft.drawFloat(pi, precision, xpos, ypos, font);  // Draw rounded number and return new xpos delta for next print position
    tft.drawString(" is pi", xpos, ypos, font);              // Continue printing from new x position
    delay(6000);
  }

That sketch compiles and runs for me on the CYD

Have you updated your user_setup file and got it working ?

yes, i found this on the internet that seems good for me because in the description is write " CHIP: ST7796" so i found this

//                            USER DEFINED SETTINGS
//   Set driver type, fonts to be loaded, pins used and SPI control method etc.
//
//   See the User_Setup_Select.h file if you wish to be able to define multiple
//   setups and then easily select which setup file is used by the compiler.
//
//   If this file is edited correctly then all the library example sketches should
//   run without the need to make any more changes for a particular hardware setup!

#define USER_SETUP_ID 27

// ##################################################################################
//
// Section 0. Call up the right driver file and any options for it
//
// ##################################################################################

// Display type -  only define if RPi display
#define RPI_DISPLAY_TYPE

// Only define one driver
#define ST7796_DRIVER

// ##################################################################################
//
// Section 1. Define the pins that are used to interface with the display here
//
// ##################################################################################

// >>>>> EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP32 SETUP   <<<<<

// The ESP32 hardware SPI can be mapped to any pins, these are the recommended default

#define TFT_MISO 0
#define TFT_MOSI 6
#define TFT_SCLK 7
#define TFT_CS 5
#define TFT_DC 4
#define TFT_RST 15#define TOUCH_CS 22     // Chip select pin (T_CS) of touch screen

// ##################################################################################
//
// Section 2. Not used for ESP32
//
// ##################################################################################


// ##################################################################################
//
// Section 3. Define the fonts that are to be used here
//
// ##################################################################################

// Comment out the #defines below with // to stop that font being loaded
// The ESP8366 and ESP32 have plenty of memory so commenting out fonts is not
// normally necessary. If all fonts are loaded the extra FLASH space required is
// about 17Kbytes. To save FLASH space only enable the fonts you need!

#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT

// ##################################################################################
//
// Section 4. Not used
//
// ##################################################################################


// ##################################################################################
//
// Section 5. Other options
//
// ##################################################################################

// Define the SPI clock frequency, this affects the graphics rendering speed. Too
// fast and the TFT driver will not keep up and display corruption appears.
// With an RPi ST7796 MH4.0 display 80MHz is OK for ESP32, 40MHz maximum for ESP8266

// #define SPI_FREQUENCY  20000000
// #define SPI_FREQUENCY  40000000
   #define SPI_FREQUENCY  80000000

// The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default.
// If the VSPI port is in use and pins are not accessible (e.g. TTGO T-Beam)
// then uncomment the following line:
//#define USE_HSPI_PORT

// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
   #define SPI_TOUCH_FREQUENCY  2500000

I am glad that you got it working

If you have not already found it then this page may be of interest GitHub - witnessmenow/ESP32-Cheap-Yellow-Display: Building a community around a cheap ESP32 Display with a touch screen

Nono, i tryied but not working!

there appear to be a number of variations of the CYD using different display drivers
e.g. the photo of the rear of the your CYD looks nothing like the CYD I have
can you give a link to the site where you purchased the CYD?

https://a.aliexpress.com/_EQYK5po

i really really appreciate if u can help me...really :slight_smile:

Hi, @brisingr19931
Have you been to the site mentioned in the AliExpress link?

And then downloaded the zip?

Tom.... :smiley: :+1: :coffee: :australia:

many of the web sites for CYDs have plenty of photos but lack technical information, e.g. the display driver chip used
which is critical when setting up the TFT_eSPI configuration

try following the suggestion by @TomGeorge to download the associated zip file - it may contain more technical information and even sample code

I contact also the service center, they said to me to use a specific user_setup and if it don't work, another to try. The serial output work perfectly but the screen stay black. Do you have some esp32 to suggest me to buy? And a touchscreen about 3"? Something that you know it Works...

I have used the HiLetgo 240X320 Resolution 2.8" SPI TFT LCD Display Touch Panel on an ESP32 NodeMCU development board with TFT_eSPI library using touch and SD card
if you do a web search (e.g. on EBAY) for " 240X320 Resolution 2.8" SPI TFT LCD" you will get plenty of links
also worth looking at are CYD (try a web search) however the external IO is VERY limited to a few GPIO pins and documentation tends to be very poor
if you wish to use TFT_eSPI use the original ESP32 not the ESP32S3, ESP32C3, etc which give problems with TFT_eSPI on the newer version of the ESP32 core

there are multiple User_Setup files for various combinations of host microcontriller and display drive
what you need is the display driver type and the GPIO pin connections for MOSI, MISO, SCK, CS, DC, etc - without them you cannot configure the TFT_eSPI setup
if not in user/technical manual look at the circuit schematic (if available)

You may be able to get help here BLough

Brian Lough (BLough) has done a lot of work to bring together information on the CYD and his Discord channel has a lot of knowledge people on it

1 Like