Objectives
- Install the Arduino environment for the M5Stack Core (esp32 board package, “M5Stack-Core-ESP32” board, upload speed 921600).
- Install the M5Unified and M5GFX libraries (the classic M5Stack library is deprecated).
- Display text on the 2.0-inch 320×240 screen with an ILI9342C driver.
- Understand the setup / loop cycle with M5.begin and partial screen refresh.
Hardware
- 1 M5Stack Core kit (Basic K001 or Gray K002, any revision).
- 1 USB-C cable (data, not just charging).
- PC with Arduino IDE and the esp32 board manager (package URL: https://dl.espressif.com/dl/package_esp32_index.json).
- Note: this board does not have a documented user-controllable LED; all visual feedback is provided by the screen.
Complete Code
// M5Stack Core (Basic/Gray/GO/FIRE) — M5Unified + M5GFX requis
#include <M5Unified.h>
void setup {
Serial.begin(115200);
auto cfg = M5.config;
M5.begin(cfg); // initialise LCD ILI9342C, boutons, IP5306
M5.Display.fillScreen(TFT_BLACK);
M5.Display.setTextColor(TFT_YELLOW, TFT_BLACK);
M5.Display.setTextSize(2);
M5.Display.setCursor(10, 20);
M5.Display.println("Hello M5Stack!");
M5.Display.setTextSize(1);
M5.Display.setCursor(10, 60);
M5.Display.println("Ecran 320x240 ILI9342C");
Serial.println("Affichage OK");
}
void loop {
M5.update;
static uint32_t compteur = 0;
M5.Display.fillRect(10, 100, 200, 20, TFT_BLACK);
M5.Display.setCursor(10, 100);
M5.Display.printf("Secondes : %lu", compteur / 1000UL);
compteur += 100;
vTaskDelay(100 / portTICK_PERIOD_MS);
}
Expected Verification
- The screen displays “Hello M5Stack!” in yellow on a black background, followed by a running seconds counter.
- The serial monitor (115200 baud) displays “Display OK” after pressing the reset button.
- If the screen remains black, check that the board is powered on (red button: single click = power on).
Common Errors
- No COM port: recent revisions (v2.7) use a CH9102F USB bridge, older ones use a CP2104/CP210X — wrong driver = no serial port.
- Wrong board selected: choose “M5Stack-Core-ESP32” and upload speed 921600.
- Inverted colors (white/black) on pre-2019.7 units (TN screen): update M5GFX, which detects the revision.
- Forgetting M5.begin: nothing is displayed and no buttons respond.
- Confusing it with a Core2/CoreS3: pinouts differ, this tutorial targets the Core generation (K001/K002).