hello-ecran.ino
Le premier coup d'écran du boîtier : texte, couleurs 16 bits et primitives de dessin via la bibliothèque M5Stack. Le tableau de bord est prêt — il ne reste qu'à y brancher des capteurs.
Matériel requis
Un M5Stack Core Basic/Gray (ESP32 dans un boîtier avec écran TFT 320×240, 3 boutons A/B/C, haut-parleur, micro SD, batterie 110 mAh). Aucun : l'écran est dans le boîtier.
Branchement
Aucun câblage. Alimentation par USB-C (ou la batterie interne 110 mAh). Le rétroéclairage s'éteint avec M5.Lcd.setBrightness(0).
Fonctionnement
M5.begin initialise écran, boutons, bus et alimentation ; le pilote ILI9341 dessine dans un framebuffer partiel et printf/writeDirect sont disponibles pour éviter les allocations du String. Dans l'Arduino IDE (paquet esp32), carte « M5Stack-Core-ESP32 » ; installez la bibliothèque « M5Stack » (ou M5Unified) via le gestionnaire, puis Téléverser.
Pour aller plus loin
Dessinez des barres de niveau pour des capteurs, ou affichez l'heure NTP du sketch dédié.
hello-ecran.ino
// Hello TFT ILI9341 — bibliotheque « M5Stack » (Gestionnaire de bibliotheques).
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setTextColor(TFT_YELLOW, TFT_BLACK);
M5.Lcd.setCursor(10, 10);
M5.Lcd.setTextSize(3);
M5.Lcd.println("M5Stack OK");
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_WHITE);
M5.Lcd.drawRect(5, 5, 310, 230, TFT_DARKGREY);
}
void loop() {
M5.Lcd.setCursor(10, 90);
M5.Lcd.printf("millis : %8lu\n", millis());
M5.Lcd.printf("heap : %8u o\n", ESP.getFreeHeap());
M5.Lcd.printf("rssi : %5d dBm\n", WiFi.Rssi());
delay(250);
}