Projects / Pico W Wi-Fi clock

Pico W Wi-Fi clock

Beginner2 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. PICO

    Wire the display

    VCC to 3V3(OUT), GND to GND, CLK to GP14, DIO to GP15.

  2. PICO

    Edit the program

    Put your Wi-Fi name and password in the placeholders and set UTC_OFFSET for your place.

  3. PICO

    Run it

    The display shows the time after a few seconds.

  4. PICO

    Save as main.py

    So it runs when you plug in the Pico.

  5. PICO

    Compare

    Check against a phone clock.

  6. PICO

    Switch it off and on

    It sets the time again.

In short

How do you build a pico W Wi-Fi clock?

A Pico W sets its clock over Wi-Fi from a network time server and shows hours and minutes on a TM1637 display with a blinking colon. You need Raspberry Pi Pico W, TM1637 4-digit display and Breadboard 830 Tie Points. It takes 6 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
3

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TM1637 VCCPico W 3V3(OUT) pin 36Power at 3.3 V
TM1637 GNDPico W GND pin 38Common ground
TM1637 CLKPico W GP14 pin 19Display clock
TM1637 DIOPico W GP15 pin 20Display data

Code

The Pico W has no battery-backed clock, so each time it starts it asks a time server for the time. NTP, the network time protocol, gives the time in UTC, and the program adds your time zone offset in seconds before showing it. India is five and a half hours ahead of UTC, which is 19800 seconds. The TM1637 display chip is driven by two wires that look like I2C but are not, so the program includes a small driver that sends the bytes bit by bit: a command to set the address mode, the address, four bytes with one bit per segment, and a command to set the brightness. The colon is one extra segment bit on the second digit. The clock re-syncs every hour to stay accurate. The Wi-Fi name and password are placeholders; type your own and keep a sketch with the real ones private.

import time
import network
import ntptime
from machine import Pin

SSID = "YOUR_WIFI_NAME"                             # placeholders: use your own network
PASSWORD = "YOUR_WIFI_PASSWORD"
UTC_OFFSET = 19800                                  # seconds: 19800 is India (UTC+5:30), change for your place

SEGMENTS = [0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F]

class TM1637:
    def __init__(self, clk, dio, brightness=3):
        self.clk = Pin(clk, Pin.OUT, value=1)
        self.dio = Pin(dio, Pin.OUT, value=1)
        self.brightness = brightness

    def _d(self):
        time.sleep_us(5)

    def _start(self):
        self.dio.init(Pin.OUT, value=1)
        self.clk(1); self._d()
        self.dio(0); self._d()
        self.clk(0)

    def _stop(self):
        self.clk(0); self.dio.init(Pin.OUT, value=0); self._d()
        self.clk(1); self._d()
        self.dio(1); self._d()

    def _write_byte(self, b):
        for i in range(8):
            self.clk(0)
            self.dio((b >> i) & 1)
            self._d()
            self.clk(1)
            self._d()
        self.clk(0)
        self.dio.init(Pin.IN, Pin.PULL_UP)           # the chip pulls the line low to acknowledge
        self._d()
        self.clk(1); self._d()
        self.clk(0)
        self.dio.init(Pin.OUT, value=0)

    def show(self, hours, minutes, colon):
        digits = [hours // 10, hours % 10, minutes // 10, minutes % 10]
        segs = [SEGMENTS[d] for d in digits]
        if colon:
            segs[1] |= 0x80                          # the colon sits on the second digit
        self._start(); self._write_byte(0x40); self._stop()
        self._start(); self._write_byte(0xC0)
        for s in segs:
            self._write_byte(s)
        self._stop()
        self._start(); self._write_byte(0x88 | self.brightness); self._stop()

display = TM1637(14, 15)

def connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(SSID, PASSWORD)
    for _ in range(30):
        if wlan.isconnected():
            return True
        time.sleep(0.5)
    return False

def sync():
    if connect():
        try:
            ntptime.settime()                        # sets the Pico clock to UTC
            return True
        except OSError:
            return False
    return False

synced = sync()
last_sync = time.ticks_ms()

while True:
    if time.ticks_diff(time.ticks_ms(), last_sync) > 3600000 or not synced:
        synced = sync()
        last_sync = time.ticks_ms()
    t = time.localtime(time.time() + UTC_OFFSET)
    display.show(t[3], t[4], t[5] % 2 == 0)         # blink the colon every second
    time.sleep_ms(250)

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
A few seconds after startThe correct time appears
ColonBlinks once a second
Compare with a phoneWithin a second
Unplug and plug inThe time is right again
One hour laterStill correct after the next sync

If it does not work

Display stays blank

Check the CLK and DIO wires and the 3.3 V power.

Time is wrong by hours

Change UTC_OFFSET to your time zone in seconds.

Time never appears

Check the Wi-Fi name and password, and that the network is 2.4 GHz.

Digits garbled

Check CLK and DIO are not swapped.

Colon does not blink

Some modules wire the colon to the second digit only, check the module.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the pico W Wi-Fi clock?

Raspberry Pi Pico W, TM1637 4-digit display and Breadboard 830 Tie Points.

How long does the pico W Wi-Fi clock take to build?

About 120 minutes for a beginner maker, in 6 steps.

How do I know the pico W Wi-Fi clock works?

A few seconds after start: The correct time appears. Colon: Blinks once a second. Compare with a phone: Within a second.

Display stays blank: what should I check?

Check the CLK and DIO wires and the 3.3 V power.

Time is wrong by hours: what should I check?

Change UTC_OFFSET to your time zone in seconds.

Time never appears: what should I check?

Check the Wi-Fi name and password, and that the network is 2.4 GHz.

Digits garbled: what should I check?

Check CLK and DIO are not swapped.