bclose

40 – Display with interface

Objectives

 

 

    • Our first 4-digit numeric display.
    • Multiplexing the digits.
    • Learning to program: splitting the problem into functions.
    • Back to operations with integers.
 

BILL OF MATERIALS

Arduino UNO

Arduino Uno or equivalent. This chapter accepts any other Arduino board.

Breadboard

A solderless breadboard.

Jumper wires

Some jumper wires.

BCD 4 digit 7 segment display

A 4-digit 7-segment display.

4-DIGIT LED DISPLAYS

 

In the previous chapter we saw how to use a 4-digit display assembling all the electronics by ourselves. We saw that the thing worked pretty well, and saw that we didn’t realize the trick of multiplexing the digits because in general Duinos are fast enough.

But what we certainly realized was how hard it is to assemble this circuit on a breadboard, the amount of wires that we have to connect and how easy it is to make mistake or inadvertently leave some wire unconnected.

In practice this system is used only for the students to learn to suffer, but in the real world it is much better to use a display with an integrated control system, which is a little more expensive, but doesn’t show none of the already mentioned problems.

Actually, they are so simple that do not usually have more than 4 pins and are directly controlled by software.
Today I am going to introduce a tiny display, but very awesome, that has been lying around on the table for some time and I love it.

It is a 4-digit display made by Catalex, a Chinese manufacturer, that is controlled via those 4 pins that we previously stated (two of them are Vcc and GND), has a very simple library and can be powered with both 5V and 3.3V.

 
  • I hope to receive one of these I2C displays soon (although we have not spoken of the I2C bus, but we will do it soon) and then we will make a chapter on the subject…
 

 

CIRCUIT WIRING DIAGRAM

 

The wiring of these displays is disturbingly simple:

Chapter 40, schematic diagram

 

After connecting Ground and Vcc there are only two wires left: DIO, Data Input Output, and Clock, which we will connect to pins 2 and 3, respectively. And that’s all, folks!

Chapter 40, Wiring diagram

THE CONTROL PROGRAM

 

The manufacturer of the display provides a library so we can forget the multiplexing and other stories:

DigitalTube.zip

We download and install it, as we saw in the chapter Getting to know servos, Then go to Sketch – > Include library and select the file you have just downloaded to be installed.

And in the list of libraries that appear in the drop-down, choose DigitalTube. You will see that the following line will be included in your sketch:

#include <TM1637.h>

It is an awful name for a library, we know it. To use it, we have to assign a couple of Arduino pins for the CLK signal and DIO:

#define CLK 3//pins definitions for TM1637 and can be changed to other ports
#define DIO 2

Now we need to create an instance of the object type TM1637, that we have called Display1, and pass it the pins that control communication:

TM1637 Display1(CLK,DIO);

And now the manufacturer asks us to send it the digits to represent as an unsigned 4 byte array defined as a rare type int8_t, but you do not need to worry about it:

int8_t  Digits[] = {3,2,1,2};

In this case the display will show 3212. And now we have to initialize the library and the display.

void setup()
   {
      Display1.set();
      Display1.init();
   }

And now we only have to ask it to print the Digits[] array:

Display1.display(Digits);

And that’s all. By sheer laziness I write the entire program for you to see the difference:

Sketch 40.1
#include "TM1637.h"
#define CLK 3    
#define DIO 2

TM1637 Display1(CLK,DIO);
int8_t Digits[] = {5,2,1,2};

void setup()
   {  
       Display1.set();
       Display1.init();
   }

void loop()
   {
       Display1.display(Digits);
   }

Let’s now make the counter example from the previous chapter to see how it looks. Let’s start with definitions

#include "TM1637.h"

#define CLK 3
#define DIO 2

TM1637 Display1(CLK,DIO);
int8_t Digits[] = {7,6,5,4};            // Initial value

void setup()
   {
      Display1.set();
      Display1.init();
   }

Let’s use a counter to see its value in the display, so we will need to split the digits of the value and put them in the Digits array. To do this we will recover the CalculateDigits() function from the previous chapter and add some minor modification:

Sketch 40.2
void CalculateDigits( int Num)
   {
      int8_t Digit0 = Num %10 ;
      int8_t Digit1 = (Num % 100) / 10 ;
      int8_t Digit2 = (Num % 1000) / 100 ;
      int8_t Digit3 = Num  / 1000  ;

      Digits[3] = Digit0 ;
      Digits[2] = Digit1 ;
      Digits[1] = Digit2 ;
      Digits[0] = Digit3 ;

      Display1.display(Digits);
   }

We calculate the digits and put them in the array, then simply call the display method (in lowercase) of the Display object (in capital letters). And to calculate the number we do the following:

void loop()
   {
       for (int i = 0 ; i<10000 ; i++)
            {
                CalculateDigits(i); 
                delay(100); 
            }
   }

 

SUMMARY

 

 

    • We have introduced the 4-digit 7-segment LED display from Catalex, which uses a proprietary (and undocumented) bus but as it works, I can almost forgive him.
    • We have modified our CalculateDigits() function, for we can use it with this display or others that require separated digits.
    • The virtue of this type of display or digital tube is the ease of connection and management using the library.
 

 

 

No Comments

Give a Reply