πŸ’Ύ Archived View for shit.cx β€Ί keyboards β€Ί h0002 β€Ί 2020-12-28-keyboard-circuit captured on 2022-03-01 at 15:02:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

➑️ Next capture (2022-07-16)

-=-=-=-=-=-=-

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.