1

I'm an Arduino newbie having problems getting a 4 digit 7 segment display to work. The display is connected to a 74HC595 and the setup is from the elegoo tutorial 28 (I think it is download only).

I figured how to control which number to display, but all 4 digits always share the same number, so it is always like 1111, 5555, 9999 etc.

I've heard about something called multiplexing which might do the trick, but I can't adapt it to my project yet, missing too much experience.

This is the code that toggles between 2222 and 8888. I want to be able to display any number like 1234 though.

Any help is very appreciated.

int latch=9;  //74HC595  pin 9 STCP
int clock=10; //74HC595  pin 10 SHCP
int data=8;   //74HC595  pin 8 DS

void setup()
{
  pinMode(latch,OUTPUT);
  pinMode(clock,OUTPUT);
  pinMode(data,OUTPUT);
}

void Display(unsigned int num)
{  
  digitalWrite(latch,LOW);
  shiftOut(data,clock,MSBFIRST,num);
  digitalWrite(latch,HIGH); 
}

void loop()
{
    Display(91);
    delay(1000);
    Display(127);
    delay(1000);
}

image taken from the tutorial

  • We have no clue what elegoo is. Show us your circuit. – Majenko May 26 '17 at 14:16
  • Either you need multiplxing or you'll need to daisy chain 4 74HC595, one per digit. Otherwise, you won't get anything different than now. For multiplexing, I think there have been plenty of questions about this topic already. And a google search will show you what you need. – jfpoilpret May 26 '17 at 15:57
5

You have a common cathode display and all your cathodes are tied to ground through resistors. You have no way at all of separating out the different digits.

You cannot directly drive such a display with a shift register like that - you need a more direct connection to the Arduino (it needs to be high speed) and rapidly switch each cathode on and off in sequence to display each of the four numbers one after another.

Also the resistors should be in the 8 anodes, not the 4 cathodes.

  • Thank you Majenko for taking the time. I guess that means that this tutorial setup is not recommended nor feasible to be used to drive all digits separately then. I will have to search for a different setup that I can take as the base then. – Esshahn May 26 '17 at 14:53
  • It is possible to use the shift register if you also connect the cathodes to the Arduino and select each one in turn. With the shift register though it may be flickery. The code is also much more complex than just shifting out a number. – Majenko May 26 '17 at 14:54
1

but all 4 digits always share the same number, so it is always like 1111, 5555, 9999 etc.

because that's how this particular circuit is designed for.

I've heard about something called multiplexing which might do the trick, but I can't adapt it to my project yet, missing too much experience.

multiplexing is no different than displaying each digit quickly (as you are doing now), and then display the next digit quickly, ....

what you are doing now will contribute to your learning multiplexing.

0

The problem with this setup is the circuit.

The Master Reset Pin 10 on the 595 is floating.

Use a 10K resistor to pull it up to VCC (+5V) and it will work.

I was getting all sorts of odd characters until I checked out the data sheet on the 595.

0

That circuit needs a 0.1uF cap from '595 VCC to Gnd for consistent operation. Ideally a resistor between each '595 output and the anode pin, and a transistor or other higher current device able to sink the current from 8 anodes being driven at once (i.e. ULN2003). Once the cathodes can be driven seperately, to allow each digit to be selected individually, than an array can be used to map the digit to be displayed to the segments in a display:

// add before setup()
byte fontArray[] = {
0b00111111, // 0  where the bits represent dp-g-f-e-d-c-b-a
0b00000110, // 1  and 1 = segment turned on
0b01011011, // 2 
// etc.
};

// and change this line in display() to display a number

shiftOut(data,clock,MSBFIRST,fontArray[num); // looks up mapping from above

// then turn on a cathode to display it for 2-3mS, then back off, and send 
// out the info for the next digit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.