Sunday 18 March 2018

Seven Segment Display (SSD)

Seven Segment Display (SSD)

A single SSD can be used to display numbers and limited characters. In this post we will look into how to display characters and numbers on a SSD. There are two types of SSD, common cathode and common anode. From the outside both looks the same, but that does not mean that the way to control is the same.
Firstly we need to understand the segment name and the pin that controls it.The segment and pin ar looks the same for both common cathode and common anode type for the real device but of course internally they are different. In the picture below the internal structure on the right shows that this is a common anode because all the anodes are wired together.


Pin 3 and 8 is the common pin. Only one of them is needed to be connected to Vcc (5V) or GND depending on Common Anode (CA) or Common Cathode (CC). One way to remember the pins is to use BAFG.CDE (pronounced bafgdotcde).
How to know if the SSD is CA or CC in case you don't have the data sheet?
Just take a 220 ohm resistor and connect to pin B ( or any other pins) and  the other end of the resistor to GND. Wire the com pin  to 5V. If the segment B lights up then this is a CA type because current can flow from the 5V to led segment B and through the resistor to ground. If segment B does not light up then this must be CC type.

Common Cathode SSD testing

Common Anode SSD testing
Once the type of SSD is known, the interface to Arduino can be done and the program can be written. For the case of CA SSD, the final wiring to Arduino will be as following. Here the dot is not used.


The code below will count up from 0 to 2 at an interval of 1 second and repeat.

// all the ports that control the segments based on BAFG.CDE without the dot
int B = 2; // Upper segment
int A = 3; // Up-right segment
int F = 4; // Down-right segment
int G = 5; // Down segment
int C = 6; // Down-left segment
int D = 7; // Up-left segment
int E = 8; // Center segment

void setup() {
// Declare the pins as Outputs
pinMode(B, OUTPUT);
pinMode(A, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
}

// function that display a number sent by the main program
void displayNumber(int num)
{
// First we erase the previous value
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);

// To write 0
if (num == 0){
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
}

//To write 1
if (num == 1){
digitalWrite(B, LOW); // segment B and C will be ON to display 1
digitalWrite(C, LOW);
}

// To write 2
if (num == 2){
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(G, LOW);
digitalWrite(E, LOW);
digitalWrite(D, LOW);
}
}

void loop(){
// countup from 0 to 2
displayNumber(0);
delay(1000);
displayNumber(1);
delay(1000);
displayNumber(2);
delay(1000);
}











No comments:

Post a Comment