Connecter un ecran TFT Display OLED LCD GMT020-02 240×320 a un ESP32
Description :
Ce projet explique comment brancher et interfacer un écran couleur GMT020-02 (équipé du contrôleur ST7789V) avec un microcontrôleur ESP32.
Prérequis :
- 1 x Carte ESP32
- 1 x 2.0 inch TFT Display OLED LCD GMT020-02 240×320
- 1 x Breadboard
Version IDE :
- Arduino IDE 2.3.5
Bibliothèque :
- Arduino_GFX_Library.h (version: 1.6.4 par Moon On Our Nationt)
Vidéo de démonstration :
NA
Schéma de câblage :


Code :
Code Arduino :
#include <Arduino_GFX_Library.h>
// --- CONFIGURATION DES BROCHES ESP32 ---
#define SCK_PIN 18
#define MOSI_PIN 23
#define MISO_PIN -1
#define CS_PIN 5
#define DC_PIN 2
#define RST_PIN 4
// --- INITIALISATION DU BUS ET DE L'ÉCRAN ---
Arduino_DataBus *bus = new Arduino_ESP32SPI(DC_PIN, CS_PIN, SCK_PIN, MOSI_PIN, MISO_PIN);
Arduino_GFX *gfx = new Arduino_ST7789(bus, RST_PIN, 0 /* Rotation */, true /* IPS */);
// --- VARIABLES DE L'ANIMATION ---
int16_t screenW, screenH;
int16_t ballX, ballY;
int16_t ballRadius = 12;
int16_t speedX = 3;
int16_t speedY = 3;
const int16_t headerHeight = 50;
const char *siteUrl = "projetsduino.com";
void setup() {
Serial.begin(115200);
// Démarrage de l'écran
if (!gfx->begin()) {
Serial.println("Erreur d'affichage !");
}
gfx->fillScreen(0x0000);
screenW = gfx->width();
screenH = gfx->height();
gfx->setTextSize(2);
gfx->setTextColor(0x07E0);
int16_t x1, y1;
uint16_t w, h;
gfx->getTextBounds(siteUrl, 0, 0, &x1, &y1, &w, &h);
gfx->setCursor((screenW - w) / 2, 15);
gfx->println(siteUrl);
gfx->drawFastHLine(0, headerHeight, screenW, 0xFFFF);
gfx->drawFastHLine(0, headerHeight + 1, screenW, 0xFFFF);
ballX = screenW / 2;
ballY = headerHeight + ballRadius + 5;
}
void loop() {
gfx->fillCircle(ballX, ballY, ballRadius, 0x0000);
ballX += speedX;
ballY += speedY;
if (ballX <= ballRadius || ballX >= (screenW - ballRadius)) {
speedX = -speedX;
ballX = (ballX <= ballRadius) ? ballRadius : (screenW - ballRadius);
}
if (ballY <= (headerHeight + ballRadius + 2)) {
speedY = -speedY;
ballY = headerHeight + ballRadius + 2;
}
if (ballY >= (screenH - ballRadius)) {
speedY = -speedY;
ballY = screenH - ballRadius;
}
uint16_t ballColor = gfx->color565(255, ballY % 255, ballX % 255);
gfx->fillCircle(ballX, ballY, ballRadius, ballColor);
delay(20);
}
