10 LED Charlieplexing Circuit Troubleshooting

So i just started playing with the arduino and this is one of my first projects. I got a 10-led Progressbar Indicator from radioshaq the other day. I was going to wire up each led individually, but Hack-A-Day had a very timely article (link on next post) on charlieplexing. So I figured I'd try my hand at it.

Unfortunately, I must not have as strong a grasp of the wiring as I thought. I can theoretically drive 12 LEDs off only 4 pins and below is a schematic of my charlieplexed circuit.

When I run my code (I will post later if the circuit doesnt have any problems), I can light up only the first 5 LEDs. Can anyone tell if my wiring logic is incorrect?

Thanks in advance.

Image in next post.

It looks OK to me; an interesting way of drawing the circuit!
Need to see the code...

Maybe your code already deals with this, but I think with charlieplexing, you can only drive a fraction of the LEDs at any given time. Each pair of outputs has two LEDs, only one of which will have the high-to-low relationship necessary to light. To make both LEDs on the same pair of outputs appear to be lit at the same time, you have to alternate the outputs every few milliseconds.

Alright, I never commented this (im adding a few comments now), so let me explain my intent for this code as its just rigged to test the circuit. I have a pot hooked up to an analog pin and that is being mapped to 0-9 and that value is being dumped to the serial console. Only one led is to be lit at a time depending on the selection on the potentiometer during setup. the value can be changed, then when the arduino is reset, it should light up that led.

When I get home today, I will post my results of each selection.

int aPin = 0;
int bPin = 1;
int cPin = 2;
int dPin = 3;

// 0 = input, 1 = output
int aPinIO[] = {1,1,1,1,1,1,0,0,0,0};
int bPinIO[] = {1,1,0,0,0,0,1,1,1,1};
int cPinIO[] = {0,0,1,1,0,0,1,1,0,0};    
int dPinIO[] = {0,0,0,0,1,1,0,0,1,1};  

// pin polarity 
int aPinHL[] = {HIGH,LOW,HIGH,LOW,HIGH,LOW,-1,-1,-1,-1};
int bPinHL[] = {LOW,HIGH,-1,-1,-1,-1,HIGH,LOW,HIGH,LOW};
int cPinHL[] = {-1,-1,LOW,HIGH,-1,-1,LOW,HIGH,-1,-1};    
int dPinHL[] = {-1,-1,-1,-1,LOW,HIGH,-1,-1,LOW,HIGH};  


int testLEDs[] = {1,0,1,0,1,0,1,0,1,0}; //unused 
int numLEDs = 10; //unused

int val = 0;       
int potPin = 2;
int i;

void setup() {
  Serial.begin(9600); 
  val = analogRead(potPin);    
  val = map(val, 0, 1023, 0, 9); // map the pot as 0 thru 9
  Serial.print("START val: ");
  Serial.println(val);
  
  i=val;
  Serial.println("PIN: Pin#, Input(0)/Output(1), Output High/Low");
  Serial.print("A: ");
  Serial.print(aPin);
  Serial.print(", ");
  Serial.print(aPinIO[i]);
  Serial.print(", ");
  Serial.println(aPinHL[i]);
  Serial.print("B: ");
  Serial.print(bPin);
  Serial.print(", ");
  Serial.print(bPinIO[i]);
  Serial.print(", ");
  Serial.println(bPinHL[i]);
  Serial.print("C: ");
  Serial.print(cPin);
  Serial.print(", ");
  Serial.print(cPinIO[i]);
  Serial.print(", ");
  Serial.println(cPinHL[i]);
  Serial.print("D: ");
  Serial.print(dPin);
  Serial.print(", ");
  Serial.print(dPinIO[i]);
  Serial.print(", ");
  Serial.println(dPinHL[i]);

    if(aPinIO[i]) {   // set pin states
      pinMode(aPin, OUTPUT);
    }
    else {
      pinMode(aPin, INPUT);   
    }   
    if(bPinIO[i]) {
      pinMode(bPin, OUTPUT);
    }
    else {
      pinMode(bPin, INPUT);   
    }       
    if(cPinIO[i]) {
      pinMode(cPin, OUTPUT);
    }
    else {
      pinMode(cPin, INPUT);   
    }      
    if(dPinIO[i]) {
      pinMode(dPin, OUTPUT);
    }
    else {
      pinMode(dPin, INPUT);   
    }   
 
}

void loop() { // light up the selected pin and dump the pot value to the console
  
    if(aPinIO[i]) {
      digitalWrite(aPin, aPinHL[i]);  
    }
    if(bPinIO[i]) {
      digitalWrite(bPin, bPinHL[i]);  
    }
    if(cPinIO[i]) {
      digitalWrite(cPin, cPinHL[i]);  
    }  
    if(dPinIO[i]) {
      digitalWrite(dPin, dPinHL[i]);  
    }
  val = analogRead(potPin);    
  val = map(val, 0, 1023, 0, 9);
  Serial.print("val: ");
  Serial.println(val);
}

Well, you have a bunch of code in setup() that looks like it should be in loop(); I don't see how the lights would change at all after it starts; you never reset i, which is the LED# to light. The reset of of pins to input/output using pinMode also has to happen in loop(); this is probably what threw you off (since pinMode() usually happens in setup()...

sure sure, i know all that. This code was a bastardization of its original form just to test out why only some leds come on... anyhow, heres the output from each setting of the dial
value-led thats on
9-10
8-9
7-8
6-7
5-10
4-9
3-8
2-7
1-nothing
0-nothing

gonna recheck my wiring tomarrow evening...

hrmm.. I see no problems with my wiring... if anyone has any ideas of where my problem my lie, i would appreciate it.

You do an:-
i=val;
In the setup but not in the main loop. Is that code you posted wrong and you really do that? Without it nothing will change once the code is run for the first time.
You might be changing the pot and then pressing reset?

yes, this code is as intended. I set the value and reset the board to change the led. only one led should be lit during the loop. this is to test out why i get the following results from changing the val variable:
(val)-(lit led)
9-10
8-9
7-8
6-7
5-10
4-9
3-8
2-7
1-nothing
0-nothing

Once i can get val = 0-9 to map out to leds 1-10, i will alter the code to allow for multiple leds to be lit quickly, simulating static lights.

thank you all for your continued support of my issues. :wink:

ok so theoretically this circuit should be able to handle 12 leds (n pins: n^2-n=leds, 4^2-4=12). So if i add in the code for the last 2 leds, i get some odd results.

Here is modified code:

int aPin = 0;
int bPin = 1;
int cPin = 2;
int dPin = 3;

int aPinIO[] = {1,1,1,1,1,1,0,0,0,0,0,0};
int bPinIO[] = {1,1,0,0,0,0,1,1,1,1,0,0};
int cPinIO[] = {0,0,1,1,0,0,1,1,0,0,1,1};    
int dPinIO[] = {0,0,0,0,1,1,0,0,1,1,1,1};  

int aPinHL[] = {HIGH,LOW,HIGH,LOW,HIGH,LOW,-1,-1,-1,-1,-1,-1};
int bPinHL[] = {LOW,HIGH,-1,-1,-1,-1,HIGH,LOW,HIGH,LOW,-1,-1};
int cPinHL[] = {-1,-1,LOW,HIGH,-1,-1,LOW,HIGH,-1,-1,HIGH,LOW};    
int dPinHL[] = {-1,-1,-1,-1,LOW,HIGH,-1,-1,LOW,HIGH,LOW,HIGH};


int testLEDs[] = {1,0,1,0,1,0,1,0,1,0};
int numLEDs = 10;

int val = 0;       
int potPin = 2;
int i;

void setup() {
  Serial.begin(9600); 
  val = analogRead(potPin);    
  val = map(val, 0, 1023, 0, 11);
  Serial.print("START val: ");
  Serial.println(val);
  
  i=val;
  Serial.println("PIN: Pin#, Input(0)/Output(1), Output High/Low");
  Serial.print("A: ");
  Serial.print(aPin);
  Serial.print(", ");
  Serial.print(aPinIO[i]);
  Serial.print(", ");
  Serial.println(aPinHL[i]);
  Serial.print("B: ");
  Serial.print(bPin);
  Serial.print(", ");
  Serial.print(bPinIO[i]);
  Serial.print(", ");
  Serial.println(bPinHL[i]);
  Serial.print("C: ");
  Serial.print(cPin);
  Serial.print(", ");
  Serial.print(cPinIO[i]);
  Serial.print(", ");
  Serial.println(cPinHL[i]);
  Serial.print("D: ");
  Serial.print(dPin);
  Serial.print(", ");
  Serial.print(dPinIO[i]);
  Serial.print(", ");
  Serial.println(dPinHL[i]);

    if(aPinIO[i]) {
      pinMode(aPin, OUTPUT);
    }
    else {
      pinMode(aPin, INPUT);   
    }   
    if(bPinIO[i]) {
      pinMode(bPin, OUTPUT);
    }
    else {
      pinMode(bPin, INPUT);   
    }       
    if(cPinIO[i]) {
      pinMode(cPin, OUTPUT);
    }
    else {
      pinMode(cPin, INPUT);   
    }      
    if(dPinIO[i]) {
      pinMode(dPin, OUTPUT);
    }
    else {
      pinMode(dPin, INPUT);   
    }   
 
}

void loop() {
  
    if(aPinIO[i]) {
      digitalWrite(aPin, aPinHL[i]);  
    }
    if(bPinIO[i]) {
      digitalWrite(bPin, bPinHL[i]);  
    }
    if(cPinIO[i]) {
      digitalWrite(cPin, cPinHL[i]);  
    }  
    if(dPinIO[i]) {
      digitalWrite(dPin, dPinHL[i]);  
    }
  val = analogRead(potPin);    
  val = map(val, 0, 1023, 0, 11);
  Serial.print("val: ");
  Serial.println(val);
}    
/*for(i=0;i<numLEDs;i++) {
    if(aPinIO[i]) {
      pinMode(aPin, OUTPUT);
      //digitalWrite(aPin, aPinHL[i]);  
    }
    else {
      pinMode(aPin, INPUT);   
    }   
    if(bPinIO[i]) {
      pinMode(bPin, OUTPUT);
      //digitalWrite(bPin, bPinHL[i]);  
    }
    else {
      pinMode(bPin, INPUT);   
    }       
    if(cPinIO[i]) {
      pinMode(cPin, OUTPUT);
      //digitalWrite(cPin, cPinHL[i]);  
    }
    else {
      pinMode(cPin, INPUT);   
    }      
    if(dPinIO[i]) {
      pinMode(dPin, OUTPUT);
      //digitalWrite(dPin, dPinHL[i]);  
    }
    else {
      pinMode(dPin, INPUT);   
    }   
    
    
    if(aPinIO[i]) {
      digitalWrite(aPin, aPinHL[i]);  
    }
    if(bPinIO[i]) {
      digitalWrite(bPin, bPinHL[i]);  
    }
    if(cPinIO[i]) {
      digitalWrite(cPin, cPinHL[i]);  
    }  
    if(dPinIO[i]) {
      digitalWrite(dPin, dPinHL[i]);  
    }
  }*/

notice that the pot now maps 0-11.

now when i set the pot to 11 i get leds 10 and 7 on. when i set it to 10 i get leds 8 and 9 on.

does this make sense? i am beginning to think that i have the wiring theory wrong. :-/