ESP32 Projects
Start a build
Markdown

ESP32 C3 Lcd1602 Pixel Clock for ESP32-C3

An ESP32 display project for ESP32-C3.

ESP32-C3ESP-IDF, ArduinoUnrated
Parts and source

Before you start

Confirm board compatibility and supported firmware targets in the upstream documentation.

Upstream README

ESP32-C3 LCD1602 Animated Network Clock

English · 中文

Clock display / 时钟显示效果

图 1 / Figure 1 — 正常时钟显示 / Normal clock display. 3×2 字符大号 HH:MM 位于左侧,右下角为两位自定义秒数字形。The 3×2-character large HH:MM occupies the left side, with two custom second digits at the lower right.

Pixel scan transition / 像素扫描线刷新过程

图 2 / Figure 2 — 像素扫描线刷新 / Pixel-scan transition. 分钟变化时, 上下两个 5×8 字符行中的全亮扫描线同步向下移动,并在扫描线上方逐行显现新时间。 On a minute change, a full-width pixel line moves downward through both 5×8 character rows while the new time is revealed above it.

中文

这是一个面向 ESP32-C3、HD44780 LCD1602 和 PCF8574T I²C 背包的 Arduino 网络时钟。 它使用 LCD1602 仅有的 8 个 CGRAM 字符绘制双行大号 HH:MM,并在右下角显示两位 科幻风格秒数。大号时间支持直接换字、像素扫描和分段翻页三种编译模式。

功能
  • 3×2 字符的大号 HH:MM,以及可选的两位秒数。
  • 默认使用 8 帧像素扫描,也可选择只更新变化位的四阶段分段翻页或关闭动画;秒数字有独立扫描动画。
  • 支持普通 2.4 GHz WPA2-Personal。
  • 支持 WPA2-Enterprise PEAP/MSCHAPv2、ESP-IDF 默认 CA 包和严格服务器域名验证。
  • 使用三个 NTP 服务器,按 CST-8 换算为中国标准时间。
  • 断网后继续走时并在后台限速重连。
  • LCD 在首次 NTP 同步前从 00:00:00 开始计时;内部仍使用编译时间或 Flash 中 保存的可信时间完成证书校验,避免证书校验与授时互相依赖。
  • 自带针对常见 P0=RS, P1=RW, P2=EN, P3=背光, P4–P7=D4–D7 背包的轻量驱动, 不需要安装额外 LCD 库。
硬件与接线
PCF8574T LCD1602 ESP32-C3
GND GND
SDA GPIO8
SCL GPIO9
VCC 参见下方安全说明

默认地址为 0x27。引脚、地址、背光极性和动画速度均可在 config.h 修改。

很多 LCD 背包会把 SDA/SCL 上拉到 5V,而 ESP32-C3 GPIO 不耐受 5V。LCD 使用 5V 供电时,请在 SDA/SCL 上使用双向 I²C 电平转换器,或确认上拉电阻连接到 3.3V。

当前 I²C 设为 250 kHz,以加快 CGRAM 动画。它高于原版 PCF8574T 标称的 100 kHz; 如果出现乱码、花屏或初始化失败,请把 I2C_CLOCK_HZ 改回 100000。

Arduino IDE 使用方法
  1. 在 Boards Manager 安装 Espressif esp32 3.3.12。

  2. 选择 ESP32C3 Dev Module。

  3. 启用 USB CDC On Boot;如果菜单提供该项,选择 USB Mode: Hardware CDC and JTAG。

  4. 打开 secrets.h,把其中 YOUR_... 提示占位符替换为自己的 SSID、密码和 EAP 参数。提交或分享代码前,请重新改回占位符,避免泄露凭据。

  5. 在 config.h 选择网络模式:

    #define NETWORK_MODE NETWORK_MODE_WPA2_PERSONAL
    // 或 / or:
    #define NETWORK_MODE NETWORK_MODE_ENTERPRISE_EAP
    
  6. 打开 LCD1602_Pixel_Clock.ino,编译并上传。

隐藏右下角秒数:

#define SHOW_SECONDS 0

关闭秒数时,中央冒号恢复为自定义方块字形。启用秒数时,CGRAM 0–5 用于大号数字, 6、7 正常用于秒十位和个位;大字扫描期间秒数暂时隐藏,6、7 临时变成可扫描实心块 和空白区扫描线,动画结束后再安全恢复秒数。

大号 HH:MM 动画在 config.h 中选择,默认使用像素扫描:

#define HHMM_ANIMATION_MODE HHMM_ANIMATION_PIXEL_SCAN
// 可选:HHMM_ANIMATION_NONE / HHMM_ANIMATION_SPLIT_FLIP

SPLIT_FLIP 依次执行“上半部灭、上半部显示新数字、下半部灭、下半部显示 新数字”,多个变化位同步进行。每阶段时长由 HHMM_FLIP_PHASE_MS 设置;该模式只 修改变化数字的 DDRAM 单元,不重写 CGRAM,因此不会干扰右下角秒数。

网络、证书与时间

企业模式使用 WiFi.begin(..., WPA2_AUTH_PEAP, ...) 选择 PEAP/MSCHAPv2。请在 secrets.h 中填写认证服务器证书的真实域名;程序不会在 CA 或域名校验失败时降级到 不安全连接,也不会将密码输出到串口。

