Go Down

### Topic: help with - 2 digit 7 segment display and 2 74hc595 (Read 8111 times)previous topic - next topic

#### crsunu

##### Oct 23, 2012, 05:51 pm
Hi all,

This is my first post here.

I just started learning about arduino recently and I am currently trying to build a two digit count down timer 0 - 99
I ran into a little bit of trouble and I am hoping someone here can give me some guidance..

my problem is that I can't seem to get it to display the numbers corectly and I don't know what I am doing wrong, now the sequence of numbers that it displays is :
0,0,00,1,4,5,66 and it loops back from 1

I have:
1. 2 digit seven segment display wich is common anode, here is the datasheet http://www.tme.eu/ro/Document/71648f1175f76e1e159746772133195f/LD-D036XX.pdf
2. 2x 74hc595 8 bit shift registers

I attached a picture of my wiring

my code is:

Code: [Select]
`/*B number order A - 3B - 9C - 8D - 6E - 7F - 4G - 1 DP - 2 */const byte ledCharSet[10] ={  B11000000,   B11111001,   B11111001,   B10110000,   B10011001,  B10010010,   B10000011,   B11111000,   B10000000,   B10011000};const int latchPin = 8;const int clockPin = 10;const int dataPin = 9;void setup(){  pinMode(latchPin, OUTPUT);  pinMode(clockPin, OUTPUT);  pinMode(dataPin, OUTPUT);}void loop() {  for (int i = 0; i < 100 ; i++) {    DisplayNumber(i);    delay(600);  }}void DisplayNumber(int num) {  int tens;  int ones;  if (num > 100 || num < 0) {    num = 0;  }  ones = num % 10;  if (num < 10) {    tens = 0;  }  else {    tens = num -(num/10)*10;  }  digitalWrite(latchPin, 0);  shiftOut(dataPin, clockPin, MSBFIRST, ledCharSet[ones]);  shiftOut(dataPin, clockPin, MSBFIRST, ledCharSet[tens]);  digitalWrite(latchPin, 1);    Serial.print(ones);  Serial.print("\n"); Serial.print(tens);  Serial.print("\n"); }`

Thank you!

#### Grumpy_Mike

#1
##### Oct 23, 2012, 05:55 pmLast Edit: Oct 23, 2012, 06:00 pm by Grumpy_Mike Reason: 1
You have a distinct lack of any current limiting resistors for the seven segment display. You also should have some decoupling capacitors on your chips:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

If the count is wrong then that is due to your software, did you write it yourself?

Put in some debug prints to see the value at various points in your code.

#### Arrch

#2
##### Oct 23, 2012, 05:59 pm
Code: [Select]
`tens = num -(num/10)*10;`
Let num be 51 for example:

51/10 = 5 (integer division)
5 * 10 = 50
51-50 = 1.

This should simply be
Code: [Select]
`tens = num/10;`

#### johnwasser

#3
##### Oct 23, 2012, 06:01 pm
Your code is written for two SEPARATE 7-segment displays, each driven by a separate shift register.  That two-digit display is a 2x8 matrix.  You have to drive it like a matrix.

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### crsunu

#4
##### Oct 23, 2012, 06:05 pm
no I didn't write it, I found it one some website..can't remember where...

I am new at arduino and electronics so any help is appreciated

Thanks for the help!

Your code is written for two SEPARATE 7-segment displays, each driven by a separate shift register.  That two-digit display is a 2x8 matrix.  You have to drive it like a matrix

can you help me with that?

#### Grumpy_Mike

#5
##### Oct 23, 2012, 06:14 pm
Quote
Your code is written for two SEPARATE 7-segment displays, each driven by a separate shift register.

Is it?
It doesn't look like that to me as there is only one data and clock line defined and the latch is clocked like two shift registers.

Why don't you follow the two bits of advice already given you. By help I assume you mean "do it for me", what we do here is help not do it for you.

#### Arrch

