Go Down

Topic: Charlieplexing (Read 6042 times) previous topic - next topic

Onions

Hello everybody!
This is my first post on this forum, so forgive me if I put it in the wrong section.  :.
I have been reading about charlieplexing on

http://www.instructables.com/id/Charlieplexing-LEDs--The-theory/

The concept sounded incredibly interesting, so I set about designing some software and
hardware for it, both of which are shown below:

Hardware schematic:


http://i.imgur.com/UH0JC.png

Software code:

Code: [Select]
int previousByte;
int incomingByte;        //variable used for storing incoming data

void setup(){
  Serial.begin(9600);    //start serial communication
}

void loop(){
  if(Serial.available() > 0){      //if there is data available...
    previousByte = incomingByte;   //store the old data as previousbyte
    incomingByte = Serial.read();  //read the new data
    incomingByte = incomingByte - 48;    //Subtract 48 form it - 0 has the ASCII value 48, so to get it back to 0, we take away 48
    Serial.flush();                      //clear the serial 'data bank'
  }
 
  if(incomingByte != previousByte){    //if the new data is different to the old suuff...
   //turn all pins to output, so we can turn them to low.
   pinMode(4, OUTPUT);
   pinMode(3, OUTPUT);
   pinMode(2, OUTPUT);
    digitalWrite(2, LOW);      //turn all the pins low
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    switch(incomingByte){      //turn on the correct pins for the LED selected:
   
      case 1:
      pinMode(4, INPUT);
      pinMode(3, OUTPUT);
      pinMode(2, OUTPUT);
      digitalWrite(3, LOW);
      digitalWrite(2, HIGH);
      break;
     
      case 2:
      pinMode(4, INPUT);
      pinMode(3, OUTPUT);
      pinMode(2, OUTPUT);
      digitalWrite(3, HIGH);
      digitalWrite(2, LOW);
      break;
     
      case 3:
      pinMode(2, INPUT);
      pinMode(3, OUTPUT);
      pinMode(4, OUTPUT);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      break;
     
      case 4:
      pinMode(2, INPUT);
      pinMode(3, OUTPUT);
      pinMode(4, OUTPUT);
      digitalWrite(4, HIGH);
      digitalWrite(3, LOW);
      break;
     
      case 5:
      pinMode(3, INPUT);
      pinMode(4, OUTPUT);
      pinMode(2, OUTPUT);
      digitalWrite(2, HIGH);
      digitalWrite(4, LOW);
      break;
     
      case 6:
      pinMode(3, INPUT);
      pinMode(4, OUTPUT);
      pinMode(2, OUTPUT);
      digitalWrite(4, HIGH);
      digitalWrite(4, LOW);
      break;
     
      default:
      Serial.println("Please select a number between 1 and 6");
      break;
    }
   previousByte = incomingByte;  //this makes the code more efficient, by only repeating the above when needed
  }
}
     
     



The code is simple, and compiles without problems. The hardware schematic was drawn in
express PCB and has the pin connections and resistor values labelled. The reason I posted this
is because I was worried about the pins. I did not want to end up breaking anything by mistake,
so:


  • Will I break the input pins by feeding too much current through them?

  • Does writing a pin as low couple it to ground, rather than just stopping it from being high?



I know I probably shouldn't worry about the input pins breaking, as they are being supplied
with less current than the outputs can provide. The thing I am concerned about is, surely
using a low pin as a ground pin will pour in power that is not neeeded or wanted, and wreck
havock with the inner workings of the microcontroller?


Thanks in advance for any help!
Onions.




My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

baum

Hook a transistor to the pin (preferably a FET) and you can have more current.
I don't think that the pins are actually tied to ground. Test it by connecting a "LOW" digital output to an analog input and read off the values over Serial. To fix it, just put a 10k pull-down resistor between the output pin and ground.ß

cmiyc

You might consider using more than 80 ohms, especially while you are testing.  This way you can ensure you don't accidentally have a setup where you Source or Sink >20mA from a single pin.  Another number to keep in mind is the absolute max current rating for the VCC and GND pins.  The max is 200mA.  Which means you probably don't want it to be more than 150mA.

Your comment: "The thing I am concerned about is, surely using a low pin as a ground pin will pour in power that is not neeeded or wanted, and wreck
havock with the inner workings of the microcontroller
?"

I'm not sure what any of that means.  When a pin goes "HIGH", it is connected to VCC through a transistor.  When a pin goes "LOW", it is connected to Ground through a transistor.  Look at the functional diagrams for an i/o pin in the datasheet.  What is the source of this "power" that will "pour"?  If you Source or Sink 40mA or more though the pin, you are likely to burn out the pin's drivers.  There isn't much else to wreck.

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Binette228

Hi,

