Arduino and TM1640 LED Display Modules

Introduction

The purpose of this article is to demonstrate the use of the second (here’s the first) interesting LED display module I discovered on the dealextreme website, for example:

As you can see the display unit holds a total of sixteen seven-segment LED digits using four modules. However thanks to the use of the TM1640 controller IC

… the entire display is controlled with only four wires – 5V, GND, data in and clock:

Here is the data sheet for the TM1640. The board also ships with the 30cm long four-wire lead and fitted plug. Finally, there is a ‘power on’ LED on the right-hand end of the board:

Getting Started

Now to make things happen. From a hardware perspective – it couldn’t be easier. Connect the 5V and GND leads to … 5V and GND. The data and clock leads will connect to two Arduino digital pins. That’s it. The maximum current drawn by the display with all segments on is ~213mA:

So you should be able to drive this from a normal Arduino-compatible board without any hassle. Please note that the TM1640 IC does heat up somewhat, so you may want to consider some sort of heatsink if intending to max out the display in this manner.

From the software side of things you will need to download and install the TM1638 library (yes) which also handles the TM1640 chip. To simply display text from a string on the display, examine the following sketch:

Which will display:

The sixteen digit binary number in the module.setDisplayToString() line controls the decimal points – 0 for off and 1 for on. For example, changing it to

will display:

You can also display text in a somewhat readable form – using the characters available in this list. Displaying numbers is very easy, you can address each digit individually using:

where x is the digit, y is the position (0~15), and true/false is the decimal point. At this time you can’t just send a long integer down to the display, so you will need to either convert your numbers to a string or failing that, split it up into digits and display them one at a time.

In the following example sketch we display integers and unsigned integers by using the C command sprintf(). Note the use of %i to include an integer, and %u for unsigned integer:

And the resulting output:

Now you have an idea of what is possible, a variety of display options should spring to mind. For example:

Again, this display board was 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 module worked well and considering the minimal I/O and code requirements, is 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.

10 Responses to “Arduino and TM1640 LED Display Modules”

  1. krishnan says:

    Very good & Thanks Mr. John Boxall.

  2. beardy241 says:

    Wow! Very nice. Thanks.

  3. Rich says:

    I enjoy your blog and have learned a lot. I bought one of these (and some of the button ones) to build a temp/humidity/baro sensor and was just now testing the display using your examples. Not sure if you meant to leave these out or not but in the sketches the first lines need to be:

    #include // required because the way arduino deals with libraries
    #include

    Thanks for doing the blog and these entries! When I get my project done I will post it somewhere.

  4. Rich says:

    OK I am learning how to use this thing,and I am quite new to actually programming an Arduino. I have managed to get mostly what I want.

    I want to use the display to show 4 sensor readings: 2 temperatures, humidity, and pressure. I am pretending at the values (which will come off the sensors when I hook them up) by specifying a value for them to see how they will display:

    void loop()
    {
    char text[17];
    int fractin;
    int fractout;
    int frachum;
    int fracpress;

    float tin;
    float tout;
    float hum;
    float press;

    tin=74.38;
    tout=95.45;
    hum=67.78;
    press=29.97;

    fractin=(tin-int(tin))*100;
    fractout=(tout-int(tout))*100;
    frachum=(hum-int(hum))*100;
    fracpress=(press-int(press))*100;

    sprintf(text, “%i %i %i %i “, int(tin), fractin, int(tout), fractout);

    module.setDisplayToString(text, 0b0100000100000100);
    delay(32766);

    module.clearDisplay();
    }

    I am just trying to display the first two temperatures, and I get the following on the display:\

    74.(blank)37(blank)95.(blank)44

    where blank is a skipped display digit. I get the decimal points in the right place but then the fraction part of the value wants to take up 3 spaces instead of 2. It also decrements the fraction values by 1 for some reason (37 instead of 38, 44 instead of 45)

    I also tried the following to try to get just a 2 digit integer but got the same display:

    void loop()
    {
    char text[17];

    int frachum;
    int fracpress;

    float tin;
    float tout;
    float hum;
    float press;
    float fractin;
    float fractout;

    tin=74.38;
    tout=95.45;
    hum=67.78;
    press=29.97;

    fractin=(tin-int(tin))*100;
    fractout=(tout-int(tout))*100;
    frachum=(hum-int(hum))*100;
    fracpress=(press-int(press))*100;

    sprintf(text, “%i %i %i %i “, int(tin), int(fractin), int(tout), int(fractout));

    module.setDisplayToString(text, 0b0100000100000100);
    delay(32766);

    module.clearDisplay();
    }

    Do you know why? I am thinking it has something to do with how many “digits” the fractin and fractout are — 3 instead of 2 but I am not sure why.

    –R

  5. Rathouis Charles says:

    Hi all, . I’m new with Arduino programming and electronic stuff, but Arduino make it quite simple !
    I have a question, will it be possible to communicate with other I2C periferical ? Because this TM&640 doesn’t have any SS pin.
    I understand that SS pin help to choose with witch slave you dial.

    Thanks !

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: