horloge.ino

M5StickC Plus2 (M5Stack) — ESP32-PICO-V3-02 "stick" wearable kit (SKU K016-P2) · File : horloge.ino · Language : Arduino · Use case : Faire une montre connectée à l'heure réseau

The stick's classic: NTP time in big digits, the colon blinking each second. The example shows configTime and the visual fallback when Wi-Fi drops.

Hardware required

An M5StickC Plus2 (ESP32-PICO-V3-02, 135×240 display, A/B/C buttons, passive buzzer on G2, IR + red LED on G19, MPU6886 IMU, microphone, 200 mAh battery). A 2.4 GHz access point.

Wiring

No wiring. The stick's antenna is moody in metal: test near the router.

How it works

configTime arms the ESP32 kernel SNTP; localtime_r fills a tm struct every pass. The display only refreshes at the delay cadence; the time source stays the kernel. In the Arduino IDE (esp32 package), board « M5StickCPlus2 »; « M5StickCPlus2 » or M5Unified library. On the PMIC-less v2, hold button C for >2 s to power on; HOLD (G4) latches the power.

Going further

Alarm + buzzer from the melody sketch, or weather from your server of choice at the screen bottom.

horloge.ino

// Horloge NTP : l'heure reelle sur l'ecran du stick.
#include <M5Unified.h>
#include <WiFi.h>
#include <time.h>

const char *SSID = "votre-wifi";
const char *CLE = "votre-cle";

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  M5.Display.setRotation(1);
  WiFi.begin(SSID, CLE);
  for (int i = 0; i < 40 && WiFi.status() != WL_CONNECTED; i++) delay(250);
  configTime(3600 * 2, 0, "pool.ntp.org", "time.google.com");  // UTC+2
}

void loop() {
  M5.update();
  struct tm t;
  time_t maintenant = time(nullptr);
  localtime_r(&maintenant, &t);

  M5.Display.setTextSize(3);
  M5.Display.setCursor(10, 30);
  M5.Display.setTextColor(t.tm_sec % 2 ? TFT_WHITE : TFT_DARKGREY);
  M5.Display.printf("%02d:%02d\n", t.tm_hour, t.tm_min);
  M5.Display.setTextSize(1);
  M5.Display.setTextColor(TFT_GREEN);
  M5.Display.setCursor(10, 100);
  M5.Display.printf("%04d-%02d-%02d  %s",
                    t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
                    WiFi.status() == WL_CONNECTED ? "wifi" : "HORS LIGNE");
  delay(200);
}

← Back to the board