TM1637TinyDisplay: text that scrolls on a TM1637 display
TM1637TinyDisplay by Jason Cox drives the same four-digit TM1637 module as the classic TM1637Display library, and adds the things people end up writing by hand. showString() spells words in seven-segment letters and scrolls anything longer than four characters. showNumber() takes floats as well as whole numbers. showLevel() draws a bar graph, and showAnimation() plays frames you design.
Built in on Mokxi: #include <TM1637TinyDisplay.h> and it builds, with nothing to install. Free, and no account needed.
What TM1637TinyDisplay does
Most calls finish their work before they return: a long string scrolls to its end, one character every setScrolldelay() milliseconds, and only then does the next line of the sketch run. When the display must animate while loop() keeps reading sensors, use startStringScroll() or startAnimation() and call Animate() on each pass instead.
The common clock module has a colon and no decimal points, so a number with a fraction puts its point on the colon: showNumber(1.5) reads as 1:50. TM1637TinyDisplay6 handles the six-digit boards, which wire their digits in an odd order; Mokxi’s tm1637 part shows four digits, so six-digit output is best read from the sketch.
| Library Manager name | TM1637TinyDisplay |
|---|---|
| Author | Jason Cox |
| Include | #include <TM1637TinyDisplay.h>#include <TM1637TinyDisplay6.h> |
| Boards | every board Mokxi compiles for |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Four-digit display, TM1637 |
Install it
It builds on every board Mokxi compiles for.
In Mokxi it is built in: #include <TM1637TinyDisplay.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "TM1637TinyDisplay" by Jason Cox from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add TM1637TinyDisplay to lib_deps in PlatformIO. Mokxi follows the calls of release 1.12.2, so a sketch written here builds there too.
What to know in the simulator: A fraction’s decimal point is the colon, the module’s only point. The six-digit class sends its digits in those boards’ grid order (2, 1, 0, 5, 4, 3); the tm1637 part shows grids 0 to 3, so its frames are best read from the sketch.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- 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.
TM1637TinyDisplay display(2, 3)
The display with CLK on pin 2 and DIO on pin 3. Any two digital pins work; this is not I2C.
display.begin()
Sets the pins up and clears the display. Newer versions of the library want it before anything else.
display.setBrightness(BRIGHT_HIGH)
Brightness from BRIGHT_0 to BRIGHT_7, with BRIGHT_LOW and BRIGHT_HIGH as the two ends.
display.showString("HELLO")
Shows text; anything longer than four characters scrolls through and the call returns at the end.
display.setScrolldelay(100)
How long each scroll step lasts, in ms. Smaller numbers scroll faster.
display.showNumber(1234)
Shows a whole number or a float, right-aligned, with a minus sign when needed.
display.showLevel(50, false)
Draws a level from 0 to 100 as lit segments, across the digits by default, or as vertical bars when the second argument is false.
display.startStringScroll("RUNNING")
Begins a scroll that does not block. Call display.Animate() on every pass of loop() to move it on.
display.startStringScroll("RUNNING");
// in loop():
display.Animate();Example: Scroll a word, then show a number
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <TM1637TinyDisplay.h>
#define CLK 2
#define DIO 3
TM1637TinyDisplay display(CLK, DIO);
void setup() {
Serial.begin(9600);
display.begin();
display.setBrightness(BRIGHT_HIGH);
display.setScrolldelay(100);
display.showString("HELLO");
display.showNumber(1234);
Serial.println("shown");
}
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
Common errors and how to fix them
Buttons and sensors are ignored while text scrolls
showString() blocks until the whole string has gone by. Use startStringScroll() and Animate() in loop() so the sketch keeps running during the scroll.
showNumber(3.7) shows 3:70 instead of 3.7
The common four-digit clock module has only the colon, so the library uses it as the point. For a real decimal point you need a module with points on each digit.
Some letters look odd, like an M or a W
Seven segments cannot draw every letter well. Pick words that read clearly in segment letters, or design the characters yourself with setSegments() and raw bit patterns.
Questions and answers
How is TM1637TinyDisplay different from TM1637Display?
It drives the same chip and adds scrolling text, float numbers, level bars and animations, plus a non-blocking way to run them.
Try TM1637TinyDisplay without installing anything
Open the example, change the sketch, and keep your version in a free account.