[ code. keyboards. terminals. cyber. ]


diy keyboard from scratch (II)


In part 1 (LINK) it was about the considerations it takes before it starts with the tinkering. Moving on, here's a hybrid of planning and having fun with the device (... which we're building first).


. For the keyboard to do what it is supposed to do - pass the characters we type to the computer - it needs more than switches.
This is where our microcontroller comes in. This recognizes which key is pressed and compares with the code, which runs on it, to which character the key belongs and sends this further to the computer.

Which microcontrollers are suitable?

Suitable DIY keyboard controllers are ATmega32u4 (DOKU), STM32F303xC (DOKU), and AT90USB1286 (DOKU.

The advantage is that the microcontroller can handle the communication between USB and keyboard without doing much. You don't have to create your own PCBs to use the controller, fortunately. There are ready boards which are equipped with this controller. Here you can simply solder the contacts of the switches to the pins of the board and these are passed on suitably to the controller.
The following boards are suitable for a DIY keyboard:

[+] Pro Micro (Datasheet)
[+] Elite C (gleiches Board wie "Pro Micro" nur mit USB-C Connector)
[+] Teensy 2.0 (Datasheet)
[+] QMK Proton C (Datasheet)
[+] Teensy++ 2.0 (Datasheet)

The next Rabbithole? Yes - if you want to deal with microcontrollers. If not you take the best documented boards and those are Teensy 2.0 and Teensy++ 2.0. In that case the ATmega32u4 is still a little bit better documented than the AT90USB1286 - but those are small things.

My choice fell on the Teensy 2.0 with ATmega32u4 microcontroller.

If the board + microcontroller are selected it goes about the firmware of the controller.
Again, fortunately, the wheel does not have to be reinvented. In the first part I had already linked the keyboard-layout-editor. With this tool you have the possibility to grab the raw data from your layout and pass it on to another handy tool.
Also, this is where you set the pins which are used for vertical rows and which are used for horizontal rows, but more on that later. Here's the link to it:Keyboard Firmware Creator

The tool gives you all the knobs you want. You can define the complete keyboard layout, create different layers (especially useful for 65% and smaller keyboards), you can pack your LEDs directly into the firmware and and and.

If you are satisfied with your settings, the whole thing is compiled, the tool spits out a *.hex file, and flashed to the microcontroller. This would be microcontroller + software done.

What also falls out of the keyboard firmware builder, is the wiring of the switches, the wiring.

Wiring (wiring)

The basic concept of wiring is a grid of rows and columns. Easiest to follow on the Plankh Ortholinear Keyboard.
For basic wiring, it doesn't take much - what it does take is:

[+] wire [+] solder [+] x-diodes (x = number of switches / 1N4148 diodes).

The diodes are needed in case the correct key signal still arrives at the microcontroller, even if several keys are pressed at the same time. Especially advantageous for key combinations.

Once the plate is equipped with the switches, it's time for soldering. Standard switches have 2 pins. One is used for the horizontal connection and the diodes, the other for the vertical connection. It is only important that always the same pins are used.


red - vertical wiring green - diodes blue - horizontal wiring

This would connect the switches to each other. Still missing is the connection to the board with the controller.
As before, the rows and columns are now connected to the board. For this you need exactly one contact from each column to the board and one from each row. These are then connected to the board as specified in the firmware.

With this we have theoretically a working homemade keyboard! Connect the cable - open VIM and start.

In the design of the case, of course, the Fanatsie no limits. My case consists of an old piece of board, from which the inside was sawed out, the plate for the keys and the bottom are the side of an old speaker - sand everything well - done.