TM1638
TM1638
User Guide
SKU: MDU1093
Brief Data:
Display Type: 8-Digit 7-Segment.
LED: 8 Red Color 3mm.
Key: 8 Tactile Switches.
Supply Voltage: 5V
Controller: TM1638.
Brightness Control on Segment.
Interface: 3 Lines Serial (CLK, STB, DIO).
Dimensions: 76mm x 50mm.
1 www.handsontec.com
Mechanical Dimension:
Unit: mm
Pin Assignment:
2 www.handsontec.com
Schematic Diagram:
Arduino Sketch:
Copy the following Arduino Sketch into Arduino IDE and upload to Arduino Uno board:
/*=====================================================================================
// Author : Handson Technology
// Project : Arduino Uno with TM1638 Display+Keypad Module
// Description : Display message on 8-digit 7-Segments, switch On LED with each key
press.
// Source-Code : TM1638_2.ino
// ====================================================================================
*/
3 www.handsontec.com
const int strobe = 7;
const int clock = 9;
const int data = 8;
void reset()
{
sendCommand(0x40); // set auto increment mode
digitalWrite(strobe, LOW);
shiftOut(data, clock, LSBFIRST, 0xc0); // set starting address to 0
for(uint8_t i = 0; i < 16; i++)
{
shiftOut(data, clock, LSBFIRST, 0x00);
}
digitalWrite(strobe, HIGH);
}
void setup()
{
pinMode(strobe, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(data, OUTPUT);
sendCommand(0x8f); // activate
reset();
}
#define COUNTING_MODE 0
#define SCROLL_MODE 1
#define BUTTON_MODE 2
void loop()
{
static uint8_t mode = COUNTING_MODE;
switch(mode)
{
case COUNTING_MODE:
mode += counting();
break;
case SCROLL_MODE:
mode += scroll();
break;
case BUTTON_MODE:
buttons();
break;
}
delay(200);
}
bool counting()
{
/*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/
uint8_t digits[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
4 www.handsontec.com
sendCommand(0x40);
digitalWrite(strobe, LOW);
shiftOut(data, clock, LSBFIRST, 0xc0);
for(uint8_t position = 0; position < 8; position++)
{
shiftOut(data, clock, LSBFIRST, digits[digit]);
shiftOut(data, clock, LSBFIRST, 0x00);
}
digitalWrite(strobe, HIGH);
bool scroll()
{
uint8_t scrollText[] =
{
/* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*H*/ /*E*/ /*L*/ /*L*/ /*O*/ /*.*/ /*.*/ /*.*/
0x76, 0x79, 0x38, 0x38, 0x3f, 0x80, 0x80, 0x80,
/* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*H*/ /*E*/ /*L*/ /*L*/ /*O*/ /*.*/ /*.*/ /*.*/
0x76, 0x79, 0x38, 0x38, 0x3f, 0x80, 0x80, 0x80,
};
sendCommand(0x40);
digitalWrite(strobe, LOW);
shiftOut(data, clock, LSBFIRST, 0xc0);
digitalWrite(strobe, HIGH);
return index == 0;
}
void buttons()
{
uint8_t promptText[] =
{
/*P*/ /*r*/ /*E*/ /*S*/ /*S*/ /* */ /* */ /* */
0x73, 0x50, 0x79, 0x6d, 0x6d, 0x00, 0x00, 0x00,
/* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/*b*/ /*u*/ /*t*/ /*t*/ /*o*/ /*n*/ /*S*/ /* */
0x7c, 0x1c, 0x78, 0x78, 0x5c, 0x54, 0x6d, 0x00,
/* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
5 www.handsontec.com
static uint8_t block = 0;
uint8_t readButtons(void)
{
uint8_t buttons = 0;
digitalWrite(strobe, LOW);
shiftOut(data, clock, LSBFIRST, 0x42);
pinMode(data, INPUT);
pinMode(data, OUTPUT);
digitalWrite(strobe, HIGH);
return buttons;
}
sendCommand(0x44);
digitalWrite(strobe, LOW);
shiftOut(data, clock, LSBFIRST, 0xC1 + (position << 1));
shiftOut(data, clock, LSBFIRST, value);
digitalWrite(strobe, HIGH);
}
Once successful uploaded, observe the message display on the 7-Segment display and the LEDs. Try pressing
any one of the key switch and observe the correspond LED being lighted.
Alternatively, you can you the ready available arduino library for TM1638 to simplify the driving of this
display+key board. Download the library from the below link and extract it to Arduino IDE Library folder.
https://github.com/rjbatista/tm1638-library
Try to upload some examples on this library and observe the display.
6 www.handsontec.com
Handsontec. com
We have the parts for your ideas
7 www.handsontec.com
The Face behind our product quality…
In a world of constant change and continuous technological development, a new or replacement
product is never far away – and they all need to be tested.
Many vendors simply import and sell wihtout checks and this cannot be the ultimate interests of
anyone, particularly the customer. Every part sell on Handsotec is fully tested. So when buying from
Handsontec products range, you can be confident you’re getting outstanding quality and value.
We keep adding the new parts so that you can get rolling on your next project.
P
Engineering Material Mechanical Hardware Electronics Components
8 www.handsontec.com