Pages: 1 [2]   Go Down
Author Topic: 100 LEDs  (Read 2423 times)
0 Members and 1 Guest are viewing this topic.
Fairborn, Ohio
Offline Offline
Newbie
*
Karma: 0
Posts: 28
The only constant is change.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Fairborn, Ohio
Offline Offline
Newbie
*
Karma: 0
Posts: 28
The only constant is change.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
    }
  }
}
Logged

USA
Offline Offline
Sr. Member
****
Karma: 17
Posts: 390
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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}
Logged

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

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.


* LED chaser core_schem.jpg (115.52 KB, 1616x981 - viewed 19 times.)
« Last Edit: July 20, 2012, 07:17:36 pm by ThePsuedoMonkey » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

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


* LED chaser core2_schem.jpg (170.93 KB, 2513x1385 - viewed 19 times.)
« Last Edit: July 20, 2012, 10:00:52 pm by ThePsuedoMonkey » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: 1 [2]   Go Up
Jump to: