Pages: [1]   Go Down
Author Topic: Charliplexing Code without Library  (Read 620 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Team,
  I am working on learning how to charlieplex to build homemade displays (next, I'll work on using MAX7219's, but charlieplexing seems simpler to start with). I have built my first matrix, a simple 3x3 square. I am controlling 9 LED's with 6 pins, the columns are the anodes and the rows are the cathodes. I can't seem to control the device. I can test each individual pin by connecting the respective column to pin 13, and the row to GND and running blink. However, when I try to control them using code, nothing happens. I have a simple code here that was intended to simply flash the top left LED, but nothing happens. Can you help me figure out why?
Code:
int Col3 = 13;
int Col2 = 11;
int Col1 = 10;
int Row3 = 3;
int Row2 = 5;
int Row1 = 7;

void setup(){
  pinMode(Col3, OUTPUT);
  pinMode(Col2, OUTPUT);
  pinMode(Col1, OUTPUT);
  pinMode(Row3, INPUT);
  pinMode(Row2, INPUT);
  pinMode(Row1, INPUT);
}

void loop(){
  digitalWrite(Col1, HIGH);
  digitalWrite(Row1, LOW);
  delay(500);
  digitalWrite(Col1, LOW);
  delay(500);
}

Thank you guys!
MonorailOrange
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the columns are the anodes and the rows are the cathodes.
I think you may not understand how charlieplexing works, or how the diodes are wired.
Diodes are wired in opposing pairs across all combinations of pins.
« Last Edit: November 08, 2012, 05:00:49 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5336
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All pins should be outputs...

But:
a) That's not how charlieplexing works
b) Trying to light rows of LEDs from an Arduino pin is a bad idea. Too much current will kill it (the Arduino pin).


« Last Edit: November 08, 2012, 05:03:51 pm by fungus » Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

... but charlieplexing seems simpler to start with ...

It isn't, believe me. The code is quite complex compared to the MAX7219, and you still have to address the issue of current-limiting resistors.

Here's a post about the MAX7219:

http://www.gammon.com.au/forum/?id=11516
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The MAX7219 has built-in current limiting, which makes life easier.
Logged

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

So would it be better for me to learn charlieplexing using something like the LoL Shield? I have ordered an 8x8 MAX7219 board, but it's going to take forever to get here (IF it ever gets here).
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK. Let's assume you have a resistor in series. I hope you do. Then this works:

Code:
const int Col3 = 13;
const int Col2 = 11;
const int Col1 = 10;
const int Row3 = 3;
const int Row2 = 5;
const int Row1 = 7;

void setup(){
  pinMode(Col3, OUTPUT);
  pinMode(Col2, OUTPUT);
  pinMode(Col1, OUTPUT);
  pinMode(Row3, OUTPUT);
  pinMode(Row2, OUTPUT);
  pinMode(Row1, OUTPUT);
}

void loop(){
  digitalWrite(Col1, HIGH);
  digitalWrite(Row1, LOW);
  delay(500);
  digitalWrite(Col1, LOW);
  delay(500);
}

Note that they all have to be outputs otherwise there is nothing to sink the current.

Charliplexing works with a combination of output/high output/low and input (high impedance).

As I recall you make a column output/high and the rows output/low, and the other columns input, to make a particular junction light up. Or reverse the low/high to make the other LED (wired the other way around) to light up.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5336
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So would it be better for me to learn charlieplexing using something like the LoL Shield? I have ordered an 8x8 MAX7219 board, but it's going to take forever to get here (IF it ever gets here).

??

Where did you order it? You can buy a dozen MAX7219s on eBay for $10 and have them in a week.

I agree with Nick, a MAX7219 is FAR easier to work with than charlieplexing and does exactly what you seem to want.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

USA
Offline Offline
Sr. Member
****
Karma: 13
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So would it be better for me to learn charlieplexing using something like the LoL Shield?

It would be better to learn charlieplexing by understanding its underlying principles. 

Based on what you say in your posts, you seem to be confusing a charlieplexed array with an LED matrix.  Maybe a matrix was what you intended to use?

In a matrix arrangement, the canonical method is to drive a column pin to its active state, leaving all the other column pins inactive, and then drive the row pins of the LEDs you intend to light to their active state, illuminating some of the LEDs in a single column simultaneously.  Naturally, the roles of the rows and columns can be exchanged, and maybe you want to illuminate only one LED at a time - if one of those is what you want to do, then your code just needs to reflect it.

In a charliplexed arrangement, only one LED is illuminated at a time.  The pin connected to that LED's anode is driven high, the pin connected to its anode is driven low, and all of the other pins are configured as inputs.  The wiring is a lot more complex than a a matrix scheme - and, for all but a few trivial applications, the code is a whole lot more complex - and there's often not a natural one-to-one correspondence between a particular LED's location in the display and the pins that activate it.  But, it'll address more LEDs than a matrix arrangement with the same number of pins.

The explanation of how charlieplexing works is long and complicated; I'm not inclined to reproduce it here, since I'm not entirely sure that charlieplexing is what you intended, and it's already described in many places on the Internet.  I'll suggest the Wikipedia article on charlieplexing, and the resources that it references.  There are oodles of descriptions of LED matrix arrangements on the web; google away.
Logged

Pages: [1]   Go Up
Jump to: