Arduino +Sparkfuns 4-digit 7-segment 16pin display

Thanks for the resistance / segment explanation.

I was using 1kOhms with 5V which explains I did not see the difference (I am lucky :slight_smile: )

Have a nice day.

Jérémy

Write up some code that switches a digit back and forth between "1" and "8". I think you will see a brightness difference. "1" will be brighter than "8".

brtech,
Thanks for answering Jeremytsl question about the resistor.

jeremytsl,
Wow, the wiring on that clock you have on your blog is so much more compact than my breadboard. Nice...

ninjamastr,
Your code for figuring out the value of each digit is much easier to understand than my power of ten array.

I think this is part of what makes the Arduino cool. There's a lot of sharing going on.

hari,
you're so right, the arduino community is amazingly helpful. Our projects could combine to form some sort of super voltron clock display robot.

brtech,
thanks for breaking this down for us. Your explanation makes sense and I will experiment with changing digits and observing brightness.

I don't fully understand the 2nd part of your explanation tho, please bare with me and my questions:

You all are driving the digits directly. That is okay as long as the resistor value is high enough. You need the current through the digit (which is the sum of the current through each segment) to be less than 40 ma).

How did you figure out this 40ma limit? The description on SF.com says "max forward current of 20mA"

If you used smaller series resistors on the segment drives, you would need to buffer the Arduino output with a transistor.

What would happen if you didn't, and your current on each digit exceeds 40ma? Would the LED's burn out?

if you were to use something else to drive the digits (shift register), that 40 ma may not work. Some shift registers can't sink 20 ma per segment either.

This part concerns me since I'm using a shift register (74HC595). What would you recommend I do? I've looked over the datasheet, but it makes little sense to me.

it says "+/- 6ma Output Drive at 5 V". Does that mean it's giving me 6ma per segment without any resistors?

Thanks in advance

40 ma is the max output of an Arduino pin, and you can't drive ALL of them at the same time at 40 ma.

If you go over it, you might burn out the microprocessor.

The 20 ma is the max current per segment i believe. if you lit 8 segments at 20 ma, the digit would need 160ma. Way more than the Arduino can supply. A cheap npn transistor could do that tho.

The datasheet is a bit weird, but yes, 6ma is what their typical output current is going to be. You can light a segment with that (not a digit), with the right value resistor, but the display won't be anywhere near as bright as it would closer to 20 ma per segment. With this device driving an LED, you can tolerate the output voltages getting a bit out of spec, so you might push that 6 ma a bit. 8ma probably works, maybe even 10.

But keep in mind that you will be driving all 8 segments from one 595. the max continuous current you can source/sink from the device is 70ma. 8 x 6 = 48, so you are okay there. Trying to run 8 x 10 ma wouldn't work. 8 x 8 is 64, pretty close to the limit.

Boy, do I have a lot to learn about electronics.

Thanks brtech for shedding some light on this stuff.

I picked up one of those (the blue ones) and i'm looking for a driver for it. I can't seem to find any decent digit multiplexing ICs for a CA display.

SAA1064 does pretty much everything I want it to (I2C, self multiplexing, small programing footprint, little processor overhead) but I don't figure I can get it working with that display (at least not for 4 unique digits).

