3
\$\begingroup\$

I'm trying to get a CPS03631BR 3 digit 7 segments LEDs to work. I've wired it to my Arduino UNO like this:

Wiring

And I'm using this code, which should light all the LEDs digit-by-digit, then light everything:

// Diagram: http://search.alkon.net/cgi-bin/pdf.pl?pdfname=13600.pdf
const int digit[] = { 9, 10, 11 };
const int led[]   = { 2, 3, 4, 5, 6, 7, 8, 12 };
                  //  a  b  c  d  e  f  g  dp

void setup() {
  for (int i = 0; i < 3; i++) {
    pinMode(digit[i], OUTPUT);
  }

  for (int i = 0; i < 8; i++) {
    pinMode(led[i], OUTPUT);
  }
}

void lights_off() {
  for (int i = 0; i < 3; i++) {
    digitalWrite(digit[i], LOW);
  }

  for (int j = 0; j < 8; j++) {
    digitalWrite(led[j], HIGH);
  }
}

void light_digit(int number) {
  switch (number) {
    case 0:
      digitalWrite(digit[0], HIGH);
      digitalWrite(digit[1], LOW);
      digitalWrite(digit[2], LOW);
      break;
    case 1:
      digitalWrite(digit[0], LOW);
      digitalWrite(digit[1], HIGH);
      digitalWrite(digit[2], LOW);
      break;
    case 2:
      digitalWrite(digit[0], LOW);
      digitalWrite(digit[1], LOW);
      digitalWrite(digit[2], HIGH);
      break;
  }
}

void light_num(int number) {
  switch (number) {
    case 0:
      digitalWrite(led[0], LOW);
      digitalWrite(led[1], LOW);
      digitalWrite(led[2], LOW);
      digitalWrite(led[3], LOW);
      digitalWrite(led[4], LOW);
      digitalWrite(led[5], LOW);
      digitalWrite(led[6], HIGH);
      digitalWrite(led[7], HIGH);
      break;
    case 1:
      digitalWrite(led[0], HIGH);
      digitalWrite(led[1], LOW);
      digitalWrite(led[2], LOW);
      digitalWrite(led[3], HIGH);
      digitalWrite(led[4], HIGH);
      digitalWrite(led[5], HIGH);
      digitalWrite(led[6], HIGH);
      digitalWrite(led[7], HIGH);
      break;
    case 2:
      digitalWrite(led[0], HIGH);
      digitalWrite(led[1], HIGH);
      digitalWrite(led[2], HIGH);
      digitalWrite(led[3], HIGH);
      digitalWrite(led[4], HIGH);
      digitalWrite(led[5], HIGH);
      digitalWrite(led[6], HIGH);
      digitalWrite(led[7], HIGH);
      break;
  }
}

void loop() {
  digitalWrite(led[0], LOW);
  digitalWrite(led[1], LOW);
  digitalWrite(led[2], LOW);
  digitalWrite(led[3], LOW);
  digitalWrite(led[4], LOW);
  digitalWrite(led[5], LOW);
  digitalWrite(led[6], LOW);
  digitalWrite(led[7], LOW);

  digitalWrite(digit[0], HIGH);
  digitalWrite(digit[1], LOW);
  digitalWrite(digit[2], LOW);
  delay(500);
  digitalWrite(digit[0], LOW);
  digitalWrite(digit[1], HIGH);
  digitalWrite(digit[2], LOW);
  delay(500);
  digitalWrite(digit[0], LOW);
  digitalWrite(digit[1], LOW);
  digitalWrite(digit[2], HIGH);
  delay(500);
  digitalWrite(digit[0], HIGH);
  digitalWrite(digit[1], HIGH);
  digitalWrite(digit[2], HIGH);
  delay(500);
}

But instead what I'm getting is this:

http://www.youtube.com/watch?v=cOB-JGoO-fg

When it should be lighting all the digit it's doing a 9 with a dot. When it reaches the third digit nothing happens. When all the LEDs should be ON it's displaying 33 and the third digit is completely OFF. I've tested each LED individually and they all work.

Any ideas?

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Where are your current-limiting resistors? Each segment pin should have a series resistor of at least 150 ohms in order to limit the current to 20 mA @ Vf = 2.0V. As it is, you are seriously overloading the Arduino outputs and over-driving the display. \$\endgroup\$
    – Dave Tweed
    Dec 16 '12 at 13:43
  • 1
    \$\begingroup\$ After adding the current limiting resistors, I would seriously look into cleaning up the wiring diagram. Part of the power of using a microcontroller is that you can use any pin to drive any LED. Get rid of all those crossovers in the wiring and change the 2nd and 3rd line in your code instead. \$\endgroup\$
    – jippie
    Dec 16 '12 at 14:20
1
\$\begingroup\$

The wiring on your schematic only agrees with the datasheet up to pin 5.

Then the datasheet implies Pin 6 is missing or disconnected and the remaining pins 7-12 are connected. Also DIP pins are conventionally numbered down one side and up the other. So your pin numbered 6 is probably Pin 12 on the LED, 7 is probably 11, and so on until your pin 11 is the datasheet pin 7.

This will be easy to confirm with a multimeter. Once confirmed, it is fixable in software.

Dave Tweed is right about the current limiting; unless you have simply omitted the resistors on the drawing to simplify it. You need 8, probably 330R, on the anodes. (3 resistors on the cathodes would vary the brightness according to the display data!)

\$\endgroup\$
2
  • \$\begingroup\$ Thanks very much. I'm not very experienced in electronics so I didn't knew about the inverted pin numbering. Thanks again. \$\endgroup\$ Dec 16 '12 at 15:02
  • \$\begingroup\$ @NathanCampos: I'm just curious ... Wasn't this obvious when you "tested each LED individually"? \$\endgroup\$
    – Dave Tweed
    Dec 16 '12 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.