Pages: [1] 2   Go Down
Author Topic: help with - 2 digit 7 segment display and 2 74hc595  (Read 4508 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
B number order
 
A - 3
B - 9
C - 8
D - 6
E - 7
F - 4
G - 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");
}


Can anyone please help me with this issue?

Thank you!


* 7seg.png (98.68 KB, 1244x868 - viewed 330 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33991
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 23, 2012, 11:00:05 am by Grumpy_Mike » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
tens = num/10;
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33991
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3379
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26969
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 digit
turn 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?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks for the reply
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26969
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.ti.com/lit/ds/symlink/sn74hc595.pdf

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

universe
Offline Offline
Sr. Member
****
Karma: 0
Posts: 258
I'm enjoying my Life
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have played with this IC 74HC595 and 4 7-segments, visit it here, it works! smiley-mr-green

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

Hope it helps!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

*bump
Logged

Pages: [1] 2   Go Up
Jump to: