About:
This single digit 7 segment display follows the cathode arrangement.
Ensure that all grounds are connected to a resistor (330 ohm is what i used).
Note this version does not have the number 0 working. Try and fix this
int RightBottom = 2; //PinC
int RightTop = 3; //PinB
int LeftBottom = 5; //PinE
int LeftTop = 6; //PinF
int CentreBottom = 8; //PinD
int CentreMiddle = 9; //PinG
int CentreTop = 10; //PinA
int PointPin = 12; //DP
int delayTime = 1000;
void setup() {
Serial.begin(9600);
pinMode(RightBottom, OUTPUT);
pinMode(RightTop, OUTPUT);
pinMode(LeftBottom, OUTPUT);
pinMode(LeftTop, OUTPUT);
pinMode(CentreBottom, OUTPUT);
pinMode(CentreMiddle, OUTPUT);
pinMode(CentreTop, OUTPUT);
pinMode(PointPin, OUTPUT);
}
void loop() {
int UserInput = Serial.parseInt();
int checkUserInput;
if (UserInput == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10; checkUserInput = UserInput) {
if(UserInput > 10){ //ensures only numbers from 1 to 10 are passed through
Serial.println("input only single digit numbers");
} else{
Serial.print("this is the inputVal ");
Serial.println(checkUserInput);
activateDigitalDisplay(checkUserInput);
}
}
}
void activateDigitalDisplay(int number) {
Serial.println("custom function running");
digitalWrite(RightBottom, LOW);
digitalWrite(RightTop, LOW);
digitalWrite(LeftBottom, LOW);
digitalWrite(LeftTop, LOW);
digitalWrite(CentreBottom, LOW);
digitalWrite(CentreMiddle, LOW);
digitalWrite(CentreTop, LOW);
digitalWrite(PointPin, LOW);
switch(number) {
case 0:
digitalWrite(RightBottom,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(LeftBottom,HIGH);
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(CentreTop,HIGH);
digitalWrite(PointPin, HIGH);
Serial.println("number 0 will be projected");
break;
case 1:
digitalWrite(RightBottom,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(PointPin, HIGH);
Serial.println("number 1 will be projected");
break;
case 2:
digitalWrite(CentreTop, HIGH);
digitalWrite(RightTop, HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(LeftBottom, HIGH);
digitalWrite(CentreBottom, HIGH);
digitalWrite(PointPin, LOW);
Serial.println("number 2 will be projected");
break;
case 3:
digitalWrite(CentreTop, HIGH);
digitalWrite(RightTop, HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightBottom, HIGH);
digitalWrite(CentreBottom, HIGH);
digitalWrite(PointPin, HIGH);
Serial.println("number 3 will be projected");
break;
case 4:
digitalWrite(LeftTop, HIGH);
digitalWrite(CentreMiddle, HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(RightBottom, HIGH);
digitalWrite(PointPin, LOW);
Serial.println("number 4 will be projected");
break;
case 5:
digitalWrite(CentreTop,HIGH);
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(PointPin, HIGH);
Serial.println("number 5 will be projected");
break;
case 6:
digitalWrite(CentreTop,HIGH);
digitalWrite(LeftTop,HIGH);
digitalWrite(LeftBottom,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(PointPin, LOW);
Serial.println("number 6 will be projected");
break;
case 7:
digitalWrite(CentreTop,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(PointPin, HIGH);
Serial.println("number 7 will be projected");
break;
case 8:
digitalWrite(CentreTop,HIGH);
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(LeftBottom,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(PointPin, LOW);
Serial.println("number 8 will be projected");
break;
case 9:
digitalWrite(CentreTop,HIGH);
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(PointPin, HIGH);
Serial.println("number 9 will be projected");
break;
case 10:
digitalWrite(RightBottom,HIGH); //0
digitalWrite(RightTop,HIGH);
digitalWrite(LeftBottom,HIGH);
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(CentreTop,HIGH);
digitalWrite(CentreMiddle,0);
digitalWrite(PointPin, HIGH);
delay(delayTime);
digitalWrite(RightBottom,HIGH); //1
digitalWrite(RightTop,HIGH);
digitalWrite(LeftBottom,0);
digitalWrite(LeftTop,0);
digitalWrite(CentreBottom,0);
digitalWrite(CentreMiddle,0);
digitalWrite(CentreTop,0);
digitalWrite(PointPin, HIGH);
delay(delayTime);
digitalWrite(CentreTop, HIGH); //2
digitalWrite(RightTop, HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(LeftBottom, HIGH);
digitalWrite(CentreBottom, HIGH);
digitalWrite(RightBottom,0);
digitalWrite(LeftTop,0);
digitalWrite(PointPin, LOW);
delay(delayTime);
digitalWrite(CentreTop, HIGH); //3
digitalWrite(RightTop, HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightBottom, HIGH);
digitalWrite(CentreBottom, HIGH);
digitalWrite(LeftBottom,0);
digitalWrite(LeftTop,0);
digitalWrite(PointPin, HIGH);
delay(delayTime);
digitalWrite(LeftTop, HIGH); //4
digitalWrite(CentreMiddle, HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(RightBottom, HIGH);
digitalWrite(LeftBottom,0);
digitalWrite(CentreBottom,0);
digitalWrite(CentreTop,0);
digitalWrite(PointPin, LOW);
delay(delayTime);
digitalWrite(CentreTop,HIGH); //5
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(RightTop,0);
digitalWrite(LeftBottom,0);
digitalWrite(PointPin, HIGH);
delay(delayTime);
digitalWrite(CentreTop,HIGH); //6
digitalWrite(LeftTop,HIGH);
digitalWrite(LeftBottom,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightTop,0);
digitalWrite(PointPin, LOW);
delay(delayTime);
digitalWrite(CentreTop,HIGH); //7
digitalWrite(RightTop,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(LeftBottom,0);
digitalWrite(LeftTop,0);
digitalWrite(CentreBottom,0);
digitalWrite(CentreMiddle,0);
digitalWrite(PointPin, HIGH);
delay(delayTime);
digitalWrite(CentreTop,HIGH); //8
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(CentreBottom,HIGH);
digitalWrite(LeftBottom,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(PointPin, LOW);
delay(delayTime);
digitalWrite(CentreTop,HIGH); //9
digitalWrite(LeftTop,HIGH);
digitalWrite(CentreMiddle,HIGH);
digitalWrite(RightTop,HIGH);
digitalWrite(RightBottom,HIGH);
digitalWrite(LeftBottom,0);
digitalWrite(CentreBottom,0);
digitalWrite(PointPin, HIGH);
delay(delayTime);
}
}
The SSD1306 128x64 is similar to the 128x32 varient except with the obvious 32 extra pixels added to the height of the display. It also has 4 pins and follows the same communication protocol.
Ensure that both common cathodes are connected to a resistor (i used 330 ohm), this can be done by replicating the same structure as fritzing diagram. The connectivity goes as follows:
Pins on Module | Pins on Uno |
---|---|
BOTH COMMON GND | (any) GND pin |
a | Pin 10 |
b | Pin 3 |
c | Pin 2 |
d | Pin 8 |
e | Pin 5 |
f | Pin 6 |
g | Pin 9 |
D.P | Pin 12 |