NTP-synchronized digital clock for M5Stack Core2.
Displays date, weekday, and time with seconds. Syncs via WiFi/NTP at startup and hourly, with RTC backup when WiFi is unavailable. Features auto brightness adjustment (night mode) and SD card configuration.
- M5Stack Core2 (ESP32, LCD 320x240, RTC, PSRAM, battery)
- Date (YYYY-MM-DD), weekday, and time (HH:MM:SS) display
- NTP time sync at startup + hourly intervals
- RTC backup when WiFi unavailable
- Night mode with auto brightness (configurable hours)
- Battery percentage display
- Static IP or DHCP
- SD card JSON configuration
- Button A: show config, Button C: manual NTP sync
- Install board: M5Stack via Board Manager (v3.x)
- Install libraries:
M5UnifiedArduinoJson
- Open
m5-clock/m5-clock.ino - Select board: M5Stack-Core2
- Upload
Copy sdcard/config.example.json to SD card as /config.json and edit:
{
"wifi": {
"ssid": "your_ssid",
"password": "your_password"
},
"ntp": {
"server": "pool.ntp.org",
"timezone": 9,
"daylight_offset_sec": 0
},
"static_ip": {
"enabled": false,
"ip": "192.168.1.123",
"gateway": "192.168.1.1",
"subnet": "255.255.255.0",
"dns1": "8.8.8.8"
},
"night_mode": {
"enabled": true,
"start_hour": 22,
"end_hour": 7,
"brightness": 60,
"day_brightness": 200
}
}| Field | Default | Description |
|---|---|---|
wifi.ssid |
(empty) | WiFi SSID |
wifi.password |
(empty) | WiFi password |
ntp.server |
pool.ntp.org |
NTP server |
ntp.timezone |
9 |
UTC offset in hours |
ntp.daylight_offset_sec |
0 |
DST offset in seconds |
static_ip.enabled |
false |
Use static IP instead of DHCP |
night_mode.enabled |
true |
Enable auto brightness |
night_mode.start_hour |
22 |
Night mode start (24h) |
night_mode.end_hour |
7 |
Night mode end (24h) |
night_mode.brightness |
60 |
LCD brightness at night (0-255) |
night_mode.day_brightness |
200 |
LCD brightness during day (0-255) |
The clock works without an SD card using default settings (UTC+9, pool.ntp.org).
m5-clock/
├── m5-clock/
│ ├── m5-clock.ino ← main sketch (setup/loop)
│ ├── config.h ← build-time constants
│ ├── config_manager.h ← SD card JSON config reader
│ ├── ntp_sync.h ← WiFi + NTP sync (UTC internally, TZ at display)
│ └── display_manager.h ← clock/config display (sprite double-buffered)
└── sdcard/
└── config.example.json ← SD card config template
- Time handling: NTP syncs in UTC. Timezone offset is applied at display time only, avoiding double-offset issues with M5Unified RTC.
- Night mode: M5Unified correctly controls Core2 backlight brightness.
The legacy M5Core2.h
setBrightness()did not work reliably. - SD card: Core2 uses GPIO4 as SD card CS pin. Explicit
SD.begin(4)is required.
v2.0 migrates from the legacy M5Core2.h library to M5Unified:
- Requires ESP32 board package v3.x
- Remove legacy
M5Core2library if installed - Install
M5Unifiedvia Library Manager
See LICENSE.