To answer you two questions:
1. (I'm assuming you talk about the I/O pins in general).
Quote
Will I break the input pins by feeding too much current through them?

Yes you will, the maximum sink or drive current per I/O pin is 40 mA, according to the Arduino hardware section. You should take a look at the datasheet for more precise information, I think some groups of pins have their own maximum current ratings. But always be careful, sinking or driving 40 mA for a long period of time COULD harm the arduino, especially if you are using LEDs, which forward voltage changes with the temperature, also changing the current passing throught them...

2.
Quote
Does writing a pin as low couple it to ground, rather than just stopping it from being high?

Writing a pin LOW will sort of "connect" it to ground, so you can sink current with it.

Don't take what I say as absolute truth, I may have done mistakes. Seriously, you should read some parts of the datasheet and take notes from it. There is all the information about current and voltage ratings.

Good luck!

Onions

Hello again!

Quote
Hook a transistor to the pin (preferably a FET) and you can have more current.

I was considering using transistors, but I decided aganst it to save space, time and money.
Then again, 20p of money, less than a minute more to set it all up... Maybe I will use some
spare transistors I have.  :)

Quote
You might consider using more than 80 ohms, especially while you are testing.  This way you can ensure you don't accidentally have a setup where you Source or Sink >20mA from a single pin.  Another number to keep in mind is the absolute max current rating for the VCC and GND pins.  The max is 200mA.  Which means you probably don't want it to be more than 150mA.


That's probably definately a good idea. Some 330 ohm resistors should sort it?

Quote
When a pin goes "HIGH", it is connected to VCC through a transistor.  When a pin goes "LOW", it is connected to Ground through a transistor.


That sums it all up nicely, thanks!

Quote
Seriously, you should read some parts of the datasheet and take notes from it.


That is something I will do!

Thanks everyone!
Onions.

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

Valalvax

I've done this already (up to 30 LEDs using 6 inputs, due to some crappy wiring 6 or so didn't work, but I never bothered fixing it)

Yes, you can break the input pins, I'd use 100? or higher resistors

When a pin is set to output and low it is indeed a ground, your code is much more fancy than mine, but works the same

Onions

Quote
Yes, you can break the input pins, I'd use 100? or higher resistors


I think I'll use 330 ohms, just to be on the safe side. Some day, I would
like to charlieplex 30+ LEDs, though I would have no use (yet!).
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

Valalvax


Quote
Yes, you can break the input pins, I'd use 100? or higher resistors


I think I'll use 330 ohms, just to be on the safe side. Some day, I would
like to charlieplex 30+ LEDs, though I would have no use (yet!).


Well, I had used a couple 100 and a couple 330s actually, because I didn't have enough of one type

I didn't have a USE for the 30 LEDs, just wanted to build up from the simple 3 Pin 6 LED circuit, should have probably stopped before hitting 6 though because I ran out of breadboard room and had a couple shorts, thinking of getting some high gauge wire and pulling the insulation off of it, then sliding it onto the LEDs legs to solve that problem in the future

cmiyc

Adafruit sells the LoLshield which is a high-number of charliplexed LEDs.

I found with matrixes once I got bigger than 5x5, it was easier to design a PCB.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Onions

Quote
I didn't have a USE for the 30 LEDs


XD That's such a goods reason, you've tempted me to build one!  :)
I will probobly buy the parts this weekend.

Quote
Adafruit sells the LoLshield which is a high-number of charliplexed LEDs.
I found with matrixes once I got bigger than 5x5, it was easier to design a PCB.


The shield looks cool, but it takes away part of the fun - making it!  :)
Although, it looks a brilliant option for bigger numbers of LEDs, and,
as you said, it would be better to just use a PCB for big numbers of LEDs.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

Grumpy_Mike

Quote
The thing I am concerned about is, surely
using a low pin as a ground pin will pour in power that is not neeeded or wanted, and wreck
havoc with the inner workings of the microcontroller?

This is called current sinking and is a perfectly normal way to drive an output from a logic pin.

Quote
Will I break the input pins by feeding too much current through them?

No you can't put too much current into an input pin if the voltage is restricted to the supply voltage.
HOWEVER
You can feed too much current into an output pin or draw too much current out of one.
You might have been confused because each pin on the arduino can be input OR output, it is only in the output mode that they are susceptible to excess current.


Onions

Quote
No you can't put too much current into an input pin if the voltage is restricted to the supply voltage.
HOWEVER
You can feed too much current into an output pin or draw too much current out of one.


So, as long as I use the correct value (or higher - within reason) resistors, it should be fine?

Thanks, Onions.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

Valalvax


Quote
No you can't put too much current into an input pin if the voltage is restricted to the supply voltage.
HOWEVER
You can feed too much current into an output pin or draw too much current out of one.


So, as long as I use the correct value (or higher - within reason) resistors, it should be fine?

Thanks, Onions.


Yep

MarkT


Hook a transistor to the pin (preferably a FET) and you can have more current.
I don't think that the pins are actually tied to ground. Test it by connecting a "LOW" digital output to an analog input and read off the values over Serial. To fix it, just put a 10k pull-down resistor between the output pin and ground.ß


If you are Charlieplexing you can't just naively use a transistor to amplify the current - Charlieplexing relies on tri-state outputs - ie the pin can be
either LOW, HIGH or INPUT (high-impedance).  To drive more current both LOW and HIGH you'll need two transistors and the circuit will need to be high-impedance if the pin is - rather tricky.  In practice with LEDs its good enough to use a class-B amp thus:


Note that there is voltage drop across the transistors - but for 5V logic there's enough headroom to drive LEDs of most colours (possibly not UV ones).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Valalvax

Hey Onions have you gotten around to running the script yet?

Go Up