CircuitPython Code

Display the system time on a four digit seven segment display.

# SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import datetime
from adafruit_ht16k33 import segments
import board
import busio

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# Create the LED segment class.
# This creates a 7 segment 4 character display:
display = segments.Seg7x4(i2c)

# clear display

while True:
    # get system time
    now =
    hour = now.hour
    minute = now.minute
    second = now.second

    # setup HH:MM for display and print it
    clock = '%02d%02d' % (hour,minute)          # concat hour + minute, add leading zeros

    # Toggle colon when displaying time
    if second % 2:
        display.print(':')                      # Enable colon every other second
        display.print(';')                      # Turn off colon


Download and Run the Code

We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

python3 ./

You should see the time appear on your 7-segment display in 24-hour format with a slow blinking colon. It should look like this:

This guide was first published on Aug 24, 2012. It was last updated on Feb 29, 2024.

This page (7-Segment Clock) was last updated on Feb 29, 2024.

Text editor powered by tinymce.