PyRaspBeta

4-digit display

A TM1637 display is four seven-segment digits with a colon between the middle two — the display from a cheap digital clock. It costs $5 and needs only two GPIOs, because the TM1637 controller is bit-banged rather than addressed like I²C. It is the easy way to show a number that must be readable across a room: a temperature, a countdown, a clock. For letters, see the LCD; for graphics, the OLED.

4-digit display

Pins

PinWhat it isType
CLKClock (pulled up on the module)io
DIOData in/out (pulled up on the module)io
VCCSupply 3.3–5 Vpower
GNDGroundground

Only CLK and DIO matter to the Pi; both are pulled up on the module (10 kΩ), so any two GPIOs work. DIO is open-drain: the driver pulls it low or lets the pull-up raise it, which is how the chip acknowledges a byte without a fight. VCC takes 3.3–5 V.

Wiring it in circuit.py

circuit.py
from wiring import *

pi = Pi()

display = TM1637()

pi.V3_3 >> display.vcc
display.gnd >> pi.GND
pi.GPIO23 >> display.clk
pi.GPIO24 >> display.dio

Driving it in main.py

The runtime ships the API of the popular raspberrypi-tm1637 library as the tm1637 module:

main.py
import tm1637
from time import sleep

display = tm1637.TM1637(clk=23, dio=24)

while True:
    display.numbers(12, 34)      # "12:34" with the colon
    sleep(1)
    display.number(42)           # right-aligned integer
    sleep(1)
    display.show("HELL")         # digits and the letters in its font
    sleep(1)

show(text) right-aligns and keeps the last four characters; number(n) shows −999…9999; numbers(a, b) shows two 2-digit fields with the colon. brightness(0–7) dims it, write([...]) sends raw segment bytes and clear() blanks it. The tm1637 library page lists the full API and the letters the font knows.

Electrical notes

  • Supply 3.0–5.5 V; the datasheet rates up to 80 mA with every segment lit. CLK and DIO are pulled up with 10 kΩ on the module (the model adds those two pull-ups to the net).
  • Not I²C: there is no address. Data goes out LSB first, each byte is followed by an ACK clock where the chip pulls DIO low, and frames are bracketed by start/stop conditions (DIO edges while CLK is high). The maximum clock is 250 kHz — far above what Python bit-banging produces.
  • Command bytes: 0x40/0x44 set data mode (auto-increment or fixed address), 0xC0 | address starts a write, and 0x80 | 0x08 | brightness turns the display on. Nothing shows until that last command.
  • The colon is bit 7 of the second digit's segment byte, which is why numbers() lights it and show() keeps a colon in the text there.
  • Input thresholds scale with VCC (30 %/70 % CMOS), so both 3.3 V and 5 V drivers are read cleanly.

Simulator vs real hardware

  • The part decodes the wire protocol bit by bit — start condition, eight data bits LSB first, ACK and stop — so the shipped tm1637 module works, and so would any other TM1637 driver or your own RPi.GPIO code.
  • Timing is not modelled: the simulator's delays are no-ops and the 250 kHz limit is not enforced. A real chip needs a few microseconds between edges; here you can send as fast as Python runs.
  • Brightness is stored (0–7), not PWM: the canvas dims the lit segments to match, and the control byte's on/off bit blanks the whole display.
  • The simulator skips repeated identical writes, so the bus sniffer will not show a frame you send twice unchanged; hardware would happily accept it.
  • Letters outside the small font (the library page lists them) render blank, as on a real module running this driver's font table.

Going deeper

Further reading