Skip to main content

What is Charlieplexing?

When you use microcontrollers and you are out of PIN's to connect some LED's for status or when you want to drive a binary clock with few pins left in microcontroller, there is a way that can solve this issue.
Its called charlieplexing and if you know multiplexing you will have some idea of how it works. I will do an example using Arduino for demonstration.
Charlieplexing is a method to drive multiple LED's with few pins available in your microcontroller.
Here is the formula to calculate how many LEDs can be drive from N number of pins.

Number of LED's = No. of PINS available ( No. of PINS available - 1)

For example you have only 3 pins left in Arduino and you want to know how many LED's can be drive.

Number of LED's = 3(3-1)
Number of LED's = 3(2)
Number of LED's = 6

So from 3 PINS you can drive 6 LED's.

Since arduino have tri-state output (INPUT, HIGH and LOW) its easy to drive the LED's using this method.
how leds are connected to 3 pins of an arduino


Truth table of how its drive

L = LOW (make out pin as LOW)
H = HIGH (make out pin as HIGH)
I = INPUT (make pin as INPUT) so this pin will be an open circuit

To drive LED 1
You have to make pin 2 and 3 as output pins. Pin 4 as an input.
So when you sent pin 2 = LOW and pin 3 = HIGH and leave pin 4 as an INPUT, the LED 1 will light up.
To drive LED 3
You have to make pin 3 and 4 as output pins. Pin 2 as an input.
So when you sent pin 3 = LOW and pin 4 = HIGH and leave pin 2 as an INPUT, the LED 3 will light up.

Here is an arduino test code that i have written for test charlieplexing.


#define L1 2
#define L2 3
#define L3 4

int delays = 400;      


void setup() {

}

void loop() {
 
  pinMode(L1,OUTPUT);
  pinMode(L2,OUTPUT);
  pinMode(L3,INPUT);
 
  digitalWrite(L1,LOW);
  digitalWrite(L2,HIGH);
  delay(delays);
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  delay(delays);
 
  pinMode(L1,INPUT);
  pinMode(L2,OUTPUT);
  pinMode(L3,OUTPUT);
 
  digitalWrite(L2,HIGH);
  digitalWrite(L3,LOW);
  delay(delays);
  digitalWrite(L2,LOW);
  digitalWrite(L3,HIGH);
  delay(delays);
 
  pinMode(L1,OUTPUT);
  pinMode(L2,INPUT);
  pinMode(L3,OUTPUT);
 
  digitalWrite(L1,LOW);
  digitalWrite(L3,HIGH);
  delay(delays);
  digitalWrite(L1,HIGH);
  digitalWrite(L3,LOW);
  delay(delays);

}



hope this will help you.
Post a Comment

Popular posts from this blog

SIMCOM SIM900A fixed

Since everyone is interested in this post and lots of request comes to get the firmware, i have put a link so that everyone can download it easily. SIMCOM 900A firmware

Its been a while that i was trying to fix the SIM900A GSM module. This module support local GSM band but after some researches it was concluded that it is carrier locked :(. After long conversion of days to actual chip manufacture SIMCOM, they told it can be fixed by updating its firmware to latest original version but unfortunately they don't provide firmware to small parties.

I never stop trying to get the firmware and SIMCOM again replied, this time they said contact local SIMCOM supplier and request for firmware. But this little Maldives don't have SIMCOM or any electronics manufacturer. So i contacted my friend coody from NOA LABS/Smart prototyping (a friend in china) and told him to help me. I explained him what to do so he can communicate with SIMCOM in china.

Finally he sends and email saying that he g…

Clover Display M302 hack

Its been a while i have this LCD and today i thought of connecting the LCD display to Arduino. Unfortunately i could not found any pin outs of this from any where and from the manufacture. Actually this is very old model which i got from old FAX machine and this display is a very cheap from online sources.
Clover Display M302 PCB Ver 1.0 (16x2) which has 10 pin flat cable. After researching for a while from the internet i have seen in many forums people are asking for help on how to connect it and what is the pin configurations? so i thought of helping them as well as my self at the same time.
After going through some of my old collections of Russian data of displays and things i found a basic diagram of how 10 pin LCD display configuration. 
PIN1   - VSS PIN2   - VDD PIN3   - CONTRAST PIN4   - RS PIN5   - R/W PIN6   - ENABLE PIN7   - DB4 PIN8   - DB5 PIN9   - DB6 PIN10 - DB7
I tried these configurations and wired up to the arduino with the LCD sketch and it worked on the first try. …

TCP communication from NEOWAY M590E- Successful

Some of the GSM/GPRS chips do not support HTTP services and since the modems are controlled via AT commands, the AT command sets are very limited to HTTP commands in NEOWAY M590E.

The only option to communicate with any cloud based or locally hosted server was using TCP protocol. I have used HTTP services in many of my projects and experiments, it is easy and with few lines of code can manage an HTTP requests. For weeks i have been struggling with TCP request and every time it fails to connect or sometimes data is sent but from server side there is no new data fetched.

Basically TCP is transport layer in OSI model and HTTP is in application layer. TCP will do a socket based connection to servers predefined port. For example  test.com:8989. what i mean is it needs a listener to listen to port that you define or open to use.

After weeks of reading articles and AT command sets thoroughly, finally i managed to handle a TCP request from modem. But still it fails sometimes or unable to conn…