/* Work in progress.. incomplete.. */
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include <Adafruit_GFX.h> // graphics library
#include <Adafruit_ST7789.h> // library for this display
#include <SPI.h>
// 2.8" TFT display ST7789 (NOT with ILI9341), 240x320
// Display | color | ESP32 pin (38 pins Dev)
// GND | black | GND
// VCC | red | 3.3V
// SCK | blue | GPIO18 -- CLK
// SDA | green | GPIO23 -- MOSI
// RST | brown | GPIO13 -- Reset pin seems important…
// D/C | gelb | GPIO22 (data/command toggle, for displays, not SPI standard)
// CS | orange | GPIO5 SS (chip select)
/*
#define TFT_DC 22 // GPIO 22, beliebig.. data pin Display Data/command
#define TFT_CS 5 // Chip select
// TODO: backlight == LED mit PWM...
#define TFT_MOSI 23
#define TFT_CLK 18
#define TFT_RST 13 // reset pin
// #define TFT_MISO -- not used...
*/
// to ensure pinout for first tests, lets enumerate the important pins from pinout.
// Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
// Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK);
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);
void setup() {
//tft.init(240, 320, SPI_MODE2);
tft.init(240, 320, SPI_MODE3);
tft.invertDisplay(false);
tft.setRotation(1); // rotates the screen
// (0) == 0 Degree == portrait mode with connector at bottom
// (1) == 90 Degree == wide mode, connector at right side..
// (2) == 180 Degree == portrait on my display / connector on top
tft.fillScreen(ST77XX_BLACK); // fills the screen with black colour
tft.setCursor(10, 10); // starts to write text at y10 x10
tft.setTextColor(ST77XX_WHITE); // text colour to white you can use hex codes like 0xDAB420 too
tft.setTextSize(3); // sets font size
tft.setTextWrap(true);
tft.print("HELLO WORLD!");
tft.setCursor(20, 60);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(2);
tft.println("2.8' TFT, 320x240");
tft.setCursor(20, 100);
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(2);
tft.println("Color, ST7789");
tft.setCursor(20, 130);
tft.setTextColor(ST77XX_BLUE);
tft.setTextSize(2);
tft.println("SPI, 3.3V");
}
void loop() {
}my Display has a different pinout.
this is just to simulate..
// 2.8" TFT display with ILI9341, 240x320
// Display | color | ESP32 pin (38 pins Dev)
// GND | black | GND
// VCC | red | 3.3V
// SCK | blue | GPIO18
// SDA | green | GPIO21 incorrect? --> MOSI GPIO23
// RST | - | -
// D/C | gelb | GPIO22 (data/command toggle, for displays, not SPI standard)
// CS | orange | GPIO5 SS (chip select)