Go Down

Topic: Minimalist Approach to 2 Digit 7 Segment (Read 6048 times) previous topic - next topic

SteveMcQuenn

Hey all -

I want to count down using two 7 segment displays, like 20, 19, 18, 17...to 00, and then reset to 20 when I push a button.
I've been searching these forums and the internet for some good examples of doing this with the Arduino using the fewest pins possible. But most are the 4 digit variety and I don't know if that solution would be the same or if because I am using just 2 digits there is an even easier approach.

There seems to be a 1000 ways to do this, but because I am still rather new to this I don't know which approach would be best (use fewest pins possible, take up as little memory as possible).

Any general pointers?

Thanks!

CrossRoads

Got 14 spare pins? Drive the 14 segments directly.
Otherwise, get 2 shift registers and let them drive the segments directly. Just need 3 pins.
Or 2, if you don't mind having the segments change (flicker) as you send data out.
Even saw a setup where the data pin was fed thru a capacitor from the clock pin, and with timing one could clock in a zero or 1.

I prefer sending data to shift registers via SPI.transfer() myself.
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.

nickgammon

I drove a 4-segment display directly from the processor (like Crossroads suggested) using this circuit:



For two segments just omit the wires running to D3 and D4 (digits 3 and 4).

The code multiplexed the appropriate pins. More details here:

http://www.gammon.com.au/forum/?id=11165
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

graynomad

The Sparkfun 4-digit module goes one better, they've dropped the current-limiting resistors. :smiley-eek:

Dodgy and gives uneven digits but it works as long as your MUXing doesn't stop.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

nickgammon

Well I have a cunning plan ...

I am going to try to wire up a 4-digit display with 2 x 74HC595 (one on each side) in such a way that one is turned around 180 degrees. The idea is that one shift register will power the 6 pins on one side of the display, and the other register power the 6 pins on the other side. Basically without wires, because the tracks on the protoboard (or whatever it is called) will make the connections.

With carefully-designed timers and interrupts you should be able to drive it with minimal effort.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

This is the basic concept, but it's just in the planning stage right now:



There won't be any wires required, apart from the ones to connect the clock and overflow pins from one chip to the next.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

graynomad

You're right, that's a very cunning plan. Look Ma, no wires.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

CrossRoads

No need for interrupts - use SPI to write to two shift registers with 2 SPI.transfers.
Cycle thru the 28 combinations to drive 1 segment at a time:
1-a,1-b,1-c,1-d,1-e,1-f,1-6
2-a,2-b,2-c,2-d,2-e,2-f,2-g
3-a,3-b,3-c,3-d,3-e,3-f,3-g
4-a,4-b,4-c,4-d,4-e,4-f,4-g

I could see it as a for:next loop within a for:next loop, pins & value to be displayed pulled from an array.
Code: [Select]

for (digit = 1 to 4){
 for (segment = 1 to 7){
   digitalWrite (SS, LOW)
   SPI.transfer( digitArray[digit]);
  SPI.transfer(segmentArray[segment]);
digitalWrite (SS, HIGH);
 }  // next segment
}  // next digit

Hmm, digitArray[] can just be {B00000001, B00000010, B00000100, B00001000}
while segmentArray[] would have to reflect the actual number to be displayed, likely stored in another array
= {a[0],a[1], a[2], a[3], a[4], a[5], a[6],  b[0], b[1],b[2],b[3],b[4],b[5],b[6],c[0],c[1],c[2],c[3],c[4],c[5],c[6],d[0],d[1],d[3],d[4],d[5],d[6]}

then when you wanted to change the display, you'd all a function (might actually have to breakdown & write one!) to change the indivual segment values:

case digit(0):
a[0] = 0; // a, where 0123456 represents segments abcdefg, low = on
a[1]= 0; // b
a[2] = 0; // c
a[3] = 0; // d
a[4] = 0; // e
a[5] = 0; // f
a[6] = 1; // g
// repeat for 1,2,3,4,5,6,7,8,9
// and somehow pass in digit info too
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.

nickgammon

Agreed, in principle. I'm just worried that without interrupts if you got "stuck" somewhere, maybe waiting for someone to let go of a button, all the LEDs would burn out.

But with some sort of timer interrupt the LEDs could be cycled no matter what else the program was doing. I'm trying to do without resistors you see. And also not have to desolder my LEDs because I burn them out. ;)
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

CrossRoads

Just need 4 resistors tho,  on the 4 "digit" lines. Put 'em on sockets, live dangerously & short them out after you get your multiplexig going.
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.

Antzy

For the original question, SteveMcQuenn can check out these links:
http://extremeelectronics.co.in/avr-tutorials/multiplexed-seven-segment-displays/
http://extremeelectronics.co.in/avr-tutorials/multiplexed-seven-segment-displays-part-ii/

massib80

I was looking into this myself because I cannot find shift registers here in Cork (damn Ireland!)

I wonder if the transistor are truly needed.

I was thinking of a minimalistic setup were I turn on and off the 2 digits connecting the common anode to 2 digital I/O and then alternate them on and off.

Basically, I will ground the segment of the two digit on the very same wires, and then I will ground the needed pin for digit 1 and turn to HIGH the I/O connected to the CA of the 1st digit, then turn it off and turn ON the second I/O and ground the needed pins.

Do you think this can work or I will have lot of flickering?

nickgammon

On the circuit further up the page I did just that, without transistors. It doesn't flicker if you do it reasonably quickly.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Antzy

but doesnt that circuit use avr pins for powering the 7 segments? if u light up all segments (to show 8), wont they burn out the pins?

nickgammon

There are resistors on the cathodes. If you only have two segments you only need two resistors.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up