Go Down

Topic: [SOLVED] 2x Shift Registers with 3 Digits 7 Segment display (Read 1 time) previous topic - next topic

hardmehdi

Hello everyone,

I need your help for a small project that I can't get to work. I am using the arduino Uno with 2x 74HC164N shift registers to drive a 3 digit 7 segment display (Common catohde). My plan is to connect all the segment pins to one shift register and the digit pins to the other.

I used this code just to test :

Code: [Select]

#define data 2
#define clock 3

void setup() {
  pinMode(clock, OUTPUT);
  pinMode(data , OUTPUT);
}
void loop() {
  shiftOut(data, clock, LSBFIRST, B10100000); // This goes to the second shift register which controls the digits
  shiftOut(data, clock, LSBFIRST, B11011010); // This goes to the first shift register which controls the segments
  delay(1000);
}

// This code Prints 2 in the middle.



With that code it works but each time the loop runs the delay all the other segments that I didn't use they switch ON with a low brithness.




I already searched on the internet about a similar project and I found some results but my knowleadge is limited with it comes to this stuff so I still didn't find a solution to my problem.

Thank you for your help!

Edit : The glow effect happens only once in a loop like a flash, it doens't go on continuously.

Paul__B

Where do I start! :smiley-eek:

OK, this is just an exercise, so we won't get too concerned about the proper way to drive such displays being to use a MAX7219 which is designed to do the job perfectly.

Where are your resistors?

The eight (it has a decimal point) 220 ohm resistors in series with the segments?

I'm not totally sure why the phantom glow, but I don't think it is even worth investigating until you fit the resistors.

hardmehdi

Where do I start! :smiley-eek:

OK, this is just an exercise, so we won't get too concerned about the proper way to drive such displays being to use a MAX7219 which is designed to do the job perfectly.

Where are your resistors?

The eight (it has a decimal point) 220 ohm resistors in series with the segments?

I'm not totally sure why the phantom glow, but I don't think it is even worth investigating until you fit the resistors.

I added the 220 Ohm resistors in series with the segments now, and it did not change the glow.

PaulRB

Paul__B is correct, you are making every mistake in the book. Let's hope that you have not already damaged the chips or the display.

I suspect the glow is caused by the fact that the chip connected to the digit commons is overloaded. You are asking just one of its outputs to sink all the current for 7 or 8 segments. You need some transistors there to help it.

But even if you do that, I think you will always get some unwanted glow, once you begin to multiplex between the digits. This will happen because the 74hc164 has no latch pin or output enable pin. This means you cannot stop the outputs from updating while new data is being shifted in to the registers. This will cause an effect called "ghosting".

Paul

hardmehdi

I may be wrong, but there's a master reset that's always connected to +5, if I tie it to a digital pin on the arduino and LOW it to reset it every time a new data is sent, it won't resolve the problem?

If I have to use transistors how would that be?

Thanks.

PaulRB

With 220R series resistors, each segment will probably draw around 13mA current (assuming segment forward voltage of 2V and supply of 5V). This amount of current is ok for the segments and ok for the outputs of the chip connected to the segments. However, the total digit current is almost 100mA, which is too much for the outputs on the chip connected to the digits. Their maximum is 25mA. Also the max total current of 50mA for both the chips is being exceeded. So I am not surprised you still see the glow.

You can avoid these overloads by using 1K series resistors.

PaulRB

I may be wrong, but there's a master reset that's always connected to +5, if I tie it to a digital pin on the arduino and LOW it to reset it every time a new data is sent, it won't resolve the problem?

If I have to use transistors how would that be?

Thanks.
You cannot shift new data into the chips while master reset is low, so that will not help.

For transistors, use 3 npn like bc337. Connect their collectors to the common cathodes of each digit and their emitters to 0V. Connect their bases to the digit shift register outputs with 1K resistors.  You can then use lower series resistors on the segment anodes, but you must still respect the 50mA max for the chip.

Like Paul__B says, it would be easier and better to use a max7219!

hardmehdi

I have just tried the 1K resistors and it didn't solve the problem, I forgot to mention that the glow happens only once per loop, like a flash. You think that the code is correct?

PaulRB

I have just tried the 1K resistors and it didn't solve the problem, I forgot to mention that the glow happens only once per loop, like a flash. You think that the code is correct?
In that case i think it is the "ghosting" problem i mentioned.

You could try to minimise this problem by using the SPI hardware on the Arduino. This will shift the data quicker, reducing the ghosting effect. You will need to use pin 11 for data and 13 for clock and use SPI.transfer() instead of shiftOut().

In setup() you will need to add SPI.begin() and SPI.setBitOrder(LSBFIRST).

hardmehdi

Thanks PaulRB,

The SPI works great but is there a way to edit the brightness?

PaulRB


hardmehdi

What do you mean "edit"?
Reduce it for example. Because it's too bright actually.

Paul__B

Well, if you use 2k2 resistors instead, the total current draw will be about 10 mA and you will not need the buffer transistors.  This may be bright enough.

PaulRB

Because it's too bright actually.
Well, before you decide it is too bright, get the multiplexing working. That will reduce the brightness to one third of what you see now (actually it will look a bit brighter than one third because of the way the eye works).

hardmehdi

Hi,

Thanks for your help, I got it working with this code :

Code: [Select]

/*
This code is an edit from : http://cdn.sparkfun.com/datasheets/Components/LED/_7Seg_Example.pde
*/

#include <SPI.h>

#define data 11
#define clock 13

byte numbers[10] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};
byte digits[3] = {B11111011, B11111101, B11111110};

// Potentiometer
int count = 0;
int pot = A0;

void setup() {
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
 
  Serial.begin(9600);
  pinMode(pot, INPUT);
}

void loop() {
 
  int val = analogRead(pot);
  count = map(val, 0, 1023, 0, 100);
 
  Display(count);
}

void Display (int num) {
 #define BRIGHTNESS_LEVEL  2000
  long beginTime = millis();
  int holder;
  for (int i = 3; i > 0; i--) {

    holder = num % 10;
    num /= 10;
   
    // light up the digit
    switch (i) {
      case 1: //
        SPI.transfer(digits[0]);
        break;

      case 2: //
        SPI.transfer(digits[1]);
        break;

      case 3: //
        SPI.transfer(digits[2]);
        break;
    }
    // light up the segments
    SPI.transfer(numbers[holder]);
   
    delayMicroseconds(BRIGHTNESS_LEVEL);
   
    // turn off the display
    SPI.transfer(B11111111);
    SPI.transfer(B11111111);
   
     while( (millis() - beginTime) < 10) ;
  }


}

Go Up