Using 2-lead bi-colour LEDs with PICAXE

Morning folks,

Is there an easy way to use a large number of 2-lead bi-colour LEDs with a PICAXE chip? I'm needing to drive approx. 100 of them, each individually switchable - not just between colours, but fully off too.

Up until now I was using 3-lead LEDs with an HT1632C driver, but I've discovered these LEDs don't fit in the mounts I have due to their "outer" two legs being wider than the LED body, and therefore not fitting in the hole in my panel. Is there something similar to that driver but for 2-lead bi-colour LEDs, ie. they can reverse polarity to change colours?

Cheers!
 

westaust55

Moderator
In basic terms if you use two outputs from a PICAXE or other chip (e.g. MCP23017) then with one output high and other low you see one colour. Don’t forget resistors to limit current.

Toggle both inputs and you see the other color. Make both outputs high or both low and the Leds are off.

Try a search on the forum for charliplexing since you have a large number of LEDs
 

hippy

Technical Support
Staff member
It don't know if it is possible to multiplex bi-colour two-lead LED's using a traditional multiplex scheme -
Code:
R0 --.-|---.-|--                                      |
      \|    \|      -.-|-   --.-----------------------|--
       |     |        \|  =   |                       |
R1 --.-|---.-|--       |      |       R               |
      \|    \|                |   .--|>|--.    ___    |
       |     |                `---{       |---|___|---{
C0 ----'     |                    `--|<|--'           |
             |                        G
C1 ----------'
Set R0 high to control Row 0 red, all other Rx as inputs / tri-state. Set Cx low to light a LED, all other Cx as inputs / tri-state.

Set R0 low to control Row 0 green, all other Rx as inputs / tri-state. Set Cx high to light a LED, all other Cx as inputs / tri-state.

So R0=High, R1=Input, C0=Low, C1=Input will light the top left LED red.
Code:
H ---.-|---.-|--
     R\|    \|
       |     |
X ---.-|---.-|--
      \|    \|
       |     |
L -----'     |
             |
X -----------'
What I'm not sure of is the leakage path - R0 high through top right LED, down C1, up bottom right LED, down bottom left LED, to C0 low.

That's a definite current path but whether it lights those LED's will probably depend on the R0 high voltage.

One cannot make R1 or C1 high or low because that simple creates a shorter current path.

8x8 bi-colour LED arrays seem to always have two separate matrices, red and green, with 8+8+8=24 pins, which might also point to it not being possible to have a single matrix..
 
In basic terms if you use two outputs from a PICAXE or other chip (e.g. MCP23017) then with one output high and other low you see one colour. Don’t forget resistors to limit current.

Toggle both inputs and you see the other color. Make both outputs high or both low and the Leds are off.
Aye, that's what I'd "normally" do with these LEDs, if I didn't have so flippin many of them 😂

Try a search on the forum for charliplexing since you have a large number of LEDs
I'm a numpty... I completely forgot about Charlieplexing! Search incoming!!

Thank you!!
 
8x8 bi-colour LED arrays seem to always have two separate matrices, red and green, with 8+8+8=24 pins, which might also point to it not being possible to have a single matrix..
Yep, that's what I originally planned to use when I wanted to use the HT1632C - I went out and bought some 3mm bi-colour LEDs with 3 leads (2 anodes and a common cathode). That would've worked perfectly fine using a normal matrix driver... But when they arrived I discovered the legs were too wide to fit in my panel mount 🤦

I'll take a look at the feasibility of Charlieplexing just now - in the spirit of a well-known electronics YouTube personality, "One moment please!"
 
Legs can't be bent to fit?
After two hours with a dremel, soldering iron, pliers, snips and lots of four-letter Anglo-Saxon words, I can most definitely confirm that is the case!! :LOL:

The problem is that they come out the bottom of the LED moulding, and immediately "swing" outwards to beyond the outer limit of the plastic casing. The problem is they're not bent to achieve that, they are actually cast in that shape. And being flat instead of circular in shape, it's nigh impossible to bend them in that direction.

A good example of what they look like is shown in the picture:

