Arduino library 路 Displays

TM1637: four digits and a colon on two wires

The TM1637 module is the small four-digit display, red or blue, with a colon in the middle, sold for clocks and counters. A TM1637 chip on the back does the multiplexing, so the board only sends it what to show, over two wires named CLK and DIO.

Built in on Mokxi: #include <TM1637Display.h> and it builds, with nothing to install. Free, and no account needed.

What TM1637 does

Those two wires look like I2C but are not. The chip has no address and does not share a bus with other I2C devices, so it can go on any two digital pins and you give those pins to the constructor. Avishay Orpaz鈥檚 TM1637Display library, the one most tutorials include, handles the timing.

Two variants of the board exist: clock modules have the colon between the second and third digits and usually no decimal points, while others have a decimal point after each digit. Which one you have decides whether the dots argument of showNumberDecEx() lights a colon or a point.

Library Manager nameTM1637
AuthorAvishay Orpaz
Include#include <TM1637Display.h>
Boardsevery board Mokxi compiles for
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesFour-digit display, TM1637

Install it

It builds on every board Mokxi compiles for.

In Mokxi it is built in: #include <TM1637Display.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "TM1637" by Avishay Orpaz from the Arduino IDE鈥檚 Library Manager (Sketch, Include Library, Manage Libraries), or add TM1637 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.2.0, so a sketch written here builds there too.

ESP32-C3 路 Arduino Uno 路 Arduino Nano 路 Arduino Mega 2560 路 Arduino Leonardo 路 SparkFun Pro Micro 路 Arduino Micro 路 ESP32-C6 路 ATtiny85 路 Raspberry Pi Pico 路 Raspberry Pi Pico W 路 Seeed XIAO SAMD21 路 STM32 路 STM32 Nucleo-F411RE 路 STM32 Blue Pill 路 micro:bit V2 路 Arduino Uno R4 路 ESP32 DevKit 路 ESP32-S3-DevKitC-1 路 ESP8266 NodeMCU 路 Arduino Pro Mini 3.3 V 路 Seeed XIAO ESP32-C3 路 ESP32-C3 SuperMini 路 Seeed XIAO ESP32-C6 路 ESP32-DevKitC V4 路 LOLIN32 Lite 路 Wemos D1 R32 路 Cheap Yellow Display 路 TTGO T-Display 路 Seeed XIAO ESP32-S3 路 Arduino Nano ESP32 路 Arduino Nano RP2040 Connect 路 Seeed XIAO RP2040 路 Waveshare RP2040-Zero 路 Arduino Uno R4 WiFi

The calls you will use

In the order a sketch meets them.

TM1637Display display(CLK, DIO)

Creates the display on two pins, clock first. Any digital pins work.

display.setBrightness(7)

Brightness from 0 to 7. A second argument of false turns the display off without losing what it shows.

display.showNumberDec(1234)

Shows a whole number from -999 to 9999. showNumberDec(7, true) pads with leading zeros to show 0007.

display.showNumberDecEx(1530, 0b01000000, true)

Like showNumberDec() with dots: on a clock module 0b01000000 lights the colon, so 1530 reads 15:30.

int hhmm = hours * 100 + minutes;
bool colon = (millis() / 500) % 2;
display.showNumberDecEx(hhmm, colon ? 0b01000000 : 0, true);

display.setSegments(data)

Lights segments directly from an array of four bytes, one per digit, built from SEG_A to SEG_G, for letters and symbols.

const uint8_t done[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,  // d
  SEG_C | SEG_D | SEG_E | SEG_G,          // o
  SEG_C | SEG_E | SEG_G,                  // n
  SEG_A | SEG_D | SEG_E | SEG_F | SEG_G };// E

display.encodeDigit(5)

Returns the segment byte for a digit from 0 to 15, for mixing digits and symbols in one setSegments() call.

display.clear()

Blanks all four digits.

Example: Numbers on a four-digit display

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino 路 Arduino Uno R3
#include <TM1637Display.h>

#define CLK 2
#define DIO 3

TM1637Display display(CLK, DIO);

void setup() {
  Serial.begin(9600);
  display.setBrightness(0x0f);
  display.showNumberDecEx(1530, 0b01000000, true);   // 15:30
  delay(500);
  display.showNumberDec(1234);
  Serial.println("showing 1234");
}

void loop() {}

Wiring

  • Arduino Uno R3 2 to Four-digit display, TM1637 CLK
  • Arduino Uno R3 3 to Four-digit display, TM1637 DIO
  • Arduino Uno R3 5V to Four-digit display, TM1637 VCC
  • Arduino Uno R3 GND to Four-digit display, TM1637 GND

Open it in the editor, wired and ready to run

Common errors and how to fix them

Nothing lights at all

CLK and DIO are swapped or on different pins from the constructor. The constructor takes the clock pin first; swap the two numbers or the two wires, and check the module has 5 V and ground.

The colon never lights

showNumberDec() never lights it. Use showNumberDecEx() with 0b01000000 as the dots argument, and check the module is the clock kind, since some boards wire decimal points instead.

Negative numbers or numbers over 9999 show wrong digits

Four digits hold -999 to 9999. Scale or clamp the value before showing it, or show the units with setSegments() when the number does not fit.

Try TM1637 without installing anything

Open the example, change the sketch, and keep your version in a free account.