Arduino and TM1638 LED Display Modules

Introduction

The purpose of this article is to demonstrate the use of some interesting LED display modules I discovered on the dealextreme website, for example:

They contain eight 7-segment red LED digits, eight red/green LEDs and also eight buttons for user input. You can get red or green display models. The units can also be daisy-chained, allowing up to five at once, and a short cable is included with each module, as well as some short spacers and bolts, such as:

The spaces are just long enough to raise the PCB above a surface, however to mount the boards anywhere useful you would need longer ones. You may also want to remove the IDC sockets if you want to mount the module close to the surface of a panel. This would be a simple desoldering task as they are through-hole sockets:

The board is controlled by a TM1638 IC:

This part seems to be a domestic Chinese product from “Titan Micro Electronics“. After a quick search the TM1638 isn’t available from Digikey, Mouser or the element14 group… so if anyone has a lead on a low-volume, reliable supplier for these – please leave a comment below. However here is a link to the data sheet – thanks Marc!.

Getting Started

Now to make things happen…

Hardware – Connection to an Arduino-compatible board (or other MCU) is quite simple. The pinouts are shown on the rear of the PCB, and match the fitting on the ribbon cable. If you look at the end of the cable as such:

The top-right hole is pin one, with the top-left being pin two, the bottom-right pin nine and bottom-left pin ten. Therefore the pinouts are:

  1. Vcc (5V)
  2. GND
  3. CLK
  4. DIO
  5. STB1
  6. STB2
  7. STB3
  8. STB4
  9. STB5
  10. not connected

For Arduino use, pins 1~4 are the minimum necessary to use one module. Each additional module will require another digital pin connected to STB2, STB3, etc. More on this later. Please note that each module set to full brightness with every LED on consumes 127mA, so it would be wise to use external power with more than one module and other connections with Arduino boards. After spending some time with the module, I made a quick shield with an IDC header to make connection somewhat easier:

Software –  download and install the T1638 library from here. Thanks and kudos to rjbatista at gmail dot com for the library. Initialising modules in the sketch is simple. Include the library with:

then use one of the following for each module:

x is  the Arduino digital pin connected to the module cable pin 4, y is the Arduino digital pin connected to the module cable pin 3, and z is the strobe pin. So if you had one module with data, clock and strobe connected to pins 8, 7,  and 6 you would use:

If you had two modules, with module one’s strobe connected to Arduino digital 6, and module two’s strobe connected to digital 5, you would use:

and so on for more modules.  Now to control the display…

The bi-colour LEDs

Controlling the red/green LEDs is easy. For reference they are numbered zero to seven from left to right. To turn on or off a single LED, use the following:

Using the method above may be simple it is somewhat inefficient. A better way is to address all of the LEDs in one statement. To do this we send two bytes of data in hexadecimal to the display. The MSB (most significant byte) consists of eight bits, each representing one green LED being on (1) or off (0). The LSB (least significant byte) represents the red LEDs.

An easy way to determine the hexadecimal value to control the LEDs is simple, image you have one row of LEDs – the first eight being green and the second eight being red.  Set each digit to 1 for on and 0 for off. The convert the two binary numbers to hexadecimal and use this function:

Where green is the hexadecimal number for the green LEDs and red is the hexadecimal number for the red LEDs. For example, to turn on the first three LEDs as red, and the last three as green, the binary representation will be:

00000111 11100000 which in hexadecimal is E007. So we would use:

which produces the following:

The 7-segment display

To clear the numeric display (but not the LEDs below), simply use:

or to turn on every segment AND all the LEDs, use the following

To display decimal numbers, use the function:

where a is the integer, b is the position for the decimal point (0 for none, 1 for digit 8, 2, for digit 7, 4 for digit 6, 8 for digit 4, etc), and the last parameter (true/false) turns on or off leading zeros. The following sketch demonstrates the use of this function:

and the results:

One of the most interesting features is the ability to scroll text across one or more displays. To do so doesn’t really need an explanation as the included demonstration sketch:

included with the TM1638 library is easily followed. Just insert your text in the const char string[], ensure that the module(s) are wired according to the module definition at the start of the sketch and you’re set. To see the available characters, visit the function page. Note that the display is only seven-segments, so some characters may not look perfect, but in context will give you a good idea – for example:

Finally, you can also individually address each segment of each digit. Consider the contents of this array:

each element represents digits 1~8. The value of each element determines which segment of the digit turns on. For segments a~f, dp the values are 1,2,4,6,16,32,64,128. So the results of using the array above in the following function:

will be:

Naturally you can combine values for each digit to create your own characters, symbols, etcetera. For example, using the following values:

we created:

The buttons

The values of the buttons are returned as a byte value from the function:

As there are eight buttons, each one represents one bit of a binary number that is returned as a byte. The button on the left returns decimal one, and the right returns 128. It can also return simultaneous presses, so pressing buttons one and eight returns 129. Consider the following sketch, which returns the values of the button presses in decimal form, then displays the value:

and the results:

Update – 21/05/2012

A reader from Brazil has used one of the modules as part of a racing simulator – read more about it here, and view his demonstration below.

Update – 08/02/2013

Great tutorial on using these with a Raspberry Pi.

These display boards were a random, successful find. When ordering from dealextreme, do so knowing that your order may take several weeks to arrive as they are not the fastest of online retailers; and your order may be coming from mainland China which can slow things down somewhat. Otherwise the modules work well and considering the minimal I/O and code requirements, are a very good deal.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

