I'm writing some microcontroller software to read a mechanical keyboard, which has diodes to prevent keys from interfering with each other.
The keyboard has the keys set up with row outputs and column inputs that can be scanned; basically the boxed area in this schematic, but with many more keys:
R1, and columns
C1 are GPIO pins on my microcontroller, AT90USB1286 (8-bit AVR).
I have limited understanding of actual electronics and don't really know how to use diodes effectively. I believe I could scan the keys using the following (naive) process:
R0to output high, all others low
- Read all
Cnpins to find out which
R0keys are pressed
- Repeat for
For that to work, my understanding is that each column would need to have a pull-down resistor to prevent floating signals when no column keys are pressed. My microcontroller has optional internal pull-ups on every GPIO pin but no pull-downs, so I would need to add them myself. I don't believe I could use the pull-ups and change the scanning row output to low because the diodes will prevent the low signal from reaching the column input.
However, I am wondering if I could swap the row and column roles:
- Enable internal pull-ups on all
C0to output low, all others high (or hi-z?)
- Read all
Rnpins to find out which
C0keys are pressed
- Repeat from 2 for
This would mean that my schematic would use
R1 as inputs with pullups enabled, and
C1 as outputs; each one would output low when scanning it.
My primary concern is that the diodes will somehow prevent the low output from overriding the pull-ups, or something like that.
Does this approach work? Should I output high on the column pins that I'm not scanning, or is it okay (or better) to make them hi-z/inputs?