7-Segment Display Wiring and Programming

Here is the data sheet for the 7-segment displays:
http://www.us.kingbright.com/images/catalog/SPEC/SA18-11EWA.pdf

Those LEDs take over 7.5V to drive - do you realise this? The common anodes will require a driver circuit each that takes logic levels up to the appropriate supply voltage (9V would be an obvious choice). LED displays compatible with 5V are much simpler to drive.

Okay, I may have two posts mixed up. But not totally. I had 6 LEDs strings & 18V supply on the mind from something else.

Did you look at the internal schematic for your part? The segments all have 3 LEDs in series. 5V from an arduino will not be enough to turn them on. You will need to apply a voltage of >6V to pins 1&5 for all the digits, then individually apply a logic low (close to 0V) to turn an individual segment on.

When a segment is not on, the bottom of the last LED will go up to whatever voltage you are suppying them with and blow up the output of the arduino or standard shift register if that is above 5V.

To turn the segments on, you will use the shiftout command with 1s & 0s.
The shiftout command looks like this
shiftOut(shiftdataout, serialclock, MSBFIRST, outdata);
where shiftdataout is the pin that data is coming from on the arduino.
serialclock is the clock line from the arduino,
MSBFIRST indidatces bit 7 goes first,
and outdata is the 8 bits you want sent out.

If for example your shift register bits were wired like this:
Output 0 = segment A
O1 = B
O2 = C
O3 = D
O4 = E
O5 = F
O6 = G
O7 = decimal point

Thus to send out a "1" character, you set outdata to
(bit # / segment -on/off)
0/a-off
1/b-on
2/c-on
3/d-off
4/e-off
5/f-off
6/g-off
7/dp-off

outdata would be set to 0b11111001 if you had a shift register that could handle >5V on its outputs, such as the tpic6b595. The 2 zero bits would result in low outputs for O2 & O3 to turn on segments B & C.
On the other hand, if you used a standard shift register and added transistors to its outputs to control the LEDs instead, such as the last schematic I posted (where I showed 6 LEDs instead of 3 by accident), then you would shift in 1's to turn on the transistors; outdata would be set to 0b00000110. The two 1 bits would turn on the 2 transistors for segments B & C and turn them on.

You will need 1 shift register per digit. The >6V supply will go to pins 1&5 on all the digits.

Another option is to put a part like an 74LS47 in there, which can work with up to 15V.
A shift register could supply 4 bits to each of two 74LS47s. The '47s will decode the 4 bits into 15 characters (plus a blank state), so you coud just shift out a "1" and it will show up as 1, "2" for a 2, etc. and hex "f" to blank the display. However, you are stuck with the decode that is built in. If you wanted characters that looked like some letters (E, h, P, n, L, A, J, C or c, etc.) you're better off with the shift register so you have more control.

But I'd need to use the serial outputs one per digit if I used shift registers right?

  1. You could shift out to each shift register individually (have the data line and the clock line common to all parts, with unique load or enable lines). Takes 10 arduino output lines.
  2. You could have the data shift thru all the parts (output becomes the input to the next) and then shift out the 64 bits of data for all of them every time. Uses less pins that way. Takes 3 output arduino lines.
  3. Another option is to use a MAX7221, which combines both these approaches - it has additional logic so that you are only shifting out to 1 part (uses the SPI format, ties up 4 specific output pins, D10-11-12-13). The registers are individually addressable (you shift out an address and then the data for that address). However, it won't do 6-7.5v outputs.
    You would have to add two sets of transistors - one set to switch on the 7.5V to each digit's common anode, and one set to switch the common segments lines to ground.
    See Figures 1 & 4 in this application note:
    Mixed-signal and digital signal processing ICs | Analog Devices

So an output line would be a pin? If I don't need to use the serial pins for this then I don't mind taking a lot of output pins since I'm using an Arduino Mega. 10 pins would be fine, but if you need to use a serial pin to send data to the shift register then I don't believe there is enough on the Arduino Mega.

Thanks a ton for your help btw!

You will not be using the Serial Rx/Tx lines, just regular I/O lines.
Define a pin as the common data output line.
Define a pins as the common shift clock line.
Define 8 pins as the unique Strobe, or Load, or whatever it is called for the 595 variant that you are using.

Glad to help. Talking others thru these helps me get things clear in my mind for my designs as well. I don't have any shift registers handy, so I am wiring up a 74F374 as shift registers, which also comes in handy for driving (single) LEDS per output (with current limit resister) directly.

So would 4 AA or similar batteries in series be a suitable power source? I saw the voltage is typically 6 volts per segment.

That would have a ~3 A current? So then a resistor of roughly 2 Ohm? That can't be right.

So then I have a wire going from each of the segments to the shift register (which pins of the register?). I have one wire going from the Arduino to the shift register. I have a common ground that would connect to the battery, the 7 segment, and the Arduino. Could I get away with a resistor only between the battery and the 7-segment display? Is that how it is connected?

4 AAs would probably be marginal, as soon as they dropped a little you'd be out of voltage. 5 would be okay. You could power the arduino from batteries 1-3 (4.5V into VCC, not Vin), and the segments from batteries 1-5 (7.5v). I have used 3 AAs like this, the arduino was still going well at 4.25V.
So if you had 5 batteries, thats 7.5V, less say 6.5V for a segment, that's 1V across the resistor and transistor of the shift register, so you'd see maybe 0.5V across the resister.
So with ohms law, V=IR, V/I = R => 0.5V/0.02A = 25 ohms. 27 or 33 are standard values.
You need a resister per segment of each LED if you are using shift registers. More below on why 1 resister per segment.
If you had all segments on in 1 digit, that would be 140mA.
How many digits were you planning on? I don't recall.

You have 3 wires going from the arduino to the shft registers, assuming you have the output of one shift register feeding the input of the next. The shift_out_clock goes to each part. The shift_data_out goes to part1, its output goes to part 2, etc.
To prevent a bunch of flickering while all this shifting is going on, you also have a load_data line that moves the data from the input shift register to the output drive pin so all the displays update at once. Then you shiftout bytes until all digits are shifted, and toggle the load line to update the outputs.
The other option is to use more wires, and shift to each digit individually.
Have a common shift_data_out, shift_clock, but individual load_data to each part for the actual output update.

Wire up your shift register - which one are you using? tpic6b595 open drain shift register, which can take higher output voltages (the voltage will go up to the battery voltage when the pin is high)? Or a standard TTL/CMOS part, in which case you will need an NPN transistor like I showed in an earlier post.
Select the mapping you want to use, maybe this:
bit 7 = decimal point
bit 6 = segment G
bit 5 = F
bit 4 = E
bit 3 = D
bit 2 = C
bit 1 = B
bit 0 = segment A
Then to turn on a segment, a bit = LOW will equal a segment turned on for the tpic6b595,
or if the shift register drives a transisor as shown earlier, a bit = HIGH will equal a segment turned on.
Lets go with HIGHs:
for #1, data out for a shift register would be 0B00000110 for segments B & C
for #0, 0B00111111 for segments A,B,C,D,E,F
for #7, 0B00000111 for segments A,B,C and so on.
for L, 0B00111000 for segments D,E,F, and so on.

You have 7.5V going to the common ANODE of each digit, the segments go thru resistors to the shift register, the battery- goes to the arduino ground.
You could try just 1 resister between the 7.5V and the ANODE of each digit, but you will find the segments changing brightness as the different segments turn on & off. 1 or 2 segments vs 5,6,7 segments all sharing the same 20mA, you see? And you have to limit for the least amount of segments on so you don't burn it out.

I will be using 8 digits. There will be two different 4-digit numbers, so essentially two different displays, so I think it'd be easier as far as programming is concerned to wire those two separately?

I have the 9 volt pack thing for the Arduino.

So I think I follow all that. I may just wire each individually, but idk which would be easier to code. I have a keypad that the user inputs numbers on and I want to display the user's input on the display one number at a time, so they know that their input has been registered. I also need to simply display 4 digit numbers arrived at in different parts of the code as well. Whichever wiring would work best for that would be good.

At this point I supposed I'll just need to translate the input and calculated digits into outputs for the display. With the user input I could have several if then statements that say, for example, if button "1" is pressed then output
for #1, data out for a shift register would be 1B11111001 for segments B & C, but that seems a little sloppy.

Then the other portion will be converting say 3097 into data to be sent to the shift register.

I was planning on using the tpic6b595 open drain shift register you suggested.

"9 volt pack thing" what is that? The 9V wallwart?

With the mega, you have plenty of IO, you can have separate control pins for each shift register.

Take a look at this code. I totally do not get how the first highlighted part sets up the shift register for the second highlighted part to display digits, but am told it works.

unsigned long currentmillis = 0;
unsigned long previousmillis = 0;
unsigned long interval = 10;

int latchpin = 8; // connect to pin 12 on the 74HC595
int clockpin = 12; // connect to pin 11 on the 74HC595
int datapin = 11; // connect to pin 14 on the 74HC595

int ones_seconds = 0;
int tens_seconds = 0;
int ones_minutes = 0;
int tens_minutes = 0;
int tenths = 0;
int hundredths= 0;

[glow]int segdisp[10] = {
  63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers
//The above numbers light up different segments of a digit[/glow]
int time_update = 0;// added new flag
void setup()
{
  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);
}

void loop()
{
  currentmillis = millis();  // read the time.
  if (currentmillis - previousmillis >= interval) // 10 milliseconds have gone by
  {
    previousmillis  = currentmillis;  // save the time for the next comparison

    time_update = 1;  
  }  // set flag to upate & shift out

  if (time_update == 1){  // no updating if not at 10ms interval, skip this whole section
    // increment the counters, roll as needed, shift the digits out
    time_update = 0; // reset for next pass thru

    hundredths = hundredths +1;
    if (hundredths == 10){
      hundredths = 0;
      tenths = tenths +1;
    }

    if (tenths == 10){
      tenths = 0;
      ones_seconds = ones_seconds +1;
    }

    if (ones_seconds == 10){
      ones_seconds = 0;
      tens_seconds = tens_seconds +1;
    }

    if (tens_seconds == 6){
      tens_seconds = 0;
      ones_minutes = ones_minutes +1;
    }

    if (ones_minutes == 10){
      ones_minutes = 0;
      tens_minutes = tens_minutes +1;
    }
    if (tens_minutes == 10){
      tens_minutes = 0;
    }

[glow]    // counters are all updated now, just do the shiftout one time here:
    digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the % first "hundredths" digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]); // print the tens of hundredths digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the % first "seconds" digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the tens of seconds digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the % first "minute" digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the tens of minutes digit
    digitalWrite(latchpin, HIGH);[/glow]
  } // end if time to be updated

} // end void loop

Is this the shift register you recommend?

Yes - altho you can find it less expensively if you look around.
Example,
http://parts.digikey.com/1/parts/527098-ic-pwr-8-bit-shift-regis-20-dip-tpic6b595n.html

Alright, so I think I understand the wiring. I just want to tackle this stage before I start code.

So is the 1 pin of the 7-segment display the positive and the 5 the negative or vice versa?

Or are both positive? I think it's that, right?

So then the wiring for the rest of the 7-segment is, for example,
DRAIN0 (on shift register)-33 OHM Resistor-Pin 7 on 7-segment display

(The batteries I'm using actually are 1,500 mAh)

I have a common ground to the shift register (just to one of the GND pins, right?), battery pack, and Arduino.

So the SER IN is the shift_data_out line and SER OUT goes to the next SER IN.

I assume that the pins of the Arduino for the shift_data_out line, shift_out_clock line, and the load_data line don't matter?

I think I'm just a bit confused about those 3 lines in general.

I believe I understand the shift_data_out line.

What pins on the shift register does the shift_out_clock line and load_data line go to?

Answers mixed in below:

So is the 1 pin of the 7-segment display the positive and the 5 the negative or vice versa?
Or are both positive? I think it's that, right?

Both pins 1 & 5 go to the positive of the supply. They are internally connected on the device.

So then the wiring for the rest of the 7-segment is, for example,
DRAIN0 (on shift register)-33 OHM Resistor-Pin 7 on 7-segment display

Yes.

(The batteries I'm using actually are 1,500 mAh)

If you have all 7 segments of a digit on, that's 7 x 20mA = 140mA, I don't remember how many digits you have altogether. 4? Then if you all 4 displaying "8888" you can expext to draw 560mA, you will get maybe 3 hours of life form 1500mA batteries. Most likely longer as you will have fewer segments on at any one time.

I have a common ground to the shift register (just to one of the GND pins, right?), battery pack, and Arduino.

Connect all 3 grounds from the shift register.

So the SER IN is the shift_data_out line and SER OUT goes to the next SER IN.

Yes.

I assume that the pins of the Arduino for the shift_data_out line, shift_out_clock line, and the load_data line don't matter?

Correct.

I think I'm just a bit confused about those 3 lines in general.

I believe I understand the shift_data_out line.

What pins on the shift register does the shift_out_clock line and load_data line go to?

shift_out_clock goes to SRCK
load_data goes to RCK
Low on SRCLR will clear the input register, tie it high if not used.
Low on G will enable the output transistors so 0s & 1s will show up on your display. With G high, no outputs will turn on.

I finished the wiring, but I'm not getting any response to the code. I imagine the other code is only for that shift register mentioned and I'll need to do a lot more work to get this one running.

I currently only have one display connected. I wanted to make sure this way works before I made more.

Post your code and a schematic of what you have so far, I'm sure we can get you going.

Wait, do I need to connect the positive of the battery power to Vcc?

Basically this is the idea, plug your parts in the correct places.
You may not need the diode to drop the voltage a little to the shift register, the recommended operating voltage is 5.5, absolute max is 7, so you may be okay with just the 4 batteries as the 1.5V/battery will drop some as they are used.

So I can not use SRCLR by tying it high meaning connecting it to 5V? And I don't have to do anything with G?

I just connected Vcc to the Arduino's 5V.