NTP 首次同步超时为 20 秒,失败后每 5 分钟重试。同步成功后由 ESP32 SNTP 客户端 按其默认周期自动校时。可信时间最多每 24 小时写入一次 Preferences;ESP-IDF NVS 自带磨损均衡,不会每秒写 Flash。

首次 NTP 同步成功前,LCD 显示从 00:00:00 起步的开机计时;同步成功后自动切换为 中国标准时间。用于 TLS 验证的内部系统时间与该临时显示相互独立。

串口诊断

USB 串口会输出 I²C 扫描、LCD 初始化、Wi-Fi、证书域名、IP、NTP 和重连状态,但不会 输出密码。LCD 显示不依赖网络;无 LCD 时出现 no I2C device found 是预期行为。

English

An Arduino network clock for the ESP32-C3, an HD44780-compatible 16×2 LCD, and a common PCF8574T I²C backpack. It uses all eight CGRAM slots to render a large two-row HH:MM clock plus optional sci-fi-style seconds. The large clock offers direct, pixel-scan, and split-flip compile-time animation modes.

Features
  • Large 3×2-character HH:MM display with optional two-digit seconds.
  • Eight-frame pixel scan by default, with optional changed-digit split flip or no animation; seconds retain their own scan.
  • 2.4 GHz WPA2-Personal support.
  • WPA2-Enterprise PEAP/MSCHAPv2 with the ESP-IDF default CA bundle and strict authentication-server domain verification.
  • Three NTP servers with the CST-8 timezone for China Standard Time.
  • Offline clock operation and rate-limited background reconnection.
  • The LCD starts at 00:00:00 before its first NTP sync, while build-time or persisted trusted time remains available internally for certificate checks.
  • A small built-in PCF8574T driver for the common P0=RS, P1=RW, P2=EN, P3=backlight, P4–P7=D4–D7 mapping; no LCD library is required.
Hardware
PCF8574T LCD1602 ESP32-C3
GND GND
SDA GPIO8
SCL GPIO9
VCC See the voltage warning below

The default backpack address is 0x27. Pins, address, backlight polarity, and animation timing are configurable in config.h.

Many backpacks pull SDA/SCL up to 5 V, while ESP32-C3 GPIOs are not 5 V-tolerant. Use a bidirectional I²C level shifter when powering the LCD at 5 V, unless the pull-ups are confirmed to connect to 3.3 V.

The project currently runs I²C at 250 kHz for faster CGRAM animation. This is above the original PCF8574T's specified 100 kHz standard-mode limit. If the display becomes unstable, set I2C_CLOCK_HZ back to 100000.

Arduino IDE setup
  1. Install Espressif esp32 3.3.12 from Boards Manager.
  2. Select ESP32C3 Dev Module.
  3. Enable USB CDC On Boot and, when available, select USB Mode: Hardware CDC and JTAG.
  4. Open secrets.h, then replace every YOUR_... prompt placeholder with your own SSID, passwords, and EAP settings. Restore the placeholders before committing or sharing the code so credentials are not exposed.
  5. Select NETWORK_MODE_WPA2_PERSONAL or NETWORK_MODE_ENTERPRISE_EAP in config.h.
  6. Open LCD1602_Pixel_Clock.ino, compile, and upload.

Set SHOW_SECONDS to 0 to hide seconds and restore the custom block colon. With seconds enabled, CGRAM 0–5 hold the large-number pieces and slots 6–7 hold the second digits. During a minute transition, seconds are hidden and slots 6–7 temporarily become the animated solid block and blank-cell scan line; normal second glyphs are restored only after the large display is safe.

Select the large HH:MM animation in config.h:

#define HHMM_ANIMATION_MODE HHMM_ANIMATION_PIXEL_SCAN
// Alternatives: HHMM_ANIMATION_NONE / HHMM_ANIMATION_SPLIT_FLIP

The split-flip mode clears the changed digits' upper halves, draws their new upper halves, clears their lower halves, and finally draws the new lower halves. All changed positions move together. It touches DDRAM only, so the second-digit CGRAM glyphs remain intact. HHMM_FLIP_PHASE_MS controls each phase duration.

Networking and time

Enterprise mode selects PEAP/MSCHAPv2 through WiFi.begin(..., WPA2_AUTH_PEAP, ...). Enter the real authentication-server certificate domain in secrets.h. The firmware never falls back to insecure certificate handling and never prints passwords to USB serial.

Initial NTP synchronization times out after 20 seconds and retries every five minutes. After synchronization, the ESP32 SNTP client performs its normal periodic updates. Trusted time is written to Preferences no more than once per 24 hours; ESP-IDF NVS supplies wear levelling.

Before the first successful NTP sync, the LCD shows uptime beginning at 00:00:00. It switches to China Standard Time after synchronization; the internal time used for TLS validation is independent of this temporary display.

Diagnostics

USB serial reports I²C discovery, LCD initialization, Wi-Fi, certificate domain, IP address, NTP, and reconnection state without printing passwords. The display works without Wi-Fi, and no I2C device found is expected when the LCD is disconnected.

License

MIT. See LICENSE.