hello-stick.ino

M5StickC Plus2 (M5Stack) — kit portable « stick » ESP32-PICO-V3-02 (SKU K016-P2) · Fichier : hello-stick.ino · Langage : Arduino · Usage : Afficher sur le petit écran 135×240

Premier écran sur la mini-station : M5Unified gère la rotation et le framebuffer du ST7789 1,14". En paysage 240×135, les printf font une console de debug embarquée dans la poche.

Matériel requis

Un M5StickC Plus2 (ESP32-PICO-V3-02, écran 135×240, boutons A/B/C, buzzer passif G2, IR + LED rouge G19, IMU MPU6886, micro, batterie 200 mAh). Aucun.

Branchement

Aucun câblage. Sur la v2 sans PMIC : maintenir bouton C plus de 2 s pour allumer ; HOLD (G4) maintient l'alimentation en batterie.

Fonctionnement

M5.begin détecte le panneau et applique la rotation ; setTextColor/fillRect dessinent directement. M5.update rafraîchit l'état des boutons A (38), B (37) et C (35). Dans l'Arduino IDE (paquet esp32), carte « M5StickCPlus2 » ; bibliothèque « M5StickCPlus2 » ou M5Unified. Sur la v2 sans PMIC, maintenez le bouton C > 2 s pour allumer ; HOLD (G4) maintient l'alimentation.

Pour aller plus loin

Éteignez l'écran avec M5.Display.setBrightness(0) pour économiser, ou affichez l'heure du sketch NTP.

hello-stick.ino

// Hello ST7789 — bibliotheque M5Unified (Gestionnaire de bibliotheques).
#include <M5Unified.h>

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  M5.Display.setRotation(1);            // paysage : 240 x 135
  M5.Display.fillScreen(TFT_BLACK);
  M5.Display.setTextColor(TFT_YELLOW);
  M5.Display.setTextSize(2);
  M5.Display.setCursor(4, 4);
  M5.Display.println("StickC Plus2");
}

void loop() {
  M5.update();
  M5.Display.fillRect(0, 40, 240, 60, TFT_BLACK);
  M5.Display.setCursor(4, 44);
  M5.Display.setTextSize(1);
  M5.Display.printf("millis : %lu\n", millis());
  M5.Display.printf("heap   : %u o\n", ESP.getFreeHeap());
  M5.Display.printf("btn A  : %d\n", M5.BtnA.isPressed());
  delay(200);
}

← Retour à la fiche