Hand Wiring Switches and LED Backlighting questions

User avatar
rklm

14 Mar 2014, 03:32

I am putting together the resources to construct a custom 60% board at the moment.

I have worked out a layout which I feel doesn't stray too far from my current keyboard usage: http://www.keyboard-layout-editor.com/# ... 39f70cf994
If you guys have any suggestions, I would love to here them.

I have a 3d model for the plate (which incorporates a cavity for the wiring and space for a teensy2.0): https://tinkercad.com/things/irhM1hX1m7v (still editing the .skp that I exported this from).
The local campus library has a Makerbot 2 with an 11x6x6 printing space, and I will most likely use it to print my model with either ABS or PLA. I have two sheets of 1/16" steel which I am going to layer and use as the bottom plate.

When I am done, I will post a full build log, however before I can really continue I need to figure out one or two more things.

I would like to add backlighting, but I am having some trouble finding the right LEDs and resistors.
Most of the white 3mm through-hole LEDs I have found are something like 2.8-3.6V 20mA. When I plug those numbers into http://led.linear1.org/led.wiz with the teensy2.0's 5v source voltage and 75 LEDs (one per switch), I get about 1500mA draw (with 82ohm 1/4watt resistors)... which would appear to be 1000mA more than the USB bus (or the teensy for that matter) could handle.
The LEDs that were recommended on /r/mechanicalkeyboards have about the same specs too: http://www.ebay.com/itm/50pcs-3mm-Pink- ... OU:US:3160

How should I go about wiring up LEDs to the teensy without destroying electronics?

Also... other suggestions, for reasons.

User avatar
Broadmonkey
Fancy Rank

14 Mar 2014, 08:03

The normal way of adding that amount of LEDs, when you only have 500mA is by controlling them with PWM, that way you can cut almost 3/4 of the power consumption from the LEDs (IIRC).

kile

14 Mar 2014, 08:40

Broadmonkey wrote:The normal way of adding that amount of LEDs, when you only have 500mA is by controlling them with PWM, that way you can cut almost 3/4 of the power consumption from the LEDs (IIRC).
That would work, but only if you group the LEDs into at least 3 groups and then successively turn one group on and all the others off. Make a sort of grouped running LEDs circuit. If you have PWM on all the LEDs at the same time you will drop the average current, but the peak will stay the same.

I suggest getting a few samples of different brand LEDs and see how bright they are with less current. Chances are, some of the LEDs will be bright enough at 5mA especially if you have 75 of them to combine their light. At 20mA they will probably be too bright anyway.

User avatar
rklm

14 Mar 2014, 19:39

These ones here: http://www.wayengineer.com/index.php?ma ... b6a371d3da
state that their operating current is 5-19mA. Does that mean that some of them might run at 5 and some might run at 19?? Or is there a way for me to drive them at the lower current?

User avatar
rklm

14 Mar 2014, 20:46

