Go Down

Topic: 30 pin 4 digit display (Read 3149 times) previous topic - next topic

cjm771

[font=Verdana]
HI I am using a 30-pin 4 digit display i ripped out of an alarm clock. With luck I found that someone had done the same thing with the same model number and made this schematic:



From my understanding, for most segments, you activate one of the two grounds on the circuit (pin 1 or pin 2) to select one of two segments. I confirmed that this works..you can see in this video here: (http://www.youtube.com/watch?v=aaz4ETmIJv0)

I set up my arduino like so:

Arduino pins 2,3,4,5,6,7 - (handling pins 16-21 from display)
Arduino pins 8, 9, 10 - 74HC595 8 bit shift register (handling 5,6,9,10,12,13,14,15 pins from display)
Arduino pin 11   - Two center dots (pin 30 from display)
Arduino pin 12, 13 - ground 1 (pin 1) + ground 2 (pin 2)

My issue is how to program it....because to print numbers,  you will always need ground 1  for a segment on pin x but ground 2 for a segment on pin y at the same time.

I attempted to use delay(5) in between pinMode changes of the ground ...but this is not perfect as it doesnt really work with the shift register, and doesnt seem like it would be the properly ..

Anyone have any clue, I am a newbie! thanks so much!

-chris
[/font]

Grumpy_Mike

Quote
I attempted to use delay(5) in between pinMode changes of the ground ...but this is not perfect as it doesnt really work with the shift register, and doesnt seem like it would be the properly ..

You do not need to change the pin mode.
You do need resistors in line with the LEDs.
You need to multiplex the display, that is display some segments for a short time and then swap over and display the others. Done rapidly enough it will look like they are on all the time.

fungus


My issue is how to program it....because to print numbers,  you will always need ground 1  for a segment on pin x but ground 2 for a segment on pin y at the same time.


You alternate quickly between the two sets of LEDs. Persistence of vision does the rest.

The word "multiplexing" in the name of the forum...? That's what this technique is called.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

cjm771

Yes but in the scheme, 2 segments LEDs are controlled by 1 pin and the ground is what can change.. Is this not right? How can I alternate 2 LEDs from that one pin?

Grumpy_Mike

Yes it is right.
It is simple, you set the anode high and the cathode low to light only one segment. If the other cathode is set low then you do not set the anode high if you do not want the segment on.

fungus


Yes but in the scheme, 2 segments LEDs are controlled by 1 pin and the ground is what can change.. Is this not right? How can I alternate 2 LEDs from that one pin?


The input voltage isn't fixed. It has to change to match the LED that's connected to ground.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

cjm771

Ok thanks I think this works with the LEDs connected to pins directly, but for some reason it doesn't work properly with the shift register LEDs , I think it has something to do with the 2 gnds and 2 vccs connected to it...which when setting a segment on.. it either enables 2 segments or none..any ideas? Thanks guys!

dhenry

The design is fairly unique. I wonder if there are very clever way of driving it.

cjm771



ok guys, i managed to fix my problems with the register, and im slowly building a driving function...but with all the delays when switching voltages...the display is not super bright and now noticeably flickery...im using delay(5) in between voltage changes and display clears. Longer delay causes flickeryness, shorter causes dimness...

here is my code...any solutions? so closeeeeee!!



Code: [Select]


//shows the 4 digits on screen
void show_num(int a,int b,int c,int d){
  //turn on dots
      clearSegments();
       swapGround(ground1);
       digitalWrite(dotsPin, HIGH);
       delay(5);
       
    switch (a){
    case 1:
      clearSegments();
      swapGround(ground2);
      setRegisterPin(5, HIGH); //with g2,
      setRegisterPin(6, HIGH);
      writeRegisters();
       delay(5);
      break;
  }
  switch (b){
    case 1:
      clearSegments();
      swapGround(ground2);
      setRegisterPin(3, HIGH); //with g2,
      setRegisterPin(4, HIGH);
      writeRegisters();
       delay(5);
      break;
    case 2:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(3, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(5, HIGH);
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
  }
  switch (c){
    case 1:
      clearSegments();
      swapGround(ground2);
      digitalWrite(ledPins[2], HIGH);
      setRegisterPin(0, HIGH);
      writeRegisters();
       delay(5);
      break;
  }
  switch (d){
    case 1:
    clearSegments();
    swapGround(ground1);
    digitalWrite(ledPins[5], HIGH);
    digitalWrite(ledPins[2], HIGH);
    delay(5);
    break;
  }
}
void loop(){
show_num(1,2,1,1);
}



Function descriptions:
clearSegments() - resets all pins to low
swapGround() - switches the voltages

clearRegisters() - resets registered pins to low
setRegisterPin() -  set a register pin to high or low
writeRegisters() - update display with updated register


Code: [Select]

void clearSegments(){
//turn off normal pin leds
for (int x=0; x<ledLength; x++){
      digitalWrite(ledPins[x], LOW);
}
      digitalWrite(dotsPin, LOW);
      clearRegisters();
      writeRegisters();
     
}

void swapGround(int gr){

      if (gr==ground1){
        //  Serial.println("switched to ground 1");
         digitalWrite(ground1, LOW);
         digitalWrite(ground2, HIGH);
      }
      else if (gr==ground2){
         //Serial.println("switched to ground 2");
         digitalWrite(ground2, LOW);
         digitalWrite(ground1, HIGH);
      }
}

Nick Gammon

Without reading your code in great length, I suggest a fairly short delay for the "on state" and a very short or no delay for the clear.

So you want the segments to be on, more than they are off.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

cjm771

#10
Dec 30, 2012, 02:06 am Last Edit: Dec 30, 2012, 02:25 am by cjm771 Reason: 1
i have a "delay(5)" for display and no delay for the  clear...if i decrease it any further...the display is not on long enough and it gets even dimmer. if I increase it to say delay( 8 )...it becomes way too flickery.

Nick Gammon

Can you post all of the current code please, so we can see exactly the context of what you are doing where?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

cjm771

below is my full code...i posted some explanation in a few posts previous to this in regards to some of the functions
basically for each digit, (except 1 and 7), it has to switch the high and low twice...with a delay(5) of between switches for displaying. this is done in "show_num"

Function descriptions:
show_num(a,b,c,d) - shows digits specified in args
clearSegments() - resets all pins to low
swapGround() - switches the voltages

clearRegisters() - resets registered pins to low
setRegisterPin() -  set a register pin to high or low
writeRegisters() - update display with updated register


Code: [Select]
/*
Arduino pins 2,3,4,5,6,7 - (handling pins 16-21 from display)
Arduino pins 8, 9, 10 - 74HC595 8 bit shift register (handling 5,6,9,10,12,13,14,15 pins from display)
Arduino pin 11   - Two center dots (pin 30 from display)
Arduino pin 12, 13 - ground 1 (pin 1) + ground 2 (pin 2)
*/

//How many of the shift registers - change this
#define number_of_74hc595s 1

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

int const ledLength = 6;

int ledPins[ledLength] = {2,3,4,5,6,7};
int dotsPin =  11;
int SER_Pin = 8;   //pin 14 on the 75HC595
int RCLK_Pin = 9;  //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 11 on the 75HC595

int ground1 = 12;
int ground2 = 13;



void setup(){
        for (int x=0; x<ledLength; x++){
          pinMode(ledPins[x], OUTPUT);
        }
       // Serial.begin(9600);
        pinMode(dotsPin, OUTPUT);
        pinMode(SER_Pin, OUTPUT);
        pinMode(ground1, OUTPUT);
        pinMode(ground2, OUTPUT);
        pinMode(RCLK_Pin, OUTPUT);
        pinMode(SRCLK_Pin, OUTPUT);
        pinMode(dotsPin, OUTPUT);

          //reset all register pins
       clearRegisters();
         writeRegisters();

}               

void show_num(int a,int b,int c,int d){
  //turn on dots
      clearSegments();
       swapGround(ground1);
       digitalWrite(dotsPin, HIGH);
       delay(5);
       
    switch (a){
     
    case 1:
      clearSegments();
      swapGround(ground2);
      setRegisterPin(5, HIGH); //with g2,
      setRegisterPin(6, HIGH);
      writeRegisters();
       delay(5);
      break;
  }
  switch (b){
   case 0:
    clearSegments();
    swapGround(ground1);
    //bottom right
    setRegisterPin(2, HIGH); //with g2
    //setRegisterPin(4, HIGH); //with g2
    setRegisterPin(3, HIGH); //with g2
    setRegisterPin(5, HIGH); //with g2
    writeRegisters();
     delay(5);
     
    clearSegments();
    swapGround(ground2);
    //bottom right
     setRegisterPin(2, HIGH); //with g2
    setRegisterPin(3, HIGH); //with g2
     setRegisterPin(4, HIGH); //with g2
    writeRegisters();
       delay(5); 
    case 1:
      clearSegments();
      swapGround(ground2);
      setRegisterPin(3, HIGH); //with g2,
      setRegisterPin(4, HIGH);
      writeRegisters();
       delay(5);
      break;
    case 2:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(3, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(5, HIGH);
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
    case 3:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(3, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
    case 4:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
   case 5:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
       setRegisterPin(2, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
     case 6:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      setRegisterPin(5, HIGH); //with g2
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
       setRegisterPin(2, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
   case 7:
      clearSegments();
      swapGround(ground2);
      //bottom right
       setRegisterPin(2, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
       setRegisterPin(4, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
    case 8:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      setRegisterPin(5, HIGH); //with g2
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
       setRegisterPin(2, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
       setRegisterPin(4, HIGH); //with g2
      //setRegisterPin(5, HIGH); //with g2
      writeRegisters();
       delay(5); 
    case 9:
      clearSegments();
      swapGround(ground1);
      //bottom right
      setRegisterPin(2, HIGH); //with g2
      setRegisterPin(4, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
      writeRegisters();
       delay(5);
       
      clearSegments();
      swapGround(ground2);
      //bottom right
       setRegisterPin(2, HIGH); //with g2
      setRegisterPin(3, HIGH); //with g2
       setRegisterPin(4, HIGH); //with g2
      writeRegisters();
       delay(5);
      break;
  }
  switch (c){
    case 1:
      clearSegments();
      swapGround(ground2);
      digitalWrite(ledPins[2], HIGH);
      setRegisterPin(0, HIGH);
      writeRegisters();
       delay(5);
      break;
  }
  switch (d){
    case 1:
    clearSegments();
    swapGround(ground1);
    digitalWrite(ledPins[5], HIGH);
    digitalWrite(ledPins[2], HIGH);
    delay(5);
    break;
  }
}
int x_=0;
int start = millis();
void loop(){

  /*
//loop numbers
   x_= int(millis()/1000)%10;
   show_num(0,x_,1,1);
*/

show_num(1,7,1,1);

}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
}
void clearSegments(){
//turn off normal pin leds
for (int x=0; x<ledLength; x++){
      digitalWrite(ledPins[x], LOW);
}
      digitalWrite(dotsPin, LOW);
      clearRegisters();
      writeRegisters();
     
}

void swapGround(int gr){

      if (gr==ground1){
        //  Serial.println("switched to ground 1");
         digitalWrite(ground1, LOW);
         digitalWrite(ground2, HIGH);
      }
      else if (gr==ground2){
         //Serial.println("switched to ground 2");
         digitalWrite(ground2, LOW);
         digitalWrite(ground1, HIGH);
      }
}
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

Nick Gammon

What is the purpose of this first delay?

Code: [Select]

void show_num(int a,int b,int c,int d){
  //turn on dots
  clearSegments();
  swapGround(ground1);
  digitalWrite(dotsPin, HIGH);
  delay(5);    // <---------------- this one


Also I suggest you change all that delay(5) to delay(delayTime) where delayTime is a constant. That will make it much easier to tweak the delays.

Code: [Select]
const byte delayTime = 5;
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

cjm771

thats for the 2 dots, in the middle.. they will always be displayed. and true that about the constant, ive been meaning to do so.

Go Up