Go Down

Topic: Arduino +Sparkfuns 4-digit 7-segment 16pin display (Read 27726 times) previous topic - next topic

cjands40

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.

GmDude66

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!


hari

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 [glow]yellow[/glow].  That should work.  Good luck!

Code: [Select]
/*
 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();
}



GmDude66

#19
Mar 27, 2010, 02:11 am Last Edit: Mar 27, 2010, 03:00 am by GmDude66 Reason: 1
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

hari

Quote
Thank you!
The display works perfectly now!

Awesome! Glad to be able to help.

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

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

Osgeld

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  :D
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Mike McLaren, K8LH

#22
Mar 27, 2010, 04:42 pm Last Edit: Mar 27, 2010, 07:19 pm by Mike-K8LH Reason: 1
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 <CLK> and <DAT> 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


guitarboy667

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.

alobar

#24
Jul 12, 2010, 06:02 pm Last Edit: Jul 12, 2010, 08:26 pm by alobar Reason: 1
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 "http://nootropicdesign.com/projectlab/2009/10/"
(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!


grehe

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.

Code: [Select]

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

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


Thanks.

grehe

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

Testato

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!
- [Guida] IDE - http://goo.gl/ln6glr
- [Lib] ST7032i LCD I2C - http://goo.gl/GNojT6
- [Lib] PCF8574+HD44780 LCD I2C - http://goo.gl/r7CstH

hari

Testato,
If I understand you correctly, it is probably simplest to adjust the wiring rather than the code.  Take a look at Arduino pins 10,11,12,13.  Those corresponds to the digits.
Say right now you have it wired like this:






ArduinoDisplay
10P
11Q
12R
13S


You have complete control as to which digit value correspond to which display digit.  What if you re-wire it like this?







ArduinoDisplay
13P
12Q
11R
10S


Good luck!

Testato

yes i know, it work, but i would understand wich is the way for correct the code, because is the code incorrect not the connection.

it is only for understand.

- [Guida] IDE - http://goo.gl/ln6glr
- [Lib] ST7032i LCD I2C - http://goo.gl/GNojT6
- [Lib] PCF8574+HD44780 LCD I2C - http://goo.gl/r7CstH

Go Up