Pages: [1] 2   Go Down
Author Topic: Need help with 7-Segment Display  (Read 2274 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still learning stuff right now so bare with me.  I just wanted to know if I needed to add any resistor when I hook the digital display up to my arduino.  I have 8 anode which I figure would all go to a pin on the arduino and 2 cathode which would hook up to the ground pin.  Let me know if I'm doing it right so far.  Also don't know if this stuff will help since I have no idea how to read it:

Maximum ratings
Forward current:   30mA
Forward voltage:   2V
Reverse voltage:   5V
Power dissipation:   100mW

Typical characteristics
Forward current:   20mA
Forward voltae:    1.7V
Peak wavelength:  655nm

Thanks alot for explaining stuff.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do you have a picture of the display or a link to a website where you bought it from?

the device i used had 8 pins. 1 for each led and 1 common ground. I connected each led pin a digital out on the arduino and the ground to ground.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34527
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes you always need a resistor with an LED (unless you have a current controlled source which you don't). It should be between 150 and 470 ohms, the smaller the value the brighter it will be.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh yeah, im an idiot, forgot to mention the resistors!!

if you don't have any resistors available you can try connecting one of the segments to pin 13 and ground. pin 13 has a 1k pull up resistor which should be enough to get you a dim light going.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.radioshack.com/product/index.jsp?productId=2062557
thats what I have.
Can I connect it like this:

anode F to 13
anode G to 12
anode E to 11
anode D to 10
anode C to 9
anode RHDP to 8
anode B to 7
anode A to 6

then connect the two cathode to ground.  

Also where would I need the resistor at if it safe to connect it like that, and how would I figure out what size to use.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah you are going to need resistors in between the arduino digital out pins and the display.

you should be able to test one led though as 13 comes with an inbuilt resistor. connect it as so

13(arduino)----F(LED)-----ground(arduino).

then use the sample program for blink and it should blink the F LED
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need eight resistors, one for each segment and one for the decimal point.  A value around 220 Ohms is usually about right.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok thank you, I did try before just hooking up 3 of them to the pin and turn them on each by themself but wasn't sure if that was a good idea to do.  I will hook them all up to resistor this time before I continue on.  I will try to put my code on here later.
Logged

Flurieu Peninsula, South Aust.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For anyone who is new to electronics and wants to really get into it, the info here should be a big help.
http://www.rmcybernetics.com/science/cybernetics/electronics_volts_amps_watts.htm#ohmslaw

Don't know if that came out as an active link, but if you go to that site you can learn how to work out your own resistors and lots of other handy stuff.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my code.  I just made it count from 0 - 9.  My question is, is there an shorter way of doing this. This my first big code lol, so just took example from LED tutorial.

Code:

int ledPinF = 13;
int ledPinG = 12;
int ledPinE = 10;
int ledPinD = 9;
int ledPinA = 8;
int ledPinB = 7;
int ledPinRHDP = 6;
int ledPinC = 5;

void setup()                    
{
  // Set pins to output.
  pinMode(ledPinF, OUTPUT);
  pinMode(ledPinG, OUTPUT);
  pinMode(ledPinE, OUTPUT);
  pinMode(ledPinD, OUTPUT);
  pinMode(ledPinA, OUTPUT);
  pinMode(ledPinB, OUTPUT);
  pinMode(ledPinRHDP, OUTPUT);
  pinMode(ledPinC, OUTPUT);
}

void loop()                    
{
  
  digitalWrite(ledPinA, HIGH);         // Turn on 0
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, HIGH);
  digitalWrite(ledPinF, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);         // Turn off 0
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);
  digitalWrite(ledPinF, LOW);
  delay(100);
  digitalWrite(ledPinB, HIGH);         //Turn on 1
  digitalWrite(ledPinC, HIGH);  
  delay(1000);  
  digitalWrite(ledPinB, LOW);          // Turn off 1
  digitalWrite(ledPinC, LOW);
  delay(100);
  digitalWrite(ledPinA, HIGH);          // Turn on 2
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinE, HIGH);
  digitalWrite(ledPinD, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);          // Turn off 2
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinG, LOW);
  digitalWrite(ledPinE, LOW);
  digitalWrite(ledPinD, LOW);
  delay(100);
  digitalWrite(ledPinA, HIGH);        // Turn on 3
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);          // Turn off 3
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinG, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  delay(100);
  digitalWrite(ledPinF, HIGH);         // Turn on 4
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  delay(1000);
  digitalWrite(ledPinF, LOW);         // Turn off 4
  digitalWrite(ledPinG, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  delay(100);
  digitalWrite(ledPinA, HIGH);        // Turn on 5
  digitalWrite(ledPinF, HIGH);
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);        //  Turn off 5
  digitalWrite(ledPinF, LOW);
  digitalWrite(ledPinG, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  delay(100);
  digitalWrite(ledPinF, HIGH);        // Turn on 6
  digitalWrite(ledPinE, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinG, HIGH);
  delay(1000);
  digitalWrite(ledPinF, LOW);         // Turn off 6
  digitalWrite(ledPinE, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinG, LOW);
  delay(100);
  digitalWrite(ledPinA, HIGH);       // Turn on 7
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);        // Turn off 7
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  delay(100);
  digitalWrite(ledPinA, HIGH);      // Turn on 8
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  digitalWrite(ledPinD, HIGH);
  digitalWrite(ledPinE, HIGH);
  digitalWrite(ledPinF, HIGH);
  digitalWrite(ledPinG, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);        // Turn off 8
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);
  digitalWrite(ledPinF, LOW);
  digitalWrite(ledPinG, LOW);
  delay(100);
  digitalWrite(ledPinA, HIGH);       // Turn on 9
  digitalWrite(ledPinF, HIGH);
  digitalWrite(ledPinG, HIGH);
  digitalWrite(ledPinB, HIGH);
  digitalWrite(ledPinC, HIGH);
  delay(1000);
  digitalWrite(ledPinA, LOW);        // Turn off 9
  digitalWrite(ledPinF, LOW);
  digitalWrite(ledPinG, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  delay(100);
  
}

« Last Edit: January 15, 2009, 09:12:54 am by demonic_crow » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

rodmac thanks for that site.  That will come in handy for me while I'm learning.
« Last Edit: January 15, 2009, 09:19:42 am by demonic_crow » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@demonic_crew: code looks good. don't know what you will be doing with it, so I don't know how much reducing can be made.

One simple way to reduce your code could be to create one method to turn off all the leds off. Then you don't have to turn all the LEDs off indivisually each time. Something like this should work (not tested it yet):

Code:
void turnLEDoff(){
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);
  digitalWrite(ledPinF, LOW);
  digitalWrite(ledPinG, LOW);
  digitalWrite(ledPinRHDP, LOW);
}

Then instead off turning off all the pins as so:
Code:
...
  digitalWrite(ledPinA, LOW);         // Turn off 0
  digitalWrite(ledPinB, LOW);
  digitalWrite(ledPinC, LOW);
  digitalWrite(ledPinD, LOW);
  digitalWrite(ledPinE, LOW);
  digitalWrite(ledPinF, LOW);
...
just call the function as so:
Code:
turnLEDoff()
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

demonic_crow: bought my Arduino card last friday and tested to make the same thing as you. Have a 7-seg display to count. Totally useless but I came up with this code:

Code:
const int num_pins = 8;                 // the number of pins used
const int numPatterns=10;               // number of patterns to display
int timer = 1000;                       // time to next pattern
int pins[] = {2, 3, 4, 5, 6, 7, 8, 9};  // pins used, first one to segment A, second to segment B...

// define all different patterns (numbers) to display
int patterns[numPatterns][num_pins]=
{
  {1,1,1,1,1,1,0,0},
  {0,1,1,0,0,0,0,0},
  {1,1,0,1,1,0,1,0},
  {1,1,1,1,0,0,1,0},
  {0,1,1,0,0,1,1,0},
  {1,0,1,1,0,1,1,0},
  {1,0,1,1,1,1,1,0},
  {1,1,1,0,0,0,0,0},
  {1,1,1,1,1,1,1,0},
  {1,1,1,1,0,1,1,0},
};

void setup()
{
  int i;

  for (i = 0; i < num_pins; i++)   // the array elements are numbered from 0 to num_pins - 1
    pinMode(pins[i], OUTPUT);      // set each pin as an output
  
}

void loop()
{
  int i;
  int p;
  
  for (i = 0; i < numPatterns; i++) {  // loop through all patterns
    for (p = 0; p < num_pins; p++) {   // loop through the pin states for pattern
      if (patterns[i][p]==1)
      {
        digitalWrite(pins[p], HIGH);   // turning it on
      }
      else
      {
        digitalWrite(pins[p], LOW);    // turning it off
      }
    }
 
    delay(timer);                      // pausing

  }
}
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, see I don't understand how to get the 1,0 thing to work.  I know it seem like thats how you charlieplex also.  I will have to go over it when I get off of work.  Thanks for adding your own code here for me to look over.  Also if you have any tip how you learn to program that way could you point me in the right direction or give me a few tips.  Thanks alot
Logged

Flurieu Peninsula, South Aust.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still learning the code myself, but when I look at BD's code it makes sense to me. I think the fact that I understand how to use 7 seg. displays is the clue.
As I see it, each horizontal line of{1, 0, 1, 1......} controls which digit the display shows.   10 lines, 10 digits.
If you connect the arduino pins to the display pins  exactly
like it says in line 4 of the code I think your display should count up from  0 to 9 in a continuous cycle.
Hadn't heard of charlieplex (had to look it up) but don't think it applies here. Forget about it for now & make sure you understand all about the display, then the code might make sense.
Logged

Pages: [1] 2   Go Up
Jump to: