Displaying an image on a screen using an ESP32

Hello, I am currently working on a small project for one of my courses at university. I want to display an image on a RB-TFT1.8 screen using an ESP32 TTG0 Lily-Go T-display and a gyroscope. When I shake the gyroscope, an image stored in the screens SD card is chosen at random to be displayed.
However, there are not many tutorials and exemples to take inspiration from, since most similar projects use an arduino uno. Another difficulty I have encountered is activating the SD card that I have inserted on my screen with my ESP. I have found a few codes using arduino uno and similar screen to mine to take inspiration from, but my attempt at adapting them to ESP 32 were a failure and usually when I upload the code to my eSP32 nothing happens. I think that either the codes are faulty, or I might have done something wrong in the wirering. For now, I prefer starting small, so I am simply trying to display text on my screen, without using the SD card or the gyroscope.

Here is the code I am currently working on:

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



#define TFT_CS    13
#define TFT_RST   2
#define TFT_DC    15
#define SD_CS     32
#define TFT_SCLK  12
#define TFT_MOSI  37


Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  Serial.begin(115200);  
  Serial.println("Initializing display...");
  
  
  
  tft.initR(INITR_BLACKTAB);
  
  Serial.println("Display initialized.");
  
  
  tft.fillScreen(ST77XX_BLACK);
  
  
  tft.setTextSize(2);
  Serial.println("Setup complete.");
}

void loop() {
  
  uint16_t color = tft.color565(random(0, 255), random(0, 255), random(0, 255));

  
  tft.setTextColor(color);
  
  
  tft.fillScreen(ST77XX_BLACK);
  
  
  tft.setCursor(20, 57);  
  tft.print("Hello, World!");
  
  Serial.println("Displayed 'Hello, World!'");
  
  
  delay(200);
}

And here is a sketch of my wirering:

1 Like

Thanks you did a great job of posting the code and schematic. I am not experienced with that part but for the most part the UNO code should work but you will need to change the physical I/O pin numbers.

try using the constructor which also specifies MOSI and SCLK

Adafruit_ST7735(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk, int8_t rst);

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