-- Leo's gemini proxy

-- Connecting to shit.cx:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;

shit.cx


Keyboard Circuit


2020-12-28T00:21


Soon I'll be wiring up the keyboard, so I figure it must be time to explain the circuit.


I use a Teensy¹ microcontroller with the TMK² firmware to drive the circuit. TMK scans the switches, then sends the state of the switches to the host while presenting itself as a standard USB HID keyboard.


To maximise the number of switches that can be driven from the very finite pin-count of a Teensy, the switches are arranged into a matrix of rows and columns. As you increase the size of the matrix, you gain pin-usage efficiency; a 8x8 matrix needs 16 pins to drive 64 switches where a 2x2 matrix needs 4 pins to drive 4 switches.


The matrix is scanned a little like this:


for r in rows {
  set_high(r);
  for c in columns {
    is_high(c) && send_key(r,c);
  }
  set_low(r);
}

An overly simple circuit might look like this:


           C¹       C²
           │        │
 R¹──┬─────◠──┐     │
     ●▁▁●──┤  ●▁▁●──┤
           │        │
 R²──┬─────◠──┐     │
     ●▁▁●──┘  ●▁▁●──┘

You then assign letters to the switches. In this example, we will map them as such:


R¹C¹: A
R¹C²: B
R²C¹: C
R²C²: D

But this circuit has a problem. When B, C and D are simultaneously pressed (like below), it incorrect detects that A has also been pressed.


           C¹       C²
           │        │
 R¹───┬────◠───┐    │
    A ●▁▁●─┤ B ●━━●─┤
           │        │
           │        │
 R²───┬────◠───┐    │
    C ●━━●─┘ D ●━━●─┘


This is because while scanning R¹, the signal takes a path through the B switch, then passes the wrong direction through D, then finally passes through the C switch causing C¹ to read high.


This problem can only arise when a signal passes the wrong way through a switch. To prevent this, we use diodes.


            C¹        C²
            │         │
 R¹───┬─────◠───┐     │
    A ●▁▁●─▶┤ B ●━━●─▶┤
            │         │
            │         │
 R²───┬─────◠───┐     │
    C ●━━●─▶┘ D ●━━●─▶┘

If you can understand that, then there's really nothing to it. The hardware to wire up a keyboard is easy and with the help of TMK, the software has been taken care of for you.


¹ Teensy 2

² TMK Firmware


---


More Posts Like This

Return to Homepage


The content for this site is CC-BY-SA-4.0.

-- Response ended

-- Page fetched on Thu Apr 25 15:52:56 2024