Button matrix that needs no diodes... WRONG.

Button matrix that needs no diodes... I thought, but was WRONG.

The matrix has X rows and Y columns with a switch at each junction.
Start with all pins moded INPUT_PULLUP.
Now make 1 column pin OUTPUT LOW and read 1 or all of the rows as a port read. Set the column pin back to INPUT_PULLUP.
Repeat for all of the columns.

Me in another thread where the notion struck me:
I think that if a button matrix has all the pins but 1 column pin at a time pinMode(x,INPUT_PULLUP) and that 1 pinMode(x,OUTPUT) and then set LOW in the DDR register. Each row can read the column, if the pins are on the same port then 1 read gets them all. When the rows are done reading, set the pin back to INPUT_PULLUP and make the next column OUTPUT LOW.

As far as I can figure, this matrix needs no diodes to get multiple keypresses right. The LOW column pin only drains rows with a closed switch to it. There is no power path up, only drains down.

http://forum.arduino.cc/index.php?topic=588250.new#new

Assuming I understand... There would be no way to wake a sleeping processor.

You do not need diodes ...

as long as you never intend to have more than two buttons simultaneously pressed. :roll_eyes:


Or you know and plan for which buttons may be simultaneously pressed and ensure they are always on different rows/ columns.

Without diodes you can only handle a single press at a time.

If two diagonally arranged buttons are pressed together there's no way to distinquish from the opposite
diagonal pair.

Its when you know the buttons will all be on the same row (or same column) that you can handle correctly
without diodes.

In theory with rapid scanning you can catch each press or release individually and know the correct buttons
from the history, but that's fairly compute intensive and you then have to do explicit debouncing rather
than rely on the scan to debounce for you. This is done, I think, in hardware keyboard scanning chips as
saving 104 diodes is a significant cost saving.

The 3 buttons could look like 4.

If two diagonally arranged buttons are pressed together there's no way to distinquish from the opposite
diagonal pair.

When only 1 column is LOW at a time, what path to ground do 2 of the row pins get right then?

Any 2 on 1 row with 1 on a column with 1 of the others would bug, it needs diodes.

Ah, I'm thinking of a display matrix (bulbs), not a push button one...

With a scanning button matrix scanned row by row, having two buttons on the same colum
means the two rows are commoned and cannot be distinguished when further buttons are pressed
as Paul__B pointed out.

MarkT:
This is done, I think, in hardware keyboard scanning chips as saving 104 diodes is a significant cost saving.

I think "normal" keyboards have groups of buttons where only one button press from given group may be recognized. "Player" keyboards are able to register more button pressed at once but AFAIK the amount is still limited.

I'd want "matrix" to be multi-button. It needs diodes.

The every pin but 1 as INPUT_PULLUP lets the rows read without changing mode, only columns change and an UNO can port read up to 6 rows at a time. That could be read really fast.