Moniteur d’état 6 boutons sur écran TFT IPS ST7789 avec Arduino Mega
Description :
Ce projet consiste à concevoir une Interface Homme-Machine (HMI) interactive utilisant une Arduino Mega et un écran couleur IPS ST7789 (240×320). L’objectif est de créer un système de monitoring capable de lire et d’afficher en temps réel l’état de 6 entrées numériques (boutons poussoirs).
Prérequis :
- 1 x Carte Arduino Mega
- 6 x Bouton
- 1 x Écran LCD TFT 2.4 pouces, avec Module combiné d’encodeur rotatif EC11 et Interface SPI ST7789
- Fils de connexion
- 1 x Breadboard
Version IDE :
- Arduino IDE 2.3.5
Bibliothèque :
- Adafruit_GFX.h (version: 1.12.0 par Adafruit)
- Adafruit_ST7789.h (version: 1.11.0 par Adafruit)
- Adafruit BusIO (version: 1.7.14 par Adafruit)
Vidéo de démonstration :
Schéma de câblage :


Code :
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
// On regroupe les pins dans un tableau
const int pinsBoutons[] = { A0, A1, A2, A3, A4, A5 };
const int nbBoutons = 6;
#define TFT_BLK 47
#define TFT_CS 48
#define TFT_DC 49
#define TFT_RST 46
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
pinMode(TFT_BLK, OUTPUT);
digitalWrite(TFT_BLK, HIGH);
// Configuration automatique des 6 boutons
for (int i = 0; i < nbBoutons; i++) {
pinMode(pinsBoutons[i], INPUT_PULLUP);
}
// Initialisation de l'écran
tft.init(240, 320);
tft.setRotation(2);
tft.invertDisplay(false);
tft.fillScreen(ST77XX_BLACK);
// Titre
tft.setCursor(10, 10);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.println("Etat des Boutons");
// Tracer une ligne de séparation
tft.drawFastHLine(0, 35, 240, ST77XX_WHITE);
}
void loop() {
// On parcourt chaque bouton
for (int i = 0; i < nbBoutons; i++) {
// On calcule la position Y sur l'écran pour chaque bouton (40 pixels d'écart)
int posY = 50 + (i * 45);
tft.setCursor(40, posY);
tft.setTextSize(3);
if (digitalRead(pinsBoutons[i]) == LOW) {
// Bouton appuyé : Texte en VERT
tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
tft.print("BT");
tft.print(i + 1); // Affiche BT1, BT2, etc.
tft.println(" ON ");
// Log console
Serial.print("Bouton ");
Serial.print(i + 1);
Serial.println(" presse");
} else {
// Bouton relâché : On écrit en NOIR sur NOIR pour effacer
tft.setTextColor(ST77XX_BLACK, ST77XX_BLACK);
tft.print("BT");
tft.print(i + 1);
tft.println(" ON ");
}
}
}