#6
##### Oct 23, 2012, 06:22 pm
One important thing to learn about coding is that if you try to write the entire project first, and then go back and troubleshoot it, you're going to have a bad time.

You should get small portions of the code working first, and gradually build up to the final project. This is where Mike's suggestion of using the Serial communication to debug comes in handy; it allows you to test variable code and verify it's result before trying to pipe those result into more code that could also potentially screw the values up.

#### crsunu

#7
##### Oct 23, 2012, 08:18 pm
I just wanted some help with this beacause I can't wrap my head around it. Now it counts 0 1 2 3...9 00 11 22 33 44

#### Arrch

#8
##### Oct 23, 2012, 08:19 pm

I just wanted some help with this beacause I can't wrap my head around it. Now it counts 0 1 2 3...9 00 11 22 33 44

And yet, no updated is code is posted.

#### dhenry

#9
##### Oct 23, 2012, 08:23 pm
Since you want to drive two digits with two 595, you can wire each 595 to each 7-segment display and drive them statically. That requires two separate 7-segment displays and it will greatly simplify programming for you - no more multiplexing.

#10
##### Oct 23, 2012, 08:39 pm
crsunu,
You need to wire it differently.
There are 2 common anodes, 1 for each digit.
There are 8 segment pins, shared between digits. These can come out of 1 shift register.
To get started, connect the 2 anode pins to arduino outputs.  You will have to rewrite the code to shift out the segment info, turn on 1 anode, wait 5mS, turn it off, change the segment info, turn on the 2nd anodem wait 5mS, turn it off, repeat. Your eyes will see them as both being on.
Since the anodes will be driven by arduino pins, you will have to limit the amount of current supplied, to <=5mA/segment, with a current limiting resistor per segment.
Assuming you have the UltraRed LEDs, the resistor should be (5V-1.9V)/.005 = 620 ohm. Use that or higher to avoid damaging the pins driving the anodes.

Code: [Select]
`void loop() {  for (int i = 0; i < 100 ; i++) {// move code here to split into 1, 10s// hang out for a bit to show the number:int x = 0;while (x<10000){// shrink void DisplayNumber to only show 1 digitturn off anode 2    DisplayNumber(ones);turn on anode 1    delay(5);turn off anode 1    Display(tens);turn on anode 2    delay(5);x=x+1;}  //    } // next number} // end loop`
Using the while (x<10000) is kind of kludgy.  Once you get the numbers working, visit Blink Without Display and use millis() to capture the time passing and turn the digits on/off based on elapsed time instead.
Make sense?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### crsunu

#11
##### Oct 23, 2012, 09:05 pm

crsunu,
You need to wire it differently.
There are 2 common anodes, 1 for each digit.
There are 8 segment pins, shared between digits. These can come out of 1 shift register.
To get started, connect the 2 anode pins to arduino outputs.  You will have to rewrite the code to shift out the segment info, turn on 1 anode, wait 5mS, turn it off, change the segment info, turn on the 2nd anodem wait 5mS, turn it off, repeat. Your eyes will see them as both being on.
Since the anodes will be driven by arduino pins, you will have to limit the amount of current supplied, to <=5mA/segment, with a current limiting resistor per segment.
Assuming you have the UltraRed LEDs, the resistor should be (5V-1.9V)/.005 = 620 ohm. Use that or higher to avoid damaging the pins driving the anodes

yes it makes perfect sense but I didn't want to use too many arduino outputs and thats why I used the two shift registers

#12
##### Oct 23, 2012, 09:17 pm

See page 6 - they're worse! Only rated for 6mA, with voltage dropping fast. Be hard to drive 8 segments on at time with any kind of brightness.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### creativen

#13
##### Oct 23, 2012, 09:54 pm
I have played with this IC 74HC595 and 4 7-segments, visit it here, it works!

http://zugiduino.wordpress.com/2012/07/11/how-to-drive-4-seven-segments-using-ic-74hc595/

Hope it helps!

#### crsunu

#14
##### Oct 24, 2012, 10:34 am
*bump

Go Up

Please enter a valid email to subscribe