I don't want to go with a BCD unless it'll output Hex as well (can't remember the proper name for them).

I figured out a decient solution using 4x 8 bit shift registers, a 4 bit (or and multiple of 4) an 8 channel mux, a few transistors and an oscillator.

Thus far, octopart has failed me in my search for a 7-segment 4 digit(+) driver w/ CA. Can I just use a chip made for CC and use some transistors?

I've used the STLED316S LED driver in several projects with good results. It's inexpensive and can drive up to 6 common anode digits plus 8 additional discrete LEDs with brightness control. It can also read from up to 16 tactile switches. I'm currently developing an alarm clock shield using this chip - I hope to post details soon. I've written a library for the chip I plan to share. It's only available in an SMT package but you could always put one on a breakout board if that's a problem.

Can anyone please help me get hari's code working with my 4 digit 7 segment display?

It is almost the same as sparkfun's except the pins are in a different configuration.

Here is the pin configuration:
1-8 on bottom (left to right)
9-16 on top (right to left)

Thanks!

bump

Pinout is not the only difference. Your display is common Cathode and my SparkFun display is common Anode. So basically wherever the code sets pin to HIGH it needs to set it LOW and vice versa. I only had to make 4 changes to the code and I've highlighted them yellow. That should work. Good luck!

/*
  WAS: Testing SparkFun's 4-digit 7-Segment Display (Blue)
  NOW: Altered for GmDude66 for H.LTC.4727
 */

int segmentA = 0; // Segments A thru P == pins 0 thru 7
int digit0 = 10; // Digits 3 thru 0 == pins 10 thru 13 (0 is LEFT most digit)

/*
[glow]Change#1 Added wiring guide for your H.LTC.4727[/glow]

W I R I N G   G U I D E

=== Common Cathode digits ===
Arduino  Display  Digit
  10        1       0 Leftmost
  11        2       1
  12        6       2
  13        8       3 Rightmost
  
=== Anode Segments ===
Arduino  Display   Segment
   0       14         A
   1       16         B
   2       13         C
   3       3          D
   4       5          E
   5       11         F
   6       15         G
*/

/*
10 digits:
 Each defines which segments should be on/off for that digit: A,B,C,D,E,F,G,P
 */
byte numbers[10] =
{
  B11000000, // 0
  B11111001, // 1
  B10100100, // 2
  B10110000, // 3
  B10011001, // 4
  B10010010, // 5
  B10000010, // 6
  B11111000, // 7
  B10000000, // 8
  B10010000  // 9
};

void setup()
{
  for (byte segment = 0; segment < 8; segment++)
    pinMode(segmentA+segment,OUTPUT);

  for (byte digit = 0; digit < 4; digit++)
    pinMode(digit0+digit,OUTPUT);
}

int perDigitTime = 100;
int digitPosition = 1;  // Start anywhere but zero so we won't crash when we try to turn off previous digit.
unsigned long previousMillis = 0;

int value = 0;
int powerOfTen[] = {
  1,10,100,1000};

void RefreshDisplay()
{
[glow]  //Change#2 (Your display is common Cathode, so to turn OFF a digit, we need to set it to +5)[/glow]
  digitalWrite(digit0 + digitPosition, [glow]HIGH[/glow]);  // Turn off previous digit

  digitPosition++;
  if (digitPosition > 3) digitPosition = 0;

  int digitValue = value % powerOfTen[ digitPosition+1 ] / powerOfTen[digitPosition];
  int number =  numbers[ digitValue ];
  
  if ((number > 0) || (value < powerOfTen[ digitPosition+1 ]))
  {
  for (byte seg = 0; seg < 8; seg++)
    digitalWrite(segmentA+seg, [glow]1 - [/glow]bitRead(number, seg) ); [glow]// Change#3 added "1-" to invert the bit for your common Cathode display[/glow]

  digitalWrite(digit0 + digitPosition, [glow]LOW[/glow]);  [glow]//Change#4 LOW will turn this digit on.[/glow]
  delay(4);
  }
}

void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > perDigitTime)
  {
    previousMillis = currentMillis;
    value++;
  }

  RefreshDisplay();
}

Thank you!

The display works perfectly now!

One more question: how would I go about getting the colon to stay lit all the time?

EDIT: Just combined your code along with ninjamastr's code to get this display working with my 74HC595

Thank you!
The display works perfectly now!

Awesome! Glad to be able to help.

One more question: how would I go about getting the colon to stay lit all the time?

I don't know. Sorry... :-[

drink 1oz of hot sauce, followed by 4 fingers of whiskey

