Clocks
Round smart watch
A watch face on a board that already has a round screen. It sets its own time over Wi-Fi, and one button switches between hands and digits.
- Medium
- about 35 min
- ESP32-S3 round
- 3 parts
- 119 lines of code
- Uses Wi-Fi
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
There is nothing to wire, so all the work is in the drawing. A hand is one line whose end is found with sine and cosine from the time.
Before you start
A LiPo cell can catch fire if it is punctured, crushed or connected backwards. An adult fits it, and it is never charged unattended.
What you learn
Drawing clock hands with trigonometry, and switching Wi-Fi off once the time is set to save power.
How it works
input
BOOT button (on the board)
decides
ESP32-S3 round · Wi-Fi
output
Round 1.28 in screen (on the board)
Powered with 5 V through the board's USB-C port.
It joins your home Wi-Fi. You type the network name and password into the sketch before uploading; they stay on the board.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 3 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
Nothing to wire: everything this build needs is already on the board. Plug in the USB cable and go to the sketch.
round-watch.ino
// Round smart watch
// A watch face on the Waveshare ESP32-S3-LCD-1.28. It sets its own time over
// Wi-Fi; press the BOOT button to switch between hands and digits.
//
// The screen is wired on the board. These are Waveshare's published pins.
#include <WiFi.h>
#include <time.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GC9A01A.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const long UTC_OFFSET_S = 7 * 3600; // Vietnam: UTC+7
const int LCD_DC = 8;
const int LCD_CS = 9;
const int LCD_CLK = 10;
const int LCD_MOSI = 11;
const int LCD_RST = 12;
const int LCD_BL = 40;
const int BOOT_BUTTON = 0;
Adafruit_GC9A01A tft(LCD_CS, LCD_DC, LCD_RST);
bool digital = false;
int shownSecond = -1;
int shownMinute = -1;
void hand(float turn, int length, uint16_t colour, int width) {
// turn: 0.0 at 12 o'clock, 0.25 at 3 o'clock
float a = turn * TWO_PI - HALF_PI;
int x = 120 + cos(a) * length;
int y = 120 + sin(a) * length;
for (int d = -width; d <= width; d++) {
tft.drawLine(120 + d, 120, x + d, y, colour);
tft.drawLine(120, 120 + d, x, y + d, colour);
}
}
void drawAnalog(const struct tm& now, bool full) {
if (full) {
tft.fillScreen(GC9A01A_BLACK);
for (int i = 0; i < 12; i++) {
float a = i / 12.0f * TWO_PI;
tft.fillCircle(120 + cos(a) * 108, 120 + sin(a) * 108, i % 3 == 0 ? 5 : 2, GC9A01A_WHITE);
}
} else {
tft.fillCircle(120, 120, 98, GC9A01A_BLACK); // wipe the old hands
}
hand((now.tm_hour % 12 + now.tm_min / 60.0f) / 12.0f, 55, GC9A01A_WHITE, 2);
hand(now.tm_min / 60.0f, 85, GC9A01A_CYAN, 1);
hand(now.tm_sec / 60.0f, 94, GC9A01A_RED, 0);
tft.fillCircle(120, 120, 5, GC9A01A_RED);
}
void drawDigital(const struct tm& now) {
char text[6];
snprintf(text, sizeof(text), "%02d:%02d", now.tm_hour, now.tm_min);
char date[12];
strftime(date, sizeof(date), "%d/%m/%Y", &now);
tft.fillScreen(GC9A01A_BLACK);
tft.setTextColor(GC9A01A_WHITE);
tft.setTextSize(6);
tft.setCursor(32, 84);
tft.print(text);
tft.setTextColor(GC9A01A_CYAN);
tft.setTextSize(2);
tft.setCursor(62, 150);
tft.print(date);
}
void setup() {
pinMode(BOOT_BUTTON, INPUT_PULLUP);
pinMode(LCD_BL, OUTPUT);
digitalWrite(LCD_BL, HIGH);
SPI.begin(LCD_CLK, -1, LCD_MOSI, LCD_CS);
tft.begin();
tft.fillScreen(GC9A01A_BLACK);
tft.setTextColor(GC9A01A_WHITE);
tft.setTextSize(2);
tft.setCursor(70, 112);
tft.print("Wi-Fi...");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED && millis() - start < 20000) delay(250);
configTime(UTC_OFFSET_S, 0, "pool.ntp.org", "time.google.com");
struct tm now;
getLocalTime(&now, 10000);
// The clock keeps running on the chip's own timer: Wi-Fi can rest now.
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
}
void loop() {
static bool redraw = true;
if (digitalRead(BOOT_BUTTON) == LOW) {
delay(30);
while (digitalRead(BOOT_BUTTON) == LOW) delay(5);
digital = !digital;
redraw = true;
}
struct tm now;
if (!getLocalTime(&now, 100)) {
delay(200);
return;
}
if (digital) {
if (redraw || now.tm_min != shownMinute) drawDigital(now);
} else if (redraw || now.tm_sec != shownSecond) {
drawAnalog(now, redraw);
}
shownSecond = now.tm_sec;
shownMinute = now.tm_min;
redraw = false;
delay(20);
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit GC9A01A: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Before uploading, type your Wi-Fi name and password into WIFI_SSID and WIFI_PASS at the top of the sketch.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.