7 SEGMENT DISPLAY

7 SEGMENT DISPLAY-Uncategorized

WHAT ARE THOSE?

Seven segment displays or seven segment indicators are popularly referred to as the old-school way of displaying Arabic numerals. Multiple characters can be displayed on the 9, 14 or 16 segment displays. Alternatively, there are similar screens which display other symbols, such as LED matrices.

Their name is obtained by being composed of 7 segments, which is seen in the picture above. Three of them are horizontal, and four vertical. Each segment is illuminated by LCD or LED technology. Actually, there are many ways to illuminate segments, for example very popular nixie lamps.

 

HOW DO THEY WORK?

Let’s stick to modern LED 7 segment displays. For starters, we will divide them into those with mutual cathode(-) and anode(+). It is simple, we will connect the displays with mutual cathode to the gnd pin, and then, using digitalWrite(pin, HIH); trigger the display’s segment and vice versa. Soon, in more detail.

The image above shows the display’s pins, a total of 10. The middle upper and lower pin refers to the mutual cathode, i.e. anode, depending on the model. 8 remaining ones are left for 7 segment display plus the spot which is in the lower right corner. Let’s check the pinout:

 

The pinout refers to the display with mutual cathode and shows which pin triggers which segment. For example, we connect the (-) pin to (-) battery’s pole, and pin8 through the resistor with + pole and the spot will light up.

If we use the display with mutual anode, we switch the poles and get the same thing.

Of course we will not relocate the cables for every sign we want to display so let’s connect everything to Dasduino.

 

CONTROLLING WITH DASDUINO

For starters, let’s connect the pins to Dasduino as shown in the picture. NOTE: here we use the display with mutual cathode, if you have a mutual anode, for now, just connect +5V off the Dasduino to pins which are connected to the black cable (gnd).

Here is a small connecting table:

There is no specific reason why we have chosen these pins, feel free to choose which ever you like. If your display takes up too many pins, consider using the shift register.

What and how to display?

The image above shows some of the symbols we can “activate” on the display. Let’s repeat the logic once more using the table:

Numbers 0 and 1 indicate both on and off, i.e. 0-LOW and 1-HIGH. Again, this applies to displays with a mutual cathode. If you use a mutual anode, simply replace zero and one.

Let’s write down one concrete Arduino code. We will turn on number 1, and after half a second, number 2.

void setup()
{
  // we will make a small loop which turns pins from 2 to 9 into output pins
  for(int i=2; i<=9; i++)
  {
    pinMode(i, OUTPUT);
  }
}
void loop()
{
  // turning number one on
  digitalWrite(5, HIGH);
  digitalWrite(8, HIGH);
  // pause 500ms = 0.5s
  delay(500);
  // shutting down the remaining characters on the display
  // in order for them not to mix with digit two
  digitalWrite(5, LOW);
  digitalWrite(8, LOW);
  // turning number two on
  digitalWrite(2, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  // another pause so that we manage to registrate
  // the change before the loop starts over
  delay(500);
  // shutting down number two segments
  digitalWrite(2, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}

And so on for each digit. A very long code. One way to make it easier is to make a function for each character we use, and then call it whenever we want:

// function for digit 1
void Jedan()
{
  digitalWrite(5, HIGH);
  digitalWrite(8, HIGH);
}
// function for digit 2
void Dva()
{
  digitalWrite(2, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
}
// function for deleting the remaining segments
void Ocisti()
{
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
}

The code from the first example would now look like this:

void setup()
{
  // we will make a small loop which turns pins from 2 to 9 into output pins
  for(int i=2; i<=9; i++)
  {
    pinMode(i, OUTPUT);
  }
}
void loop()
{
  Jedan(); //turning number one on
  delay(500);  //pause
  Ocisti(); //deleting the remaining segments
  Dva(); //turning number two on
  delay(500); //pause
  Ocisti(); //deleting the remaining segments
}
void Jedan()
{
  digitalWrite(5, HIGH);
  digitalWrite(8, HIGH);
}
// function for number 2
void Dva()
{
  digitalWrite(2, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
}
// function for deleting the remaining segments
void Ocisti()
{
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
}

This, of course, makes sense when we use the same digit more often than it is used in this example. These same functions can be put into library and be called when desired. Check out our tutorial about how to make your own Arduino library which controls these displays.