Wiring keypad in cube instead of matrix

When doing investigation on keypads/keyboards I realized all implementations are wired in matrix forms (columns and rows). This is a 2D approach, but we can take it a step further and use 3 dimensions (or more). This can give us more keys with the same amount of pins, depending on the number of keys / switches you have.

Here's a quick mockup.


Notes:
It might have some mistakes, as I haven't simulated it.
For the amounts of pins in the diagram, you would actually still get more keys with a 2 dimensional layout, but this was easier to demonstrate. By adding 2 more pins it would actually give more available keys.

The idea basically would be to scan both the columns as before, but adding a scanning of each layer. In the example above, we would scan;
iteration 1: set layer 0 to HIGH, layer 1 to LOW, set column 0 to HIGH, column 1 to LOW. Check rows.
iteration 2: set layer 0 to HIGH, layer 1 to LOW, set column 0 to LOW, column 1 to HIGH. Check rows.
iteration 3: set layer 0 to LOW, layer 1 to HIGH, set column 0 to HIGH, column 1 to LOW. Check rows.
iteration 4: set layer 0 to LOW, layer 1 to HIGH, set column 0 to LOW, column 1 to HIGH. Check rows.

As mentioned, depending on the number of available pins, the optimal number of dimensions varies.

Example 1:
If we have 6 pins, we would have 9 (3x3) available keys in a matrix layout.
Using a 3 dimensional layout we can only get 8 (2 x 2 x 2).
Matrix layout is better in this situation.

Example 2:
If we have 8 pins, we would have 16 (4x4) available keys in a matrix layout.
However, using a 3 dimensional layout we can get 18 (3 x 3 x 2).
3 dimensional layout is only slightly better, most likely not worth the effort.

Example 3:
If we have 12 pins, we would have 36 (6x6) available keys in a matrix layout.
However, using a 3 dimensional layout we can get 64 (3 x 3 x 3).
3 dimensional layout is vastly slightly better.

Taking it 1 step further; 4 dimensional layout with 12 pins gives us 81 keys (3x3x3x3).
This is more than double of the matrix layout. However, the extra complexity might make it not viable.

Pros and cons:
1-dimensional (a switch connects to a pin individually) and 2-dimensional (matrix) approaches are much simpler (and probably cheaper). They are also easier to solder, take up less space and are easier to troubleshoot.

N-dimensional approaches lets you use your more keys for the same amount of pins. They are slower too, as you need to scan layer by layer now, but for a low number of layers it's probably not an issue. I doubt that having more than 3 layers might be a nightmare to solder everything and still keep it relatively compact.
In the example above I used AND gates, which can be implemented with transistors, which are cheap, but if you use small micro controllers, then the price alone might perhaps make it more expensive. That will also take up a lot more space.
If you're just making a big box with a lot of buttons and don't care about the case being big, this might be viable for you.

Either way, I'm curious, has anyone ever done this and are my assumptions correct? Any other reasons why this isn't used?

As common switches only have two terminals they can only be connected to two dimension planes. Okey, 2 switches can share one "plane".....
Using 6 I/O, like in Your example, a 2 dimensional rigging handles 9 buttons, one more then the 8 in Your example.

Isn't that what I wrote?


In the image my 1st post, I have switches with 2 terminals, what's the problem?

Sure, you can Charlieplex a keyboard too. No gates or transistors, just diodes.

You could have a 3x9 matrix, and envision folding it up into a 3x3x3 cube mechanically, and still keep the 3x9 wiring going.
Still uses the same number of pins.
Physically, I don't have a need for a cube of buttons, and think it would be awkward to use, having to move you hand in and out of the cube to transition between layers. Maybe you have something else in mind.

The idea was to have the switches layed out in a 2D matrix, but have them wired as a 3D cube to save pins.
I just wanted to share the idea, I don't really have a need for it myself.
I'm guessing that, most likely, the extra costs of the components would make it cheaper to just buy an additional micro controller. But still, I thought it was an interesting idea to explore.

Cool. Never heard of charlieplexing before, very interesting.

So really, you're adding extra electronics as sort of an enable line for what could be envisioned as additional layers, or sections of the 2D matrix.
Could be as simple as 74HC125 gates, where the switch is allowed to drive the matrix when the output is enabled. Or something larger, like the equivalent of 74HC244, with 1 enable to support 8 Ins & Outs.

Exactly.

Nice, those were actually cheaper than I expected, perhaps it's economically viable anyway. Interesting.

But 3 pins have 8 different options. With multiplexers and demultiplexers you could drive an 8x8 matrix with 6 pins.

Or you could use four pins to drive two shift registers: Clock, Data Out, Data In, and Latch. That would get you 64 keys with four pins. :slight_smile:

That's actually a great point. Haven't seen any design use those. As each column is scanned 1 at a time, a demultiplexer can easily be used for that, so that's kind of a no-brainer. But what would you use a multiplexer for? Multiple rows can be activated at once for the same column and you want to detect each of them, so I don't really see how you would do that.

Are you sure about that?

Instead of demultiplexers, decoders can also be used I guess.

Yes, I'm sure you can Charlieplex a keyboard. If you can turn on a single LED that way, you can select a diode/switch pair in exactly the same way. Thought experiment - Charlieplex a bunch of LEDs. Now put a switch in series with each LED. When you select a given LED, current will flow if and only if the switch is closed. Now measure the impedance across the two select lines you used to select that LED. But the driving circuit has to be reconfigured constantly to allow for the bidirectional polarity of opposing diodes.

OK, well you need to specify that by "just diodes", you actually meant LEDs.

And preferably green ones, not red!
No, I take that back. Green LEDs are likely not to work, with threshold over 2.5 V. By the same token, red LEDs are the correct ones to use. :+1:

Why is that? Is the higher voltage drop of a led, compared to other types of diodes, required?

From what I understand, you can't, in most applications, because both musical keyboards and typing keyboards need to be able to deal with multiple keys pressed at once. With Charlieplexed key matrices, you can't avoid "phantom" key presses appearing when multiple keys are pressed. So only applications where it would be the case that only one key is ever pressed at once would Charlieplexing be used. Am I right?

In my opinion, this way of connecting is very complicated and unjustified. If I needed a lot of buttons I would use several 74HC595 registers connected in series and 1 Arduino pin as input. Thus, each added 74HC595 adds 8 buttons and the number of required Arduino pins remains the same - 3 for registers control and 1 for reading a pressed button, ie. total 4. Or I would use an IR remote control connected with a cable and in this case I will need only 1 pin - with 2 wires from the IR diode to 1 pin of the Arduino and ground connection.

Without diodes, you are right. But with one diode for each key, you would have full n-key rollover.

Yes.

OK, I was waiting for aarg, but I will reveal the secret. "Phantom" paths. :sunglasses:

That's it. You can avoid it by selecting the LED voltage such that one LED drop (1.8 V) pulls the logic down (or up if you use it that way) past the threshold, but two LED drops (3.6 V) will not.

For Charlieplexed LED displays, you may have a problem with red LEDs, or with higher than 5 V.

Well, your opinion. :roll_eyes:

Ah! Latecomer!

Yes, with red LED diodes. :grin:

Actually, without diodes, you lose half of the switch positions. :astonished:

Charlieplexing is based on the use of diodes (and thresholds). It does not work for incandescent bulbs.