DigiClock Unit

UNIT-Digi-Clock is a 2.1 inch 4-digit 7-segment display module. There are decimal points on each digit and an extra wire for colon-dots in the center, which can display Decimals and Clock. This module adopts TM1637 as the driver IC, and STM32F030 as I2C communication. I2C address can be modified per 4-bit dip switch. The red LED supports 8 brightness. And we have reserved 4 fixing holes there.

Support the following products:

DigiClockUnit

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9from unit import DigiClockUnit
10import time
11
12
13label0 = None
14i2c0 = None
15digiclock_0 = None
16
17
18now = None
19
20
21def setup():
22    global label0, i2c0, digiclock_0, now
23
24    M5.begin()
25    Widgets.fillScreen(0x222222)
26    label0 = Widgets.Label("label0", 99, 97, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu40)
27
28    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
29    digiclock_0 = DigiClockUnit(i2c0, 0x30)
30    now = str((str(((time.localtime())[3])) + str(":"))) + str(((time.localtime())[4]))
31    digiclock_0.set_string(now)
32    label0.setText(str(now))
33
34
35def loop():
36    global label0, i2c0, digiclock_0, now
37    M5.update()
38    if now != (str((str(((time.localtime())[3])) + str(":"))) + str(((time.localtime())[4]))):
39        now = str((str(((time.localtime())[3])) + str(":"))) + str(((time.localtime())[4]))
40        label0.setText(str(now))
41        digiclock_0.set_string(now)
42    digiclock_0.set_raw(1, 2)
43    time.sleep(1)
44    digiclock_0.set_raw(0, 2)
45    time.sleep(1)
46
47
48if __name__ == "__main__":
49    try:
50        setup()
51        while True:
52            loop()
53    except (Exception, KeyboardInterrupt) as e:
54        try:
55            from utility import print_error_msg
56
57            print_error_msg(e)
58        except ImportError:
59            print("please update to latest firmware")

UIFLOW2 Example:

example.png

cores3_digi_clock_example.m5f2

class DigiClockUnit

Constructors

class DigiClockUnit(i2c: I2C, address: int | list | tuple = 0x30)

Initialize the DigiClockUnit.

参数:
  • i2c (I2C) – I2C port to use.

  • address (int | list | tuple) – I2C address of the DigiClockUnit.

UIFLOW2:

init.png

Methods

DigiClockUnit.clear() None

Clear the display.

UIFLOW2:

clear.png

DigiClockUnit.set_brightness(brightness: int) None

Set the brightness of the display.

参数:

brightness (int) – The brightness of the display, range from 0 to 8.

UIFLOW2:

set_brightness.png

DigiClockUnit.set_raw(data: int, index: int) None

Write raw data to the display.

参数:
  • data (int) – The data to write.

  • index (int) – The index of the data, range from 0 to 4.

UIFLOW2:

set_raw.png

DigiClockUnit.set_char(char: str, index: int) None

Write a character to the display.

参数:
  • char (str) – The character to write.

  • index (int) – The index of the character, range from 0 to 4.

UIFLOW2:

set_char.png

DigiClockUnit.set_string(string: str) None

Write a string to the display.

参数:

string (str) – The string to write.

UIFLOW2:

set_string.png

DigiClockUnit.get_fw_version() int

Get the firmware version of the DigiClockUnit.

返回:

The firmware version.

UIFLOW2:

get_fw_version.png