16x16 button matrix using two 4067 multiplexers

Hello,

I am currently considering an approach to efficiently read up to 256 buttons using two 4067 multiplexers. Please refer to the image below:

The proposed method involves the following steps:

  1. The first multiplexer connects one column to the ground.
  2. The second multiplexer reads each of the 16 rows for ground connection (using input_pullup).
  3. The first multiplexer then connects the next column to the ground.
  4. The second multiplexer again reads each of the 16 rows for ground connection (using input_pullup).
  5. Repeat the above steps for all columns.

I would like to know if there are any potential issues or limitations with this approach. Since I have not come across similar examples, I have some doubts regarding its feasibility.

Would I need diodes for better isolation, or will the multiplexers alone provide sufficient isolation?

Thank you in advance for your valuable feedback!

If 2 buttons or more are pressed simultanously, what should happen?

1 Like

Hi Railroader
In the event that two or more buttons are pressed at the same time, I would expect that all of them are detected as pressed. However, I am concerned about the possibility of ghosting and false positives.

Considering that we are only connecting a single column to ground at a time, it is not immediately apparent to me how these issues could arise.
But I could be overlooking something....
Thanks

Several buttons detected... Then each button needs a diode. This has been shown here before.
Make a search for "Arduino + matrix keyboard"!

As mentioned earlier, after searching I have been unable to find specific examples that involve the use of two multiplexers to isolate rows from one another. This particular configuration seems to be less common or documented.

Whatever way You use the multiplexers each button needs a diode. How to do that was the intention to point at.
Use a Mega and drop the multiplexers is a suggestion.
What is "isolating" supposed to tell?

If we're not applying voltage to the matrix but instead connecting and disconnecting the ground to one row at a time, and only connecting one column to the GPIO at a time, I'm struggling to understand why we require diodes.

When reading one row, the remaining rows should be disconnected or 'hanging,' which is what I meant by 'isolated from one another.

I don't see anything wrong with your reasoning or design.

Without isolation diodes, you can get ghosting as soon as 3 keys are pressed simultaneously. It doesn't make any difference how you scan the matrix or what type of chip you use. Not all combinations of 3 buttons cause ghosting. If they are in the same column or same row, no problem.

Key rollover - Wikipedia.

I would recommend 2x PCF8575. Only 2 pins (SDA, SCL) used and even those can be used for other i2c devices also.

Thanks @PaulRB @jim-p @Railroader For your feedback!
I'll experiment with the PCF8575!
Happy Weekend to all

You need to use diodes definitely. But There is only one thing that no one mention;
and is; you have to find the way to control the two muxes independently so one of them stays reading only one row (or pin) at any given moment, while the other reads 16 consecutive pins (or columns), and for that you need four extra control pins on the Arduino (that's eight pins!).
I dont know if is possible without those four extra control pins for the second mux, I tried unsuccessfully.
It took me a long time to figure that out, but definitely works. (256 buttons) with only nine pins.
The two Z's I/O on the multiplexers must be connected like this:
One (rows mux) goes to common GND, and the other (columns mux) connects to any digital pin as INPUT_PULLUP.
I can post my Arduino sketch sometime in the future.

And we can help better when you do.

But I don't immediately understand why you cannot control the two multiplexers independently.

have to find the way to control the two muxes independently

If you are working with the schematic you posted, it seems a simple as not changing GPIO1..GPIO4 whilst you riffle through all combinations of GPIO5..GPIO8.

a7

Hello All, thanks for your feedback, PCF8575 worked will in the end, and I did use diodes.
Much appreciated

Glad PCF8575's work for you. I need to learn more about them.

But for Alto777, I'd like to add, that the only reason why I said that you have to control the muxes independently ( correct me if I'm wrong ) is because multiplexers share the same four control pins, ( S0~S3 -----> Arduino pins 2~5 or whatever, in the case of the 4067's ).

So it doesn't matter if you have only one mux connected, or six muxes connected, they are all switching at the same time, and reading all the same pin at any given moment, because they share the same four arduino control pins, and you only know what multiplexer is, because you are reading the microcontroller's analog or digital input that is connected to.

In the case of the matrix, we all know that you have to enable only one row at a time, on mux 1, while mux 2 is reading (or switching) to 16 consecutive columns independently, and then repeat the process for the next row.

The only way, for what I see, to achieve this, is using four extra control pins for the second mux in order to control what pin is been reading at any moment.

Am I missing something?, if there is any other way to accomplish this with code, let me know, because I don't know..

Yes

@pablomoreno has not posted a schematic. @britFrog posted one in the original post.

By the way, I know the topic is solved, but for those who want to know, they say that you don't have to use 256 diodes, but only sixteen at the beginning of the columns.

It will protect the mux pins of reverse electricity, but don't know about ghosting, you have to try.
If you use INPUT_PULLUP mode, you don't need the resistors either.

I'll post schematics of what I did (if possible), but it was tested with only two buttons, many cables on a breadboard, and two 4067;s.

Of course you aren't. As @PaulRB points out, I thought this was your thread, somehow, and your schematic. It must be the similarity of your ID and @britFrog's. :expressionless:

And it is so obvious in this case, the solution to use, if you have them to spare, is separate address lines for the two (or six) mixes.

The I/O expander idea cuts that requirement down to seize.

Sry for my confusion.

a7

I don't see how that can prevent ghost detections.

In the schematic you posted, the rows 1 to 4 are pulled low by resistors. I presume the columns 1 to 4 will be pulled high by pins 9 to 12, each in turn, to scan the matrix.

Imagine that, at a given moment in time, pin 9 is high to scan the buttons in column 1.

If only button s1.1 is pressed, then row 1 will be pulled high, and so pin 4 will be pulled high and the button press is detected. Rows 2, 3, 4 are still pulled low, so pins 5, 6, 7 will read low, and the Arduino will know that buttons s1.2, s1.3, s1.4 are not pressed.

But what if button s2.1 is also pressed at the same moment? Without a diode in series with s2.1, column 2 will also be high. The diodes on the columns won't prevent that.

Now imagine a third button, s2.2, is also pressed along with s1.1 and s2.1. This will make row 2 and pin 5 high, making the Arduino believe that s1.2 is pressed, even though it is not. A ghost press!

Diodes on the columns might protect the output pins controlling the columns, from short circuits, if they are always either high or low, when multiple buttons are pressed. However, normally the pins controlling the columns will be put into input mode, not output/low, when they are not high, so short circuit will not be a danger.

The diodes are not needed to protect the 4067. It's input & outputs are bi-directional and current can flow in either direction. Other types of multiplexer are not bi-directional, and those may need protection diodes.

1 Like

Here's the tl;dr version:


The dots are closed switches. The open circle is an unpressed or open switch.

No diodes or anything else anywhere in the circuit can keep the open circle matrix position from appearing as if there were a closed switch there.

HTH

a7

1 Like