The fact that the "bend" is cast flat makes it almost impossible to bend them back inwards :-( On my LEDs, they were actually even wider than that, with the inner edge of the legs being about level with the outer surface of the LED casing

8 of these MCP23017 boards (with 3-bit addressing) using 2 bits per LED would still only allow you to control 64 LEDs. Perhaps 2 PICAXEs linked by serial and each controlling 8 MCP23017s would do it.
Yeah, that (or any other shift register like it) would work... ideally I'd find one which uses SPI, cos then I wouldn't have as much of a problem with connecting many of them to a single chip (limited only by Chip Select lines). Trouble is... with over 100 LEDs, that's gonna get messy real quickly... I'll investigate that too, but I think I'll put it in the queue behind Charlieplexing for now, as the latter seems to me to be the "sensible" option.

I could be very wrong!!
 

hippy

Technical Support
Staff member
The problem is that they come out the bottom of the LED moulding, and immediately "swing" outwards to beyond the outer limit of the plastic casing.
It would depend on exactly which LED bezels you have, but it may be possible to hacksaw a slot to allow the legs to extend beyond the clip.

If the type of bezel which has a ring which slips over the bezel it may be possible to sand that down to being a thinner ring. If the assembly is a little loose in the panel that could be cured by super-gluing the ring to the bezel, and/or a dab of hot glue.

I do recall having to jump through that hoop when I was fitting three-lead LED's some time ago.

Another option may be to use a plastic panel, just drill holes which are a push-fit for LED's, with that dab of hot glue when in place.
 
It would depend on exactly which LED bezels you have, but it may be possible to hacksaw a slot to allow the legs to extend beyond the clip.

If the type of bezel which has a ring which slips over the bezel it may be possible to sand that down to being a thinner ring. If the assembly is a little loose in the panel that could be cured by super-gluing the ring to the bezel, and/or a dab of hot glue.

I do recall having to jump through that hoop when I was fitting three-lead LED's some time ago.

Another option may be to use a plastic panel, just drill holes which are a push-fit for LED's, with that dab of hot glue when in place.
I'm afraid I tried that... that's what the aforementioned Dremelw as used for :-(

The panel I'm using is constructed of 9mm ply (because it's what was available, and the model railway club couldn't use the piece for anything else as it was slightly warped). I used LED mounts which fit through a hole in the panel, much like panel mount buttons or togge switches, albeit the securing nut is screwed in from underneath.



The mounts are designed so that the LED is inserted from the "top", and secured from the "bottom" with a tiny rubber piece, through which the TWO leads fit, and which is then squished up inside the mount, effectively holding the LED in place.

But because the LED is inserted from the top, it sits inside the body of the mount. I tried dremelling (is that even a word?) slots from the top for the leads to fit through, but that didn't work - the LED was completely lopsided, and the mount looked awful.

I mean, if you know of a type of mount that works with these 3-lead LEDs, let me know!! My only current problem is that the holes are already drilled in the panel, and I really don't wanna end up with ugly holes...
 

AllyCat

Senior Member
Hi,

Charlieplexing is a good solution provided that you don't need the LEDs to be too bright and/or too many lit at the same time. AFAIK Charliplexing can be only a "one LED on at a time" multiplex, so the brightness (or specifically the average drive current) is inversely proportional to the (maximum) number of LEDs lit. It's probably not worthwhile attempting to devise individual tri-state drivers to increase the brightness.

Another possibility might be a "split-rail" configuration, with one pin of every LED connected to a "mid" rail of perhaps 3 volts (or 5 volts) and the other LED pins driven either to ground or to 5 volts (or 9 - 12 volts) depending on the colour required Whether both colours can be driven within the confines of a 5 volt rail will depend on the forward voltage of the LEDs. Also bear in mind that the "mid rail" may need to sink current from the (LEDs driven by the) supply rail, not just source current for the grounded LEDs.

Cheers, Alan.
 

hippy

Technical Support
Staff member
Your panel mounts look plastic so would it be possible to hacksaw the thread off, leaving enough to use the nut or to give enough sort of grip to glue them to the panel ?

I guess 9mm ply says "no" to that, but you could put a far thinner sheet of something over the ply and cut larger holes in the ply where the LED's come through.

The LED legs will be difficult to bend because they are a stamped square profile. It may be possible to bend them in on each other, like -
Code:
   _____
  / _.  \
 / |     \
(  O O O  )
 \   ._| /
  \_____/
Another option may be to cut the legs very close to the body and solder on flying leads. The rubber grommet can possibly have the two holes snipped together creating a slot for the legs or wire to slot through.

It does seem using dual-lead LEDs will be the easiest to assemble which then leaves driving. I suspect charlie-plexing would have the same problems as multiplexing, but bi-multiplexing can work, which we'll come to in a moment.

That there's no example of multiplexing or charlie-plexig for dual-lead arrays I could find, and no chips which describe themselves as being for that, suggests to me no one has figured a way to do it, not in a way which is universal.

You could go the easy route; have one 08M2 per LED, or more sensibly use a PICAXE for a group of LED's. And that's where bi-multiplexing comes in -
Code:
X -------------------.      X A B | a b
                     |      ______|____
     __   .-|>|-. a  |            |
A --|__|--^-|<|-^----{      ? - - | - -
                     |      0 1 - | R -
     __   .-|>|-. b  |      0 - 1 | - R
B --|__|--^-|<|-^----{      1 0 - | G -
                     :      1 - 0 | - G
                     :
You can extend the number of LED's to the number of pins you have. You can also have multiple bi-multiplexed sets per PICAXE. The big issue would be how much current that PICAXE can source or sink.

There's probably some sort of drive circuit one could build to use shift registers and the like but that's probably more complicated and costly than using multiple PICAXE.
 

inglewoodpete

Senior Member
I realise you want to use around 100 R-G LEDs but you can cut the outer leads off near the LED body and solder fresh pigtails on the stumps. I've used this method on 3-wire RG LEDs before with the help of (modified) plastic jaw guards on a mini vice to hold the LED body, magnifying lamp and a 1mm soldering iron tip. (Oh yes - and a fair bit of patience! Where there is a will there's a way.)

I tried to post an MP4 of the PICAXE counting 0-9 in each of the three colours but the file was a bit (a lot!) big for the forum. Colour saturation in the camera did not do the image justice but you should get an idea of what can be done.
RGY-7Seg.jpg
 
Last edited:

Buzby

Senior Member
Dual lead bi-colour LEDs are perfect for Charlieplexing, but not so good for Multiplexing

Did you see my Orrery ?. https://picaxeforum.co.uk/threads/the-picaxe-orrery.30868/ ( There was a better write-up in the blog, but that's gone now. )

If you only need Off-Red-Green, with only about 20 LEDs lit at once, then Charlieplexing is your best route.

If you need Off-Red-Green with more than 20 LEDs lit, then Multiplexing is your best route, but ( as hippy says ) it will need an extra set of X pins, which you don't have with dual lead LEDs.

If you need Off-Red-Green-Yellow, then bi-multiplex ( as hippy showed ) is best, but it will get messy driving 100 LEDs.


The idea of using multiple PICAXE chips is much easier, more practical, and lots less wiring. The cost of a few little PICAXEs will save you many hours of headscratching.

Cheers,

Buzby
 

techElder

Well-known member
I didn't see a diagram of your LED setup, but why not arrange your setup so you can use one of the serialized LED arrays that work with SPI? They can be cut to length and arranged for indicators, and you would be able to choose most any color.
 
Morning folks,

Sorry for the late reply, but I got one email notification about a reply and never got round to opening it... unfortunately busy working :-(

The Charlieplexing does seem like a good idea... but I see the problem of having large numbers of LEDs connected to an array, meaning very dim LEDs potentially. To help solve this, I had an idea (Highly dangerous, I know, but hear me out... :p)...

  • If I group together LEDs which will ALWAYS be lit together (which is a fair few, as a lot of them form a "line", and would always be lit together), and wire those together in series...
  • Double the number of outputs required for "traditional" charlieplexing, which enables me to use pairs of PNP and NPN transistors, alsmost like an H-Bridge...
  • And replace the traditional current limiting resistor with a constant current (20mA) LED driver (arranged in pairs, one for each direction in series with diodes), with a larger power supply (12/16V).

The transistors would enable the higher voltages to be switched (albeit I'd require a second NPN transistor to switch the PNP transistor), and the constant current drivers would ensure that the appropriate voltage is dropped, no matter how many LEDs happen to be in a "string".

I'll do a little testing this evening when I get home, see if that's feasible... It would obviously require a fair bit more circuitry, but in my mind it should work...

However, over the weekend I met an old friend of mine. I told him about this problem, and his instant reaction was "how about some 3D printed mounts for the 3-lead LEDs?"... So I may or may not now be in the middle of throwing together a quick design in CAD for a mount which is actually capable of accepting my 3-lead LEDs after all!
 

Buzby

Senior Member
....
  • If I group together LEDs which will ALWAYS be lit together (which is a fair few, as a lot of them form a "line", and would always be lit together), and wire those together in series...
  • Double the number of outputs required for "traditional" charlieplexing, which enables me to use pairs of PNP and NPN transistors, alsmost like an H-Bridge...
  • And replace the traditional current limiting resistor with a constant current (20mA) LED driver (arranged in pairs, one for each direction in series with diodes), with a larger power supply (12/16V).
I still think either multiple simple PICAXE modules or addressable APA102 LEDs will be the best solution.

Trying to 'beef-up' the Charlieplexing will create lots of unexpected problems due to mis-matched resistances.

Charlieplexing is *very* fussy in this respect.
When I built the orrery I had spurious LED lighting problems when using different colour LEDs, due to the different currents they required.

Also, don't forget that the 'dimness' of Charlieplexed LEDs is due to the very low duty cycle.
The orrery ran the LEDs at about 70mA to compensate, by overdriving both the PICAXE pins and the LEDs !

If you need really bright LEDs you would need a lot more current than 70mA, and you will probably burn out the LED even with a low duty cycle.

Stick with simple tech.

Cheers,

Buzby
 
I had feared as much... multiple modules would obviously work well, it would just be messy (in my mind - I'm a wierd character!)... I'll see what comes of the offer of custom 3D-printed mounts for the 3-lead LEDs... if that works I can go back to my original plan to use a bog-standard LED matrix controller
 

hippy

Technical Support
Staff member
multiple modules would obviously work well, it would just be messy (in my mind - I'm a wierd character!)
I really can't see how daisy-chained modules would be more messy than the spider's web tangle of a multiplexed or charlie-plexed set-up.

Just trying to figure out what goes where, even before trying to wire that up and get it right, is hard enough. I would dread to think how much time getting it wrong would take to figure out and fix it. I can well imagine the easy option would soon become "rip it all out and start again".
 
I really can't see how daisy-chained modules would be more messy than the spider's web tangle of a multiplexed or charlie-plexed set-up.
Like I said - I'm a wierd twit :LOL:
It's just me, for some reason I'm not a fan of distributed processing. Please don't ask why - I'll happily do it if nothing else works, but I always try and find another solution... just my wierd brain!
 
Your HT1632C solution is 'distributed processing' !.
I know, I know... Like I said, I'm wierd - for some reason my brain isn't a fan of the multiple PICAXE solution. Perhaps it's because I'm "wasting" processing power in a certain way...?

It's a very good idea, and one I would use if it came to it - for some reason I just can't seem to "like" it :LOL::LOL:
 
I think the easiest way to describe my (completely bizarre) mindset is I like to have "dedicated" solutions - so a central "processor" - a microcontroller etc. - which does what it's designed to do, process & controll; and specialised "independent" chips, such as the HT1632C, doing specifically what it's designed for... Please don't ask me why, it's just the way I seem to think!
 

hippy

Technical Support
Staff member
The key to becoming comfortable with distributed solutions is to think of remote processors exactly like dedicated chips.

In fact many of those dedicated chips will contain software and microcontrollers, it's just that we don't think of them as being processor systems.

So whether a PICAXE has shift registers, a string of RGB LED controllers, a MAX7219 or a load of other PICAXE chips connected; it's all the same thing in many ways. It's just that with a PICAXE as the dedicated chip one has to program it first. But once that's done it can be treated as much as a black box as any other hardware can.

Of course, with a PICAXE master and PICAXE slave, one can tune the two for the best all-round performance and in doing that one blurs the separation.

But that's often over-optimisation. Design something good enough to work as the bridge between the two, then approach the two sides separately; master talking to the bridge, the slaves receiving what comes over it. It then falls back to being two separate projects.

Plus the meta-project of what that bridge is. It's trying to do all three together, as a whole, which is what leads to confusion and things seeming far more complex than they actually are.
 
That does make a lot of sense, Hippy... :) I suspect it's just my systems engineering mindset coming through into my hobby - too much work and not enough play 😂
 

Buzby

Senior Member
... Just trying to figure out what goes where, even before trying to wire that up and get it right, is hard enough. ...
The orrery display was 'auto-designed' by a VB program that calculated all the relevant wiring and LED positions. There was no way I could have even contemplated planning that by hand.

The pinball was done exactly the opposite way !. The APA102 LEDs were all put in place and wired by the easiest route, with no plan at all. A simple bit of code was then used to find out where each LED was on the buss.

Two extremes, but I preferred the second one !
 

grim_reaper

Senior Member
Just in case your offer of 3D printed parts doesn't work out for some reason, there's always the relatively simple thinning of the plywood. I presume 'standard' LED mounts could be used if the ply was thin enough - so if you've got access to a drill stand, you can enlarge all of the holes up to 80% of the way through from the back of the panel.
 
Top