41 Responses to “Arduino and TM1638 LED Display Modules”

  1. Richard says:

    The IDC placement is something that really baffles me with these displays, as does the lack of allignment of the LEDs and buttons.

    But as a readable alternative to a 16×2 LCD and some basic input in a cheap device they are great.

    I tried desoldering the header and putting one on the back, but then the pin order was totally messed up and I seemed to toast my display.

  2. Steve says:

    Thanks John, they are also available in Green http://tinyurl.com/8ycu4p2

    • Steve says:

      Actually, if you check out the electronic gadgets section http://www.dealextreme.com/c/gadgets-405 there is some cool stuff.

      • John Boxall says:

        Mmm gadgets…
        Note to Australians – importation and use of GSM boosters or jamming devices is illegal and under the Radiocommunications Act 1992, the regulator ACMA can take action against those that use jammers. Penalties include up to two years imprisonment or a fine of up to $165,000. Telstra and the ACMA can and do track down users of GSM boosters.

  3. pixel_k says:

    Interesting piece of hardware, too bad the IDC connectors are too high for a direct panel mount.
    Do you plan to test the 16 digit one ( https://www.dealextreme.com/p/jy-mcu-16x-digital-tube-yellow-led-module-104311 ) ?

    • John Boxall says:

      Yes the sockets are a puzzle. Will be removing them from one board for a forthcoming project. Thanks for pointing out that other device – I will now order some. Thanks!

  4. Serge says:

    Congrats, excelent article !
    My unit is already ordered, hope to have it here soon.
    Thanks John!

  5. hlantz says:

    Excellent timing; my three modules finally arrived after what seemed forever (but probably only was about a month) last week and I was hoping to get a look at them soon!

  6. Steve says:

    Thanks for the heads up John. I bought 5 of these modules thanks to this post for a project where I’ll have them display the pressures from 5 off 0 – 5V pressure sensors ( 0.5V – 4.5V) (4.5V short circuit fault monitoring).Delivery wasn’t too bad for me, 18 calendar days from payment to delivery.

    One of Ricardo’s libraries that could come in handy is the inverse one. For mounting displays vertically on a panel. I took a screen shot. http://wotid.com/pictures/albums/arduino/TM1638_inverse.jpg

    • John Boxall says:

      Very well done Steve, kudos. Stuff from DX is taking a little longer that usual due to the fact they sell mobile phone jammers… so I think customs is pulling almost all of their parcels at the moment. Waiting for my 16-digit and matrix displays…

  7. studzin says:

    Hi,
    I ordered tm1640 and tm1638 from zizhenfu at gmail.com, and they work great. I paid by paypal tm1638 $1.66 and tm1640 $1.7 with shipping.

  8. alex says:

    good all
    e-bay has them on offer for app, one dollar american +postage, p.s anybody got English data sheet . having problems downloading one

  9. alex says:

    good day all
    update found board schematic sheet for 1638.can studzin supply information on supplier for 1638

    thanks alex

  10. sandy says:

    studzin has actually left the paypal acc. name her e-Bay address is whymin_hvw5726pj

    [email protected]

    should this link go down, all i done was just e-mail some Chinese suppliers from e-bay and told them the part i required, and the rest is history
    sandy. (ps. great site keep up good work john)

  11. sandy says:

    hell0 folks re tm1638 studzin has actually left the pay- pal ref. the e-mail address

    [email protected]
    if this link should be broken all i done was e-mail several Chinese websites with the relevant question, ( part No) and the rest is history as they say. ps. great site john keep up good work.

    sandy

  12. BrunoG says:

    Hi, I want to make a binary counter with the leds but I have problems with the “0x…” can anybody help me?

  13. Ardiyno says:

    Thank you for the great tutorial.

  14. djdance says:

    Hello John, what do you think about how to connect a bigger digits to this TM1638-device?
    Big like this: http://proto-pic.co.uk/7-segment-red-6-5-display/
    It need 12v, so we have to use 8х8 transistors?

  15. dan says:

    If anybody would like to control this with the latest (and really cheap ! :) ) Stellaris Launchpad from TI, here’s a library I wrote:

    https://trandi.wordpress.com/2012/10/11/tm1638-display-driver-for-stellaris-launchpad/

    Hope you guys find it useful !

    Dan

  16. Mark Buttigieg says:

    Can you point me to a compatible Adruino Board? I would like to give this a try.

    Thanks

  17. Sebastian Schaffrath says:

    Hi, i will use 3 or 4 of this Modules but how i power them?
    The Arduino himself has too little power…

    Thanks
    Sebastian

    • John Boxall says:

      You will need to wire in your own 5V supply via pins 1 and 2 of the connector on the board.

      • Sebastian Schaffrath says:

        I tested this at the same way and it worked not properly.

        I hooked it up to an Breadboard Power Supply that Outputs +5v DC.
        VCC and GND to the Power Supply and DIO, CLK, STB0 to the Arduino.
        When i power the Module from the Arduino himself it works fine…

        But when i use the VCC and GND from the Power Supply it will not work. The 7-digit display lights then in a curious way up.

        What is when i connect the Power Supply GND and the Arduino GND on the GND Pin of the Module?

        Thanks for the help :)

      • John Boxall says:

        You will need to connect both GNDs together. Make sure your power supply can deliver enough current for all the boards.

  18. Alexsandr says:

    Hi! I’m from Russia, please tell me whether it will work in Assetto Corsa???

  19. Chamie says:

    Hi, for those in search for bare TM1638: they’re sold in any quantities by many sellers on AliExpress(.com) (as well as boards/modules built on them) for as low as US$ 0.40-0.50 (including the “free” shipping) in batches of 20+ pieces.
    What I’d be glad to know is the schematic of your board to build my own one with an external 4×4 keyboard.

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: