Arduino Charlieplexing LED & Code


The term “Charileplexing” is not a familiar one for many electronics hobbyists. Charlieplexing is a technique proposed in early 1995 by Charlie Allen (at Maxim Integrated) for driving a multiplexed display in which relatively few I/O pins on a microcontroller are used to drive an array of LEDs. This method uses the tri-state logic capabilities of microcontrollers in order to gain efficiency over traditional multiplexing.

Often, when it comes to your Arduino project,you never have enough input/output (I/O) pins on your Arduino Microcontroller. The addition of your favorite LCD display, a bunch of blinkers, beepers and a few sensors, you are already up to more pins than what is available in the microcontroller platform.

Fortunately, you can Charlieplex a number of LEDs from a few Arduino ports, and save those precious ports for something really exciting. Here, I’m going to show you how to perfectly blend an Arduino and the charlieplexing technique!

Arduino Charlieplex LEDs

In principle, Charlieplexing technique allows you to drive “n2−n” LEDs using only “n”
Arduino pins. Here, we are using 3 pins to drive 32 − 3 = 6 LEDs. Note that, we setting related pins (D5-D6-D7) of the Arduino to one of the three states (tri-state logic):

  • HIGH (H): 5V
  • LOW (L): 0V
  • High Impedence (Z): Disconnected

Arduino Sketch

/*
- Arduino & Chralieplexing
- Driving 6 LEDs using only 3 I/O Pins
- Tri-State Logic Implementation
- Demo Code From Internet
- Prepared by T.K.Hareendran
- Tested at TechNode Protolabz
- Source: http://www.electroschematics.com
*/
#define LED_1 5
#define LED_2 6
#define LED_3 7

void setup()
{
   pinMode(LED_1, INPUT);
   pinMode(LED_2, INPUT);
   pinMode(LED_3, INPUT);
}

void loop()
{
   set_pins(LED_1, LED_2);
   delay(100);
   set_pins(LED_2, LED_1);
   delay(100);
   set_pins(LED_3, LED_1); 
   delay(100);
   set_pins(LED_1, LED_3);
   delay(100);
   set_pins(LED_2, LED_3);
   delay(100);
   set_pins(LED_3, LED_2);
   delay(100); 
}

void set_pins(int high_pin, int low_pin)
{
   reset_pins();
   pinMode(high_pin, OUTPUT);
   pinMode(low_pin, OUTPUT);
   digitalWrite(high_pin, HIGH);
   digitalWrite(low_pin,LOW);
}

void reset_pins()
{
   pinMode(LED_1, INPUT); 
   pinMode(LED_2, INPUT);
   pinMode(LED_3, INPUT);
   digitalWrite(LED_1, LOW);
   digitalWrite(LED_2, LOW);
   digitalWrite(LED_3, LOW);
}

Tri-State Logic?
In digital electronics tri-state logic allows an output port to assume a high impedance state (Z) in addition to the High (H) and Low (L) logic levels, effectively removing the output from the circuit. This allows multiple circuits to share the same output line or lines.

Lab Note:
Prototype tested at lab with 3mm Red LEDs (x6), and 100 R resistors (x3). Choosing the value of esistors is very important. Try both theoritical & empirical calculation method to find optimal resistor values for LEDs.


Sorry, comments are closed!