I read up on controlling PWM on the Teensy (https://www.pjrc.com/teensy/td_pulse.html) and it looks like the way to go.

I suppose the plan is now to wire up my matrix of 13x6 with 20mA/3.6v LEDs and 82ohm 1/4watt resistors to one of the PWM pins on the Teensy (I will most likely have a number of pins available, since I am only using 19 for my switch matrix) and run them at a pulse width of 25%.

That aught to bring the LED power consumption down under 400mA, which leaves 100mA for the Teensy (I think I read somewhere that it uses 50mA, correct me if I am wrong).

That wraps up pretty much all of the hardware problems I had, but opens the door to some new software problems I will have to work out :S

The guy who works in the 3d printing room at the library will be back on the 18th, so that gives me a couple days to work out any more kinks before I can really get started on the project. I have pretty much everything else I need to start soldering this bad boy together.

kile

16 Mar 2014, 12:34

That will not work for at least two reasons. You can not directly drive 75 LEDs from one AVR pin. An AVR pin is capable of at most 40mA, but even going over 20mA is probably not safe for the pin in the long run. You can, however, use PWM to drive a MOSFET which will then turn the LEDs on and off. Which leads to the second problem: as I already mentioned in the previous post, PWM only lowers the average, not the peak current. While the PWM signal is high, the current draw will be 1500mA, and then it will drop to 0mA while the signal is low.

As I said, the best solution to this is to use lower current per LED. LEDs are not on/off devices - they will start emiting light at much lower currents. The 20mA probably means the current at which the LED will have peak brightness before any more current starts to damage it.

So, drive the LEDs at 5mA and see how bright they are. If they are bright enough - you have your solution.

The LEDs you linked should work, but they are not flangeless - meaning they have a small ring around their base that you will need to sand off if you want them to sit well in the CherryMX switch. Not a problem, but it could take a while for 75 switches.

User avatar
matt3o
-[°_°]-

16 Mar 2014, 13:21

couldn't you PWM the LEDs in batches? only half or 1/3 or 1/4 at any given time.

User avatar
Muirium
µ

16 Mar 2014, 13:33

Are you after simple, even backlighting? If so, I'm sure I read that people have patched a whole load of LEDs onto a keyboard's power rail before, wired up right so they all share the current.

Pulse Width Modulation — aka flicker — annoys me quite a bit. I don't mind it on a few keys here and there, but a large area of them pulsing away really distracts my eyes. The only fundamental advantage to a PWM matrix of LEDs is that you can address them individually and do fancy light shows, like the Ducky Shine 3. But if you want a practical light, a level voltage is the better way.

User avatar
rklm

16 Mar 2014, 21:12

On the Teensy, is there a way to directly reduce the current without PWM?

Also, I am using a matrix of 19, so I suppose given that the teensy2.0 has 24 pins I could split the LEDs among the remaining 5?

That would be 15 LEDs per pin, and 75mA per pin at 5mA per light.

This seems so complicated... how do keyboard manufacturers manage to do this?!

User avatar
Muirium
µ

16 Mar 2014, 21:16

They don't. I'm pretty sure that they just go by the main USB power rail, except for the rare full LED matrix keyboards that are beginning to show up now. But I'm no engineer, so bear that in mind!

User avatar
Broadmonkey
Fancy Rank

16 Mar 2014, 22:09

Okay okay.. what I meant was to control the whole 75 leds with PWM. You can not control it from one PIN, this is not possible from just about any controller, since you can only draw so much current from one PIN.
If you use PWM and you set it up to have the rising edge on all PINs you have connected the LEDs to, it would still draw too much current since the peak will be too high, that is why you want to "spread" the rising edge out on as many groups of LEDs as possible (this is just straight from the head, so it might not be true, so please correct me. Also if you can explain it better)
So what you want is to create as many groups of LEDs as possible, if not have a single PWM pin for every LED, this is not however possible from a Teensy, so you would have to get something to help you. The answer?

Well, an LED driver ofcourse!
This is what is used in the MAX keyboard Blackbird: TLC59282

I haven't look much into it, since I am not THAT fussed about LEDs. But I know this is how large keyboard manufacturers do it.

User avatar
Soarer

16 Mar 2014, 22:17

Yeah, well, they often just switch the LEDs with a FET that can take the current.

PWM and bigger resistors have the same effect - reducing average current, and reducing brightness. PWM might not be the best choice if peak current is still over the 500mA USB limit!

Don't forget, manufacturers shave every cent off costs. So they use the cheapest LEDs they can (and waste your power...). Ultrabright LEDs can give a nice glow at less than a mA each (or maybe a tad more if they have to shine through a not very transparent keycap). Think resistors in the 1k to 10k range :) Key point: when an LED says it's 20mA, that's 20mA for its rated brightness (lumens/millicandelas) and other parameters; you can run less.

Teensy has power limits from each pin (40mA?), from each port (100mA?), and for the whole device (500mA?). All must be respected.

Do you want to be able to dim them from your firmware? Then PWM is the simplest way to go. Switch them? Still need at least one pin (plus FET), so might as well make it a PWM pin even if you don't use the PWM. Always on? No problem, just wire to USB 5V.

Deck published their schematics for a couple of keyboards - http://www.deckkeyboards.com/support/de ... -schematic - they use a resistor DAC to set brightness to a different levels without using PWM.

User avatar
rklm

17 Mar 2014, 01:34

The brightness of the LEDs doesn't really matter too much for my purposes (as long as they are visible) and they can all be on at the same time (all the time).

The case I am building this into is going to be extraordinarily streamlined, so the simpler the wiring the better (between the LEDs and the matrix, I am going to have a lot of layers and only a few mm to solder in).

Is it possible to reduce the draw from the LEDs to 5mA via resistors alone?

Say I use LEDs that are 3.6v @ 20mA spec, but I treat them like 5mA LEDs and use 330 ohm resistors (like these http://www.amazon.com/E-Projects-330k-R ... 1%2F4+watt ), would they actually only draw the correct amount and work on the pins of a teensy?

User avatar
rklm

17 Mar 2014, 01:38

Or maybe it would be best to just use a short extension and tap right into the 5v on the USB cable?

User avatar
Soarer

17 Mar 2014, 02:39

For 'on all the time' you can wire to one of the two +5V pins on the Teensy and draw up to the USB limit (minus a bit for the Teensy); no need to extend and tap the USB cable itself.

Even 5mA per LED would be too much really (well, how many LEDs?). Aren't you still thinking about the mA rating wrongly? That's just the nominal rating, and you can give it more or less current by changing the resistor as you desire.

You can find 10000 mcd brightness LEDs for about $5 for 100. They are, as you would say, '20mA' LEDs, but at that current they would be far too bright for backlighting. They should run fine with large resistors at (possibly much) less than 1mA, giving the right brightness level (experimentation required to get it just right).

User avatar
rklm

17 Mar 2014, 03:01

The keyboard community is so awesome, this thread has been so helpful.

I am only using 75 LEDs (one per key) so I figure as long as I stay under ~400mA I would be alright (not sure of the power consumption of the Teensy, but I thought it was below 100mA), and 75x5mA is only 375mA.

I do plan to use cherry mx LED color changer clips (just got them from the recent massdrop), but I doubt they will reduce the brightness of the LEDs that much.

If they will be bright enough running at ~1mA, then I suppose I should use a 1.5k 1/4watt resistor like this: http://www.amazon.com/E-Projects-1-5k-R ... 1%2F4+watt

That would bring the power consumption down to 75mA for LEDs on the whole board.

Then I'll wire them to the 5v on the teensy (which I assume is a direct connection to the 5v pin in the mini-usb header?)

User avatar
rklm

17 Mar 2014, 22:36

Gave my 3d model (https://tinkercad.com/things/k4Cn3ejGuAP) to the library, and it is being printed now.

Once I pick it up, I start a build log thread.

jeffkoch

17 Mar 2014, 23:14

Soarer wrote:Yeah, well, they often just switch the LEDs with a FET that can take the current.

PWM and bigger resistors have the same effect - reducing average current, and reducing brightness. PWM might not be the best choice if peak current is still over the 500mA USB limit!
<snip>
Do you want to be able to dim them from your firmware? Then PWM is the simplest way to go. Switch them? Still need at least one pin (plus FET), so might as well make it a PWM pin even if you don't use the PWM. Always on? No problem, just wire to USB 5V.
<snip>.
If you scan the rows and columns, you could illuminate any individual LED or set of LEDs. Perhaps have each key light when pressed, or backlight the entire board, and have the key extinguish when pressed.

User avatar
Muirium
µ

17 Mar 2014, 23:18

Like this:
Not my cup of tea. But reactive mode has its charm, compared to the others.

User avatar
Soarer

17 Mar 2014, 23:39

jeffkoch wrote:If you scan the rows and columns, you could illuminate any individual LED or set of LEDs. Perhaps have each key light when pressed, or backlight the entire board, and have the key extinguish when pressed.
Well, of course, but you'll be adding a fair amount of circuitry and/or specialised driver chips to do it!

Various ways to skin that rat... http://geekhack.org/index.php?topic=26751.0 ;)

User avatar
rklm

18 Mar 2014, 01:27

Ok... well... I did briefly consider wiring the LEDs ~through~ the switches... so that when they are actuated the light would come on... but there are probably complications that I am not foreseeing, and there would probably have to be another set of resistors to prevent current from making it's way into the teensy through the switch...

But if someone wants to see that in this build, and can explain a wiring pattern that would be safe for all the electronics... that might be enough incentive for me to figure it out.

User avatar
rklm

18 Mar 2014, 01:34

This was what I was imagining originally (without any sort of light-show work)

Blue connections are the negative from the LEDs, purple rectangles are 330 ohm resistors
Red connections are for the switch matrix, brown rectangles are diodes
Green connections are from the switch to the teensy, the top connections are a ribbon cable (like this: http://deskthority.net/workshop-f7/the- ... t1067.html )

Sorry for the inexcusable ugliness... this was only meant to be a reference for myself :P
Attachments
Minimal Animal Wiring diagram Complete.png
Minimal Animal Wiring diagram Complete.png (68.52 KiB) Viewed 17481 times

User avatar
rklm

18 Mar 2014, 03:57

Maybe something like this?

The LED would be connected to 2 resistors, so it would glow dimly, until the switch makes a connection that bypasses one of the resistors so it can run at its maximum spec.

I am such a good graphical artist XD
Attachments
I won't blame you for not understanding this.
I won't blame you for not understanding this.
switch+led wiring.png (5.17 KiB) Viewed 17471 times

User avatar
Muirium
µ

18 Mar 2014, 10:57

I understand it. The bit I question is whether the Teensy is going to see this as on or off when the switch is open and closed. The lower resistor makes the open state dubious, and the left resistor has the same effect on the closed state. Guess it's worth a test on a breadboard.

User avatar
Grendel

18 Mar 2014, 23:16

matt3o wrote:couldn't you PWM the LEDs in batches? only half or 1/3 or 1/4 at any given time.
I believe the G710+ does that, cycling through quadrants. Ducky may too, their USB descriptor claims 300mA power use. Doesn't really help w/ the flickering :/ Driving 1/4 of the LED's at a time is possible but requires some more thinking about how exactly you shift through the quad's -- probably via an external 4-way switch that distributes the PWM signal to the MOS-FET's (could get its clock signal from TOV.) If you drive the timer w/ 2MHz (/8) (resulting in a ~8kHz cycle), the cycle time of the segments would be ~2kHz, flicker shouldn't be too bad.

Edit: it's kind of pointless tho, since the LED's can be on max. 1/4 of the 500us cycle so you have to drive them w/ more current to compensate for the loss of 3/4 on-time ;)
Muirium wrote:Pulse Width Modulation — aka flicker — annoys me quite a bit. I don't mind it on a few keys here and there, but a large area of them pulsing away really distracts my eyes. The only fundamental advantage to a PWM matrix of LEDs is that you can address them individually and do fancy light shows, like the Ducky Shine 3. But if you want a practical light, a level voltage is the better way.
While in general I wholeheartedly agree here, I usually use 2MHz based timer driven PWM where I can (Frosty Flake, CMS Demo mod, Scorpius 32 mod, SmallFry test board) since it's easier to implement and it's very smooth -- no flicker visible to me during normal use (and I'm VERY sensitive to stroboscopic effects. Gave away a 710+ and DS3 because of this.)
Last edited by Grendel on 19 Mar 2014, 02:41, edited 1 time in total.

User avatar
Soarer

19 Mar 2014, 01:00

rklm wrote:Maybe something like this?

The LED would be connected to 2 resistors, so it would glow dimly, until the switch makes a connection that bypasses one of the resistors so it can run at its maximum spec.
Trouble is, although that would change the current flowing through the LED, there isn't an easy way for the CPU to read the switch state any more! And even if that problem is solved, making it work correctly with multiple switches pressed probably wouldn't be viable.

User avatar
rklm

19 Mar 2014, 01:19

Soarer wrote:
rklm wrote:Maybe something like this?

The LED would be connected to 2 resistors, so it would glow dimly, until the switch makes a connection that bypasses one of the resistors so it can run at its maximum spec.
Trouble is, although that would change the current flowing through the LED, there isn't an easy way for the CPU to read the switch state any more! And even if that problem is solved, making it work correctly with multiple switches pressed probably wouldn't be viable.
That is pretty much what I figured. Just a wild idea :P

I will probably just wire up an independent matrix with 330 ohm resistors to keep the draw under 400mA. Positive leads to the 5v on the teensy, negative to the ground. Clean and simple :)

Also, the case 3d print failed (it was too wide, and the cooling PLA curled the edges in).

I talked to the guy who runs the 3d printing room at the local library (I have a pretty awesome local library let me tell you), and he recommends that I just laser cut the layers from acrylic.

This is turning out more and more similar to Matt3o's build the more I fiddle with it XD

Hopefully tomorrow I will have the vector files together for the laser cut layers, and I can get the case together and show off some pics.

I will show off the source of my switches as well, it is a surprise too

User avatar
rklm

20 Mar 2014, 19:25

A small teaser before I get my LEDs, finish the project, and upload my build log:

Image





(I guess if you are really adamant about seeing this project you could just look at the stuff I put on imgur XD )

User avatar
rklm

23 Mar 2014, 17:43

I have everything wired up (except for the leds, waiting for them to ship from China), but now I am having some programming problems.

Before I start modifying hasu's code for the teensy, I wanted to test the matrix by running a modified "HelloKeypad" script (from the keypad library), but so far I cant get anything to show up on the serial monitor.

I have inspected the whole board for gratuitous wiring errors a number of times but I can't find anything visible that would keep ALL the keys from functioning.

Any advice? Test software or the like?

User avatar
rklm

24 Mar 2014, 13:44

I took a hard look at the wiring done for the Brownfox and Lowpoly's Apple m0110 again and noticed that I had wired my diodes in series.
:roll:
Went back in and added a wire to connect all the diodes to, so that their connection on the rows would be in parallel.

After fixing that bit, I can't find anything else that seems wrong. I will post pictures later.

I wrote a small piece of software that turns the yellow LED on the teensy on until a connection on the matrix is made, and it works when I jump any of the row pins to any of the column pins, but it doesn't work when I actuate the switches.

I don't think that the switches are broken, and I don't think it can be a wiring error anymore, so I am not sure what is going on.

My assumption is that the teensy is putting out 3.3v on one of the pins and lighting up the LED if it hits a ground (it works when I jump from one of the pins to any ground) and it is sending the 3.3v the wrong direction for the diode.



I am going to test the connections with a voltmeter later and let you guys know what I find.

Post Reply

Return to “Workshop”