Wiring guide

How to wire a TM1637 display to an ESP32

To wire a TM1637 display to an ESP32, connect VCC to 3V3, GND to GND, CLK to GPIO 4 (D4) and DIO to GPIO 5 (D5). The module runs from 3.3 V here, so CLK and DIO stay at the board’s 3.3 V; the digits are a little dimmer than at 5 V. The sketch below uses the TM1637Display (TM1637Display.h) library. It counts up on the four digits of the display.

  • 3.3 V logic
  • Library: TM1637Display.h
  • 4 wires
ESP32 · TM1637 displaylive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

TM1637 display to ESP32 wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

TM1637 display pinESP32 pinWire colorWhy
VCC3V3redThe TM1637 runs from 3.3 to 5 V; brighter at 5 V.
GNDGNDblueCommon ground.
CLKGPIO 4 (D4)cyanClock. Any digital pin: it is not I2C, despite looking like it.
DIOGPIO 5 (D5)violetData, both directions.
Voltage

Power and logic levels for TM1637 display and ESP32

Logic level

The ESP32’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.

Supply

The TM1637 display takes 3.3 V from 3V3. That pin is the ESP32’s own regulated 3.3 V output.

This pair

On the ESP32 the module runs from 3V3, so CLK and DIO stay at the board’s 3.3 V. The digits are a little dimmer than at 5 V; setBrightness(7) makes up most of it.

Pins to leave alone

GPIO 34, 35, 36 (VP) and 39 (VN) are input only: they cannot drive a pin or take an internal pull-up. GPIO 0, 2, 5, 12 and 15 are strapping pins, read at power-on, and GPIO 6 to 11 are the flash chip.

The sketch

The working code for the ESP32

Library: TM1637Display (TM1637Display.h). This is the sketch the circuit above runs.

TM1637 clock on ESP32
#include <TM1637Display.h>

const int CLK_PIN = 4;   // GPIO 4 (D4)
const int DIO_PIN = 5;   // GPIO 5 (D5)

TM1637Display display(CLK_PIN, DIO_PIN);

void setup() {
  Serial.begin(115200);
  display.setBrightness(4);         // 0 to 7
  Serial.println("Counting");
}

void loop() {
  // Minutes and seconds since reset, with the colon on.
  unsigned long s = millis() / 1000;
  int mmss = (s / 60) % 100 * 100 + s % 60;
  display.showNumberDecEx(mmss, 0b01000000, true);
  delay(200);
}
Output

What you should see

The four digits count up. The serial monitor, at 115200 baud, prints Counting once. The module takes two data pins, CLK and DIO, and these are not I2C even though there are two of them.

A dark display with the supply connected usually means CLK and DIO are swapped or on pins other than the ones the sketch names.

The serial monitor prints this, recorded from the circuit above running:

Counting
Pitfalls

Common mistakes wiring a TM1637 display to an ESP32

Wiring CLK and DIO to the I2C pins

The protocol looks like I2C but is not; it has no address and the Wire library cannot talk to it. Any two digital pins work, and leaving GPIO 21 (D21) and GPIO 22 (D22) free keeps them for a real I2C part.

Expecting decimal points

Most TM1637 clock modules wire only the colon, not the dots under each digit. The dots argument lights them on modules that have them, and the colon on these.

Putting CLK or DIO on an input-only pin

GPIO 34, 35, 36 and 39 on the ESP32 have no output driver at all. pinMode() to OUTPUT on one of them does nothing and the line never moves, which looks exactly like a dead part. GPIO 4 (D4) is a safe choice; so are GPIO 13, 14, 16 to 19, 23, 25 to 27 and 32 to 33.

Build your own TM1637 display project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.