Part

LED and key board, TM1638

Eight digits, eight LEDs and eight buttons on three wires. STB low, bytes least significant bit first.

See every part
  • 5 pins
  • In 1 project
  • In 1 lesson
Drawn live by the editor's own code, at the size you see it.
LED and key board, TM1638 as drawn in the Mokxi simulator
At a glance

The LED and key board, TM1638 in brief

What it is, and where it sits on the bench.

The TM1638 LED&KEY board has eight seven-segment digits, eight LEDs and eight buttons on three wires: STB, CLK and DIO, with VCC and GND at 5 V. STB, the strobe, is low for the length of each command. Data is taken on the rising edge of CLK, and DIO carries data both ways: the board drives it to send and the chip pulls it low to answer a key read. The chip holds the picture and scans the buttons itself, so a sketch only sends bytes, which makes it the usual front panel for clocks, counters and scoreboards. The model follows the datasheet’s data, address and display control commands, with sixteen bytes of display RAM. Press the buttons with the pointer.

Family
Displays
Pins
5
Pins

5 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
VCC
Supply, 5 V.
GND
Ground.
STB
Strobe: low for the length of each command.
CLK
The clock; data is taken on its rising edge.
DIO
Data, both ways: the board drives it to send, the chip pulls it low to answer a key read.
How to use it

How to use a TM1638 LED&KEY board with an Arduino

The board takes three signal wires and 5 V. STB goes to pin 4, CLK to pin 6 and DIO to pin 7, with GND on the Uno’s ground and VCC on 5 V. The sketch uses Gavin Lyons’ TM1638plus library, which Mokxi ships as TM1638plus.h, and its constructor takes the strobe, clock and data pins in that order.

readButtons() returns a byte with one bit for each of the eight buttons, bit 0 being S1. This sketch lights the LED over each held button, counts presses and shows the count and the last button on the eight digits. Click the buttons with the pointer.

Part pin
Board pin
VCC
5 V
GND
GND
STB
Pin 4
CLK
Pin 6
DIO
Pin 7
LED&KEY boardlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
Buttons to LEDs
#include <TM1638plus.h>

TM1638plus tm(4, 6, 7);   // STB, CLK, DIO

void setup() {
  tm.displayBegin();
  tm.brightness(2);
  tm.displayText("LED KEY ");
}

void loop() {
  uint8_t buttons = tm.readButtons();     // bit 0 is S1
  tm.setLEDs((uint16_t)buttons << 8);     // the LED over each button
  delay(20);
}
Common errors

Common LED and key board, TM1638 errors and fixes

What goes wrong
The fix
The digits stay blank.
Call displayBegin() first, then displayText(). Check STB, CLK and DIO are on pins 4, 6 and 7 as in the constructor.
The LEDs light over the wrong buttons.
The LEDs are the odd bytes of the display RAM. setLEDs() takes the button byte shifted left by 8, as above.
No button is seen.
DIO is two way: the chip pulls it low to answer a key read. Do not drive it from the board with a fixed output.
Questions

Questions and answers

How many pins does the TM1638 board need?

Three signal pins, STB, CLK and DIO, plus 5 V and ground.

How many buttons and LEDs does the LED&KEY board have?

Eight of each, with eight seven-segment digits.

Which library does Mokxi use for the TM1638?

Gavin Lyons’ TM1638plus, as TM1638plus.h.

How it is modeled

What is true about the LED and key board, TM1638, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

From the TM1638 datasheet: the data, address and display control commands; bytes least significant bit first on the rising edge of CLK; auto-increment and fixed addressing; sixteen bytes of display RAM, the even ones the digits and bit 0 of the odd ones the LEDs on this board; the eight pulse widths; display off keeping the RAM. A key read returns four bytes on DIO, open drain against the board's pull-up, with the board's buttons wired so the usual byte_i << i fold gives one bit per button.

Not modeled

The multiplexing (all eight digits are drawn lit at once), the 1 MHz clock limit, test mode, and the bicolor LEDs of the other TM1638 boards.

From TM1638 LED and key board, in full.

Projects

See the LED and key board, TM1638 in a project

One built-in project uses it. It opens in the editor, already wired.

Lessons

Where it turns up in a lesson

One lesson places it in its own circuit.

Boards

The boards it is shown on

This board has a built-in project with the LED and key board, TM1638 in it.

Libraries

Arduino libraries for the LED and key board, TM1638

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the LED and key board, TM1638

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.