I promise your colon will be lit up full time for quite a while :smiley:

zink0xide,

As others have mentioned, you can use practically any 8-bit serial-to-parallel 'sinking' driver IC or "constant current" sinking driver IC connected to the segments and five PNP or P-channel MOSFET 'sourcing' column drivers. The 74HC595 is a little "light duty" for this application but seems to hold up well. A better choice might be the TPIC6C595.

Here's an example of my MacMux? design for that Sparkfun display. I apologize for not yet having enough experience to back up the design with an Arduino software driver example but I could provide a C example for PIC if someone wants to take a stab at coding my method for Arduino.

The MacMux? design uses the PWM module with a period equal to the digit scan interval (1 to 2 msecs) to multiplex the column driver lines. When the PWM signal goes high (display "off") at the beginning of each digit scan interval the column driver lines are re-tasked for use as and lines to load the 74HC595 shift register. The column driver lines are then reset to the correct column select pattern (only one line low) before the PWM line goes back low (display "on"). Complete fade-to-black brightness control is a matter of setting the PWM duty cycle to some value between approximately 5% and 100% in the main program. PWM duty cycle is inversely proportional to display brightness with a 5% duty cycle = full brightness and a 100% duty cycle = black.

Regards, Mike

I was just wondering how to program the Arduino to make the 4 digit 7-segment display show a number that was arrived at in a different part of the program. I would be using the red display, so would it be different than Hari's post? I think I may have to use an Arduino Mega since I'm already taking up 8 digital pins with other things.

just a quick comment.
4 resistors are enough, and the 40ma is not a real issue (only 4 segments can be using the same current source, and with 10ma you can still get good brightness) if using the code from "Archives | Project Lab"
(mentioned by jeremytsl).
in this code the relevant segments are turned on individually, and stays on for a short delay, and then turned off. this also answers the question embedded in the code for why there is a need for a delay.
"delay(1); // Don't understand why I Have to set a delay
digitalWrite(groundPins[g], HIGH);"
also, if using the red 7-segment display, which is rated 2.1V and 20ma a 330 or 220 Ohm resistors are better.
if using a code that lights all the segments in a number at the same time - then the comments are accurate and segments should each have a resistor and 40ma Arduino pin output should be taken under consideration.
thanks everyone for your comments!

Hi all, my apology if this belong in a separate thread.

I just received this (YSD-439AK2B-35) from sparkfun and started playing with it. What I realize is that if I set this to input on HIGH, it uses lower voltage (1.74v). And I tested it out with 1k resistors, which is the smaller I have ATM, it will lid up but very dim (w/ 1k R).

I'm too chicken too remove the resistor, since its brand new... So what I want to know is, can I cut the cost down and save a few resistors this way?

The specs say Reverse voltage: VR=5V, 10µA and this is the code I used to test it.

void setup() {
  pinMode(13, INPUT);
  digitalWrite(13, HIGH);
  pinMode(2, OUTPUT);
}

void loop() {
  digitalWrite(2, LOW);  
  delay(1000);
  digitalWrite(2, HIGH);  
  delay(1000);
}

Thanks.

nm.... forgot about internal resistors on pin13...

Hi Hari,

i used your modified code for Common Cathode display, but the digit is inverted, i have the millisecond number on the left and the other number to the right.

Maybe the problem is your note //Digits 3 thru 0 == pins 10 thru 13 (0 is LEFT most digit)

i Think that the right is //Digit 0 thru 3 == pins 10 thru 13 but i don't know how change this in the sketch.

thanks for your attention


Posted by: hari Posted on: 26.03.2010 at 04:54:35
Pinout is not the only difference. Your display is common Cathode and my SparkFun display is common Anode. So basically wherever the code sets pin to HIGH it needs to set it LOW and vice versa. I only had to make 4 changes to the code and I've highlighted them yellow. That should work. Good luck!