How to use a TM1638 4-digit display. Watch video

How to use a TM1638 4-digit display. Watch video

The TM1638 module is a versatile component that can display numbers and characters while being controlled by buttons. In this tutorial, you'll learn how to set up and program this display to show various values, including numbers and hex values. By the end of this guide, you will have a fully functional display that responds to button presses and changes what is shown based on user input. You can see a demonstration in the video at (in video at 00:00).
TM1637 keypad display module-1

Hardware Explained

The TM1638 module is designed for displaying information and receiving input from buttons. It consists of an 8-digit LED display and a matrix of 16 buttons. Each button can be programmed to trigger different functions, allowing for a user-friendly interface. The module connects to a microcontroller via three pins: a data input/output pin, a clock pin, and a strobe pin. This setup enables efficient communication between the microcontroller and the TM1638. The TM1638 IC manages the display and button inputs. It uses a serial communication protocol that allows it to control the display and read button states with minimal wiring. Each button press sends a signal to the microcontroller, which can then execute specific actions based on which button was pressed.

Datasheet Details

ManufacturerQYF
Part numberTM1638
Logic/IO voltage5 V
Supply voltage5 V
Output current (per segment)20 mA
Peak current (total)120 mA
Input logic thresholds0.2 V (low) / 0.8 V (high)
PackageDIP-28
  • Ensure the supply voltage is stable at 5 V for optimal performance.
  • Limit the output current to avoid damage to the display.
  • Use resistors to avoid excessive current through the LEDs.
  • Debounce button inputs in software to avoid multiple triggers.
  • Keep wiring short to reduce noise in communication.

Wiring Instructions

To wire the TM1638 module, you'll connect it to your microcontroller as follows:
Arduino wiring for TM1637 keypad display module
Arduino wiring for TM1637 keypad display module
- Connect the pin labeled VCC on the TM1638 to the 5V power supply of your microcontroller. - Connect the GND pin on the TM1638 to the ground of your microcontroller. - Connect the STB pin (often labeled as STROBE) to digital pin 5 on your microcontroller. - Connect the CLK pin (clock) to digital pin 2 on your microcontroller. - Connect the DIO pin (data input/output) to digital pin 3 on your microcontroller. Make sure to check your connections before powering on the system. If you have followed the video at (in video at 02:30), you should have no issues with the wiring.

Code Examples & Walkthrough

The following code snippet initializes the TM1638 module and sets up the display. The identifier module represents the TM1638 instance created for interacting with the display.
TM1638QYF module(DIO, CLK, STB);
void setup() 
{
  module.setupDisplay(true, 7);
}
In this snippet, the display is set up to show the maximum brightness (7). The next part of the code manages button presses and changes the display based on which button is pressed.
void update(TM1638QYF* module, word* mode) {
  word buttons = module->getButtons();
  if (buttons != 0) {
    *mode = buttons >> 1;
  }
  switch (*mode) {
    case 0: module->setDisplayToString("press 1"); break;
    // other cases follow
  }
}
This function checks which button is pressed using getButtons() and updates the display accordingly. The variable mode determines what text is displayed based on the button pressed. Finally, the main loop continuously updates the display.
void loop() 
{
  update(&module, &mode);
}
This loop calls the update function, ensuring the display is refreshed based on user interaction. For a complete understanding, refer to the full code loaded below the article.

Demonstration / What to Expect

Once you have everything wired and the code uploaded, pressing the buttons should change the display text accordingly. For example, pressing button 1 will display "press 1", while pressing button 2 changes it to "press 2". If there are any issues, double-check your wiring and ensure that the correct pins are used as mentioned. Watching the video at (in video at 05:00) will also help confirm that everything is functioning as expected.

Video Timestamps

  • 00:00 - Introduction
  • 02:30 - Wiring Instructions
  • 05:00 - Code Explanation and Demonstration

Images

TM1637 keypad display module-1
TM1637 keypad display module-1
TM1637 keypad display module-2
TM1637 keypad display module-2
TM1637 keypad display module-3
TM1637 keypad display module-3
TM1637 keypad display module
TM1637 keypad display module
Arduino wiring for TM1637 keypad display module
Arduino wiring for TM1637 keypad display module
28-This is the Arduino code for a TM1638 8-digit display with a 4x4 matrix button.
Language: C++
Copied!

Things you might need

Resources & references

Files📁

Arduino Libraries (zip)

User’s Manual