MojoScale Studio Docs
API Reference

tm1637

TM1637 7-segment display module.

Studio Docs Displays

import tm1637

The tm1637 module drives common two-wire TM1637 LED display boards, usually 4-digit clock or counter displays. Use ``tm1637.Display(...)`` to create an independent display object. Each object owns one native display slot, so two or more TM1637 displays can run at the same time without channel bookkeeping.

Quick example

import tm1637
import system

counter = tm1637.Display(clk=18, dio=19)
clock = tm1637.Display(clk=22, dio=23, brightness=3)

counter.show_number(1234)

def tick():
    clock.show_clock(12, 34, colon=True)

system.schedule("clock", 1000, 1000, -1, tick)

import tm1637

display = tm1637.Display(clk=18, dio=19, digits=4, brightness=3)
display.show_text("done")
display.set_brightness(7)

importtm1637

TM1637 7-segment display module.

The tm1637 module drives common two-wire TM1637 LED display boards, usually 4-digit clock or counter displays. Use ``tm1637.Display(...)`` to create an independent display object. Each object owns one native display slot, so two or more TM1637 displays can run at the same time without channel bookkeeping.

API 21 available

tm1637.Display(clk: int, dio: int, digits: any = None, brightness: int = None, delay_us: int = None) -> tm1637_display

Create an independent TM1637 display object.

Parameters
Name Type Pass as Required Description
clk int positional or keyword Yes GPIO output pin connected to CLK.
dio int positional or keyword Yes GPIO output pin connected to DIO.
digits any positional or keyword No Optional number of display digits. Defaults to 4. Supported values are 1 through 6.
brightness int positional or keyword No Optional brightness from 0 through 7. Defaults to 7.
delay_us int positional or keyword No Optional bit-bang delay in microseconds. Defaults to 3.
Returns

tm1637_display tm1637_display object.

tm1637.Display().show_number(value, colon=False, leading_zero=False) -> bool

Display an integer.

Parameters
Name Type Pass as Required Description
value any positional or keyword Yes Required value.
colon bool positional or keyword No Optional value. Defaults to False.
leading_zero bool positional or keyword No Optional value. Defaults to False.

tm1637.Display().show_text(text, colon=False, position=0) -> bool

Display simple 7-segment text.

Parameters
Name Type Pass as Required Description
text str positional or keyword Yes Required value.
colon bool positional or keyword No Optional value. Defaults to False.
position int positional or keyword No Optional value. Defaults to 0.

tm1637.Display().show_clock(hour, minute, colon=True, leading_zero=True) -> bool

Display HHMM time.

Parameters
Name Type Pass as Required Description
hour any positional or keyword Yes Required value.
minute any positional or keyword Yes Required value.
colon bool positional or keyword No Optional value. Defaults to True.
leading_zero bool positional or keyword No Optional value. Defaults to True.

tm1637.Display().set_digit(position, value, dot=False) -> bool

Set one hex digit.

Parameters
Name Type Pass as Required Description
position int positional or keyword Yes Required value.
value any positional or keyword Yes Required value.
dot bool positional or keyword No Optional value. Defaults to False.

tm1637.Display().show_segments(segments, position=0) -> bool

Write raw segment byte or bytes.

Parameters
Name Type Pass as Required Description
segments any positional or keyword Yes Required value.
position int positional or keyword No Optional value. Defaults to 0.

tm1637.Display().set_brightness(value, enabled=True) -> bool

Set brightness and visibility.

Parameters
Name Type Pass as Required Description
value any positional or keyword Yes Required value.
enabled bool positional or keyword No Optional value. Defaults to True.

tm1637.Display().clear() -> bool

Blank this display.

tm1637.Display().info() -> dict

Return this display's configuration.

tm1637.Display().close() -> bool

Release this display slot and reset its pins.

tm1637.begin(clk: int, dio: int, digits: any = None, brightness: int = None, channel: int = None, delay_us: int = None) -> bool

Legacy: initialize one module-level TM1637 display channel.

Prefer ``display = tm1637.Display(...)`` for new code. The legacy default API remains for older scripts that manage displays through ``channel``.

Parameters
Name Type Pass as Required Description
clk int positional or keyword Yes GPIO output pin connected to CLK.
dio int positional or keyword Yes GPIO output pin connected to DIO.
digits any positional or keyword No Optional number of display digits. Defaults to 4. Supported values are 1 through 6.
brightness int positional or keyword No Optional brightness from 0 through 7. Defaults to 7.
channel int positional or keyword No Optional display channel. Defaults to 0. Supported channels are 0 through 3.
delay_us int positional or keyword No Optional bit-bang delay in microseconds. Defaults to 3.
Returns

bool True when the GPIO pins are configured and the display accepts a frame.

tm1637.show_number(value: any, colon: bool = None, leading_zero: bool = None, channel: int = None) -> bool

Display an integer.

Parameters
Name Type Pass as Required Description
value any positional or keyword Yes Integer value to show. Long values are clipped from the left.
colon bool positional or keyword No Optional colon/dot marker on the middle digit. Defaults to False.
leading_zero bool positional or keyword No Optional zero padding. Defaults to False.
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when the frame was transmitted.

tm1637.show_text(text: str, colon: bool = None, position: int = None, channel: int = None) -> bool

Display simple 7-segment text.

Parameters
Name Type Pass as Required Description
text str positional or keyword Yes Text to display. Supported characters include digits, common 7-segment letters, dash, underscore, space, and decimal points.
colon bool positional or keyword No Optional colon/dot marker on the middle digit. Defaults to False.
position int positional or keyword No Optional starting digit. Defaults to 0.
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when the frame was transmitted.

tm1637.show_clock(hour: any, minute: any, colon: bool = None, leading_zero: bool = None, channel: int = None) -> bool

Display hour and minute in HHMM form.

Parameters
Name Type Pass as Required Description
hour any positional or keyword Yes Hour value.
minute any positional or keyword Yes Minute value.
colon bool positional or keyword No Optional colon marker. Defaults to True.
leading_zero bool positional or keyword No Optional zero padding for the hour. Defaults to True.
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when the clock frame was transmitted.

tm1637.set_digit(position: int, value: any, dot: bool = None, channel: int = None) -> bool

Set one digit and write the display.

Parameters
Name Type Pass as Required Description
position int positional or keyword Yes Zero-based digit position.
value any positional or keyword Yes Hex digit value from 0 through 15.
dot bool positional or keyword No Optional decimal point on this digit. Defaults to False.
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when the frame was transmitted.

tm1637.show_segments(segments: list, position: int = None, channel: int = None) -> bool

Write raw TM1637 segment bytes.

Parameters
Name Type Pass as Required Description
segments list positional or keyword Yes One integer segment byte or a list of segment bytes.
position int positional or keyword No Optional starting digit. Defaults to 0.
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when at least one segment byte was written and transmitted.

tm1637.set_brightness(value: any, enabled: bool = None, channel: int = None) -> bool

Set brightness and display enabled state.

Parameters
Name Type Pass as Required Description
value any positional or keyword Yes Brightness from 0 through 7.
enabled bool positional or keyword No Optional visible display state. Defaults to True.
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when the brightness command was transmitted.

tm1637.clear(channel: int = None) -> bool

Blank the display.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when the blank frame was transmitted.

tm1637.encode(value: any, dot: bool = None) -> int

Return a raw 7-segment byte for a character.

Parameters
Name Type Pass as Required Description
value any positional or keyword Yes Character or digit to encode.
dot bool positional or keyword No Optional decimal point bit. Defaults to False.
Returns

int Integer segment byte.

tm1637.info(channel: int = None) -> dict

Return display configuration.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

dict Dict with initialized, channel, clk, dio, digits, brightness, enabled, and delay_us fields.

tm1637.deinit(channel: int = None) -> bool

Release a display channel and reset its pins.

Parameters
Name Type Pass as Required Description
channel int positional or keyword No Optional display channel. Defaults to 0.
Returns

bool True when an initialized display was released.