A TM1638-based LED display with pushbuttons for Arduino I/O

I recently decided to start playing with Arduino embedded computers. On May 9th 2012 I purchased an I/O board from DX.com containing eight 7-segment LED displays, 8 individual LEDs and 8 pushbutton inputs. It arrived May 30th 2012. These are my initial notes and an experiment.

The I/O board

My Arduino Uno R3 is based on an ATmega328 microcontroller (datasheet) with a range of analog and digital I/O pins for controlling and sensing their environment. Users are expected to provide their own external I/O boards.

Given the limited number of I/O pins on an Arduino board, this LED+pushbutton board is attractive in that it uses only two power connections (5v and GND) and three control signals.

Based on a TM1638 chip, the board uses a serial communications interface to enable three-wire control of the LEDs and reading of the pushbuttons. An unofficial translation of the Chinese TM1638 chipset reference manual is online here. (And the board I purchased appears to be a slightly improved version of this other board from DX.com)

The unit’s Input connector has following pinout (odd numbered pins down side closest to edge of PCB, even numbered down side closest to centre of PCB) :

	LED Display	Arduino
	1 - VCC		5V
	2 - GND		GND
	3 - CLK		?? (depends on the program)
	4 - DIO		?? (depends on the program)
	5 - STB0	?? (depends on the program)

CLK, DIO and STB0 are driven by whatever programmable pins the user has free on their Uno.

Programming with a Library

An Arduino enthusiast has been kind enough to develop a Library to drive this I/O board, saving me the hassle of learning how to drive the serial comms interface. Grab the library from here (a wiki with more information is here). I grabbed version 2.1.1 for my experiment.

Unzip the library file, and copy the TM1638 folder to the ./libraries/ sub-folder of the Arduino IDE’s folder. This enables the IDE to ‘see’ the library when compiling new “sketches” (as Arduino programs are called).

I wired up the I/O board to my Uno and successfully compiled, uploaded and ran the following modification of an example program from the library. (See here for my initial attempts at programming a Uno using WinXP under FreeBSD.)

/*
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>

This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <TM1638.h>

// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(8, 9, 7);

byte dots = 1;
long value = 0x1234ABCD;

void setup() {
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
 // display a hexadecimal number and set the left 4 dots
 module.setDisplayToHexNumber(0x1234ABCD, 0xF0);

 delay(3000);
}

void loop() {

 byte keys = module.getButtons();

 Serial.println(dots);

 module.setDisplayToHexNumber(value, dots, true);

 // light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
 module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));

 delay(50);

 dots = (dots * 2);
 if (dots == 0) {
 dots = 1;
 }

 value = (value +1 ) & 0xFFFFFF;
}

My modifications created an animation — the decimal points along the row of numeric LEDs would scan from right to left, and the number on the display would begin incrementing every 50ms with the top octet cleared to 00. The actual Uno pins to which my I/O board is connected are defined by the initial “TM1638 module(dio, clk, stb);” line.

Conclusion

It works, the Arduino Uno drove it without problem.

Advertisements

3 comments

  1. Hello there, You’ve done an incredible job. I’ll certainly digg it and personally recommend to my friends.
    I’m sure they’ll be benefited from this site.

  2. Can you please post a close up photo of conections made between arduino and TM? Has been a nut cracker to me to conect the 2 right..
    Thanks!

  3. In order to control ALL leds, I suggest this change:

    // light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
    module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xFF));

    Regards.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: