Go Down

Topic: 100 LEDs (Read 2711 times) previous topic - next topic

MasterErik

Ok, dig this, by why do they go out of order on my breadboard? I wired just 20leds to 5pins. It blinks: 1 2 9 10 15 16 19 20 3 4 11 12 17 18 5 6 13 14 7 8

And how do I address them individually??




I think it would indeed be easy to code.  I believe that this will sequentially light 96 LEDs, using Arduino pins 2 through 12:
Code: [Select]
void setup() {
  for (uint8_t i=2;i<=12;i++) {
    pinMode(i,INPUT);
    digitalWrite(i,LOW);
  }
}

void loop() {
  uint8_t n = 0;
  for (uint8_t i=2;i<=12;i++) {
    pinMode(i,OUTPUT);
    for (uint8_t j=i+1;j<=12;j++) {
      pinMode(j,OUTPUT);
      digitalWrite(i,HIGH);
      delay(5000);
      n++;
      digitalWrite(i,LOW);
      digitalWrite(j,HIGH);
      delay(5000);
      digitalWrite(j,LOW);
      n++;
      pinMode(j,INPUT);
      if (n == 96) {
        break;
      }
    }
    pinMode(i,INPUT);
    if (n == 96) {
      break;
    }
  }
}


I've run this code on my Uno, and tested its operation by examining the data and direction registers for ports B and D for each virtual LED, in place of the delay function shown in this code.  It looks like there's always only one LED on, and it's the one that I expect.  So, I'd say that for this code, my confidence is high.

Getting the code this simple requires the LEDs to be wired in a conceptually natural way.  Wiring it, though, would be a beast of a job.

I've fiddled with finding an LED arrangement that simplifies the wiring at the expense of code complexity.  After all, at the worst I'd have to create an array of output patterns, and index it sequentially.  But I haven't found any method that's particularly satisfying.  I'd very much like to see others' experience and thoughts on wiring arrangements for charlieplexed LEDs.

MasterErik

I used:

void setup() {
  for (uint8_t i=2;i<=6;i++) {
    pinMode(i,INPUT);
    digitalWrite(i,LOW);
  }
}

void loop() {
  uint8_t n = 0;
  for (uint8_t i=2;i<=6;i++) {
    pinMode(i,OUTPUT);
    for (uint8_t j=i+1;j<=6;j++) {
      pinMode(j,OUTPUT);
      digitalWrite(i,HIGH);
      delay(500);
      n++;
      digitalWrite(i,LOW);
      digitalWrite(j,HIGH);
      delay(500);
      digitalWrite(j,LOW);
      n++;
      pinMode(j,INPUT);
      if (n == 20) {
        break;
      }
    }
    pinMode(i,INPUT);
    if (n == 20) {
      break;
    }
  }
}

tmd3

You have them wired like this:
  ---2---    ---3---    ---4---    ---5---    ---2---    ---3---    ---4---    ---2---    ---3---    ---2---   PIN#
  --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\
   1    2     3    4     5    6     7    8     9   10    11   12    13   14    15   16    17   18    19   20   LED#
  \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --
  ---3---    ---4---    ---5---    ---6---    ---4---    ---5---    ---6---    ---5---    ---6---    ---6---   PIN#
That looks a lot like the schamtic previously posted in this thread. And, that's a handy way of making a schematic, but it's certainly not the only way to wire the LEDs.  When you charlieplex, you have to match your code to your wiring.

Here's the arrangement that I had in mind:
  ---2---    ---2---    ---2---    ---2---    ---3---    ---3---    ---3---    ---4---    ---4---    ---5---   PIN#
  --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\    --   /\
   1    2     3    4     5    6     7    8     9   10    11   12    13   14    15   16    17   18    19   20   LED#
  \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --    \/   --
  ---3---    ---4---    ---5---    ---6---    ---4---    ---5---    ---6---    ---5---    ---6---    ---6---   PIN#
Notice that it looks a lot like the code:  the upper pins are the slowly-varying index, and the lower pins are the rapidly-varying index.

There's a straightforward solution that doesn't involve rewiring.  Define an array, NLEDS x 2, that holds the LOW pin and the HIGH pin for each pair of LEDs.  To light one, get its pins, and manipulate the outputs to light it up.  A code snippet might be:
Code: [Select]
  for (uint8_t i=2;i<=NLEDS;i++) {
    pinMode(LEDArray[i][0],OUTPUT);
    pinMode(LEDArray[i][1],OUTPUT);
    digitalWrite(LEDArray[i][0],HIGH);
    delay(<something>);
    digitalWrite(LEDArray[i][0],LOW);
    digitalWrite(LEDArray[i][1],HIGH);
    delay(<something>);
    pinMode(LEDArray[i][0],INPUT);
    pinMode(LEDArray[i][1],INPUT);
  ... 
If you don't get the array right the first time, trial and error will get the answer.  For your wiring, this might be the array:
{2,3},{3,4},{4,5},{5,6},{2,4},{3,5},{4,6},{2,5},{3,6},{2,6}

#18
Jul 21, 2012, 02:09 am Last Edit: Jul 21, 2012, 02:17 am by ThePsuedoMonkey Reason: 1
Attached is an example of using a decade counter/divider chip for the basic principle.  All you need is to scale it up for your number of LEDs and create a timer circuit for your desired timing.  In this example, each LED is lit sequentially and the next one lights when the switch cycles (off-on-off).  All of the components necessary for this method can be found for ~$6 on ebay, no controller necessary.

CrossRoads

You sure about that part?
http://www.ti.com/lit/ds/symlink/cd4017b.pdf
According to the datasheet, it's only good for a couple of mA output current, could struggle turning on an LED.
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.

#20
Jul 21, 2012, 04:07 am Last Edit: Jul 21, 2012, 05:00 am by ThePsuedoMonkey Reason: 1
Hmm, I missed that.  It looks like it was meant to be driven by 10-15 volts, so that would make sense.  You could always tie the signal into an NPN transistor to source power (similar to a Darlington Pair), but you'd need one for each LED.  I only paid $2 for a pack of 100 BC546's, which can give 100mA, but that does increase the total cost and complexity by a fair amount.  I guess the CD4017BE may not be the best IC for this, but I still think that a microprocessor would be overkill and too costly for this.
Edit: updated schematic

CrossRoads

"a microprocessor would be overkill and too costly for this."
Well, a '328P is just $2.50
http://www.mouser.com/ProductDetail/Atmel/ATMEGA328P-PU/?qs=K8BHR703ZXhdUS2n3IW%2fRITwfrPGjO%2fc
If the internal oscillator is used, then only a 10K pullup and the current limit resistors are needed.
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.

Go Up