🛠 Afficher du texte sur l'écran 135×240
Objectives
Discover the 1.14" 135×240 screen (ST7789V2 controller, SPI: MOSI=G15, CLK=G13, DC=G14, RST=G12, CS=G5, backlight G27) of the M5StickC Plus2 and display your first lines of text using the M5Unified library, the officially recommended library (the old M5StickCPlus2.h is marked Deprecated by M5Stack).
Hardware
- 1× M5StickC Plus2 (SKU K016-P2, revision v2 since 2023.12, ESP32-PICO-V3-02, 8 MB flash + 2 MB PSRAM)
- 1× USB-C data cable (note: with a C-to-C cable, the COM port may not be recognized — power off the device until the green LED turns off, then reconnect)
- CH9102 USB driver installed on the PC
- Arduino IDE with the esp32 package (or PlatformIO:
platform = espressif32@6.7.0,board = m5stick-c, flags-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue,lib_deps = M5Unified)
Complete code
// M5StickC Plus2 — hello écran (M5Unified + M5GFX depuis le gestionnaire de libraries)
#include <M5Unified.h>
void setup {
auto cfg = M5.config;
M5.begin(cfg); // init ST7789V2 135x240 (broches officielles)
M5.Display.setRotation(1); // paysage : 240 x 135
M5.Display.fillScreen(TFT_BLACK);
M5.Display.setTextColor(TFT_GREEN, TFT_BLACK);
M5.Display.setTextSize(2);
M5.Display.setCursor(4, 4);
M5.Display.println("StickC Plus2");
M5.Display.setTextSize(1);
M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Display.printf("Flash: %u MB\n", (unsigned)(ESP.getFlashChipSize / 1048576));
M5.Display.printf("PSRAM: %s\n", psramFound ? "2 MB OK" : "absente");
}
void loop {
M5.update;
M5.Display.setCursor(4, 110);
M5.Display.printf("millis = %lu ", (unsigned long)millis);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
Expected verification
Upon power-up, the screen displays "StickC Plus2" in green, followed by "Flash: 8 MB" and "PSRAM: 2 MB OK"; a millis line scrolls at the bottom. The device powers on by holding the C button for more than 2 seconds (revision v2, without PMIC AXP192).
Common errors
- Incorrect screen initialization → "Green LED on but black screen": a classic issue when compiling a standard M5StickC (Plus) example for a Plus2; use M5Unified and a Plus2-compatible board.
- Forgetting
M5.begin(cfg)orM5.updatein the loop. - Screen "upside down": don't forget
setRotation(1)for landscape mode 240×135. - COM port not found: missing CH9102 driver, or a C-to-C cable not properly recognized (power off then reconnect).
- Using the old library
M5StickCPlus2.h: it compiles but is no longer maintained.
Other tutorials for this board
Code examples for this board
hello-stick.inoArduinoboutons.inoArduinobuzzer.inoArduinoinclinometre.inoArduinohorloge.inoArduinoir-tv.inoArduino