Home / Tutorials / Arduino Tutorial / How to Use TM1637 and Four Seven Segment Display Module
TM1637 4 digit seven segment display module

How to Use TM1637 and Four Seven Segment Display Module

A seven segment display has one pin for each of its seven segments. This means if directly interfaced with a microcontroller, you will need at least seven pins. Fortunately, there is a way to use four seven segment displays and using only four pins from your Arduino.

The TM1637 is a seven segment LED driver that communicates serially and can control up to six digits. Aside from power pins, it only requires a data pin and a clock pin.

TM1637 pinout

The segments connect to the SEGX pins as shown. The TM1637 supports only common anode displays and that anode pin connects to the GRIDX pins. The IC is also able to read eight keyboard pins and connects to the KSX pins.

How the TM1637 Works

One byte of data is sent to the TM1637 serially through its DIO pin. A start and stop sequence frames this data. A start sequence occurs when the DIO pin is low while the CLK pin goes from high to low. A stop sequence occurs when the DIO pin is low while the CLK pin goes from low to high.

TM1637 data format

To display a digit, the TM1637 must receive 0x40 first (command 1) then a 0xCX (command 2) where X is the position indicating which display to use. For example, if a digit is to be on the 3rd display, then the second command should be 0xC2. The next byte is the encoded value of whatever character you want to display. Finally, the last byte is 0x8Y (command 3) where Y is the 4-bit brightness of the display.

Four Digit Seven Segment Display Module

A module is available that contains a TM1637 and four mini seven-segment displays:

TM1637 4 digit seven segment display module

This module easily connects to an Arduino. Here’s an example wiring diagram:

Arduino to 4 digit seven segment display module

To simplify programming, I recommend using the TM1637 library by avishorp. This library centers on four main functions:

These functions are usable after installing the library, adding the header:

and then initiating a TM1637 object

Where CLK and DIO are user-defined Arduino pins.

After this, you can now call the functions above including setting the brightness of the display:

Here, 0x0F is the level for the brightest display while 0x00 is the dimmest.

Review on Seven Segment Displays

A digit displays on a seven segment if the correct LED segment receives power. Recall that each segment in a display is given a letter:

seven segment letter designation

We can represent our characters as binary numbers, with the LSB as the ‘a’ segment and MSB as the ‘dot’.

seven segment display as binary

For example, for a common cathode display, the digit ‘0’ in binary number representation is 0b00111111.

Using the TM1637 Library

As mentioned, the TM1637 library centers around four functions: setSegments(), showNumberDec(), showNumberDexEx() and setBrightness(). And while the IC supports a common anode display, the library reads binary representations as common cathode.

The setSegments() function accepts an array of bytes, length of characters and position of the character.

For example:

This code snippet will display two digit ‘0’ starting at the leftmost (position 0).

The colon in the middle is controllable through the second digit. We just need to set its ‘dot’ segment. So, this one displays two ‘0’ with a colon:

The showNumberDec() function has the following parameters:

Here, num is the digit to display, length is the number of digits to display and pos is the starting position. The leading_zero is either true or false; if true then zeroes are added to the left of the integer. If false, then the other leading numbers are left blank.

For example, this displays a 7, at position 3, with one leading zero.

This displays 32, starting at position 1, with no leading zero:

The showNumberDecEx() functions has the following parameters

The only difference of this function with that of showNumberDec() is the dots parameter. For our module, the colon directly connects with the 2nd digit. Thus, to turn it on, you can use:

Where 0x80 is the hexadecimal equivalent of 0b10000000. Recall that for binary representation of seven-segment displays, the MSB is the dot. Here, only the MSB is set hence it turns on.

However, this doesn’t turn on the dot:

This is because we are only using the 1st digit and since the colon is on the second digit, it doesn’t turn on.

You can display temperature values from a DHT11 to the seven segment module.  You can also display a simple minute-second timer:

I hope you find this article useful. See my Arduino projects for more applications of the TM1637 and four-digit seven segment displays. For any questions, kindly drop a comment below!

Check Also

Ultrasonic sensor with temperature compensation

Ultrasonic Sensor and Temperature Compensation

If you've been using Arduino, you might have used or have heard about the ultrasonic …

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.