Electronics

Custom 60 Percent Bluetooth Keyboard

Why a custom keyboard

A few weeks ago I had no idea about the custom keyboard market until I started looking for a replacement for my daskeyboard that was smaller than its full size layout. This was to reduce the amount space cluttering my desk. I started out looking for a ten keyless mechanical keyboard that I could take into the office. What I ended up finding is that I was not satisfied with what I could buy, this lead me down the proverbial rabbit hole.

After numerous days of internet searching I found that I would really like to design my own, from designing the PCB to building the case. This would have been very expensive so I decided to buy a standard kit that uses a micro-controller board that I could switch out for one with bluetooth functionality. This standard kit also has the benefit of having a wide selection of standard components to choose from such as cases, layout plates, keycap sets and much more.

Hardware

To build the keyboard we need hardware! There are a lot of components and kits out there on the internet so you need to research what you want to build. I wanted a 60% size keyboard that had bluetooth capability. A 60% keyboard is essentially the main section of a full sized keyboard. This means that the other keys are mapped using modifiers, like function, to reach all the other keys. I also wanted dedicated arrow keys but decided not to pursue that due to the difficulty of getting compatible keycaps.

PCB

The Pactice60 PCB kit is a basic 60% keyboard kit that has the user populate the diodes and backlighting resistors along with the other necessary components. I went with this instead of an integrated PCB solution because it breaks out all the IO to a large enough size for hand soldering. This allows me to make modifications and add my own controller!

Here are the Steps you will need to follow for this kit.

Controller

The controller that comes with the kit is a blue pill board, which is a basic STM32 micro-controller with a good amount of IO. This makes it suitable for driving the large matrix used for the keyboard.

blue pill STM32

The controller is attached to the PCB using low-profile connectors. These connectors do not use the standard pin headers and require thinner wires. This is why I saved the diode legs, the make perfect pins for low-profile sockets. Follow the steps below for so set up the blue pill controller.

To make the keyboard work on bluetooth I cannot use the blue pill board and need a new board that supports the QMK bluetooth firmware. I went with the Adafruit Atmel 32u4 bluefruit board. It has a bluetooth module on board as well as a charging circuit to recharge the battery.

Adafruit Atmel 32u4 bluefruit

The one issue with this board is that there are not enough IO to support the 60% keyboard matrix. Because of this we need to use an IO expander. There are several different chips that could be used to do this. I went with the MCP23008 which has 8 additional IO that the micro-controller can interact with over I2C. Adafruit sells the 16 IO version but I wanted to have all the IO on one side of the chip which that version does not support (this will be clearer when I show the proto-board).

MCP23008 Pin out

I decided to prototype the expansion board on a cheap proto-board. But first I needed to work out the pin mapping from the blue pill board so I know how to correctly interact with the PCB.

Blue pill Row pins 
[B3, B4, B5, B6, B7]

Adafruit Row pins
[A0,  A1,  A2,  A3,  A4]

Blue pill Column pins
[B11, B10, B1, B0, A7, A6, A5, A4, A3, A2, A1, A0, C15, C14]

MCP23008 column pins 
[ [7, 6, 5, 4, 3, 2, 1, 0] [7, 6, 5, 4, 3, 2] ]

Green are the Column pins, Red are the Row pins, Purple are the grounds, Blue are the USB pins, and Yellow is the programming reset.

Pin Mapping

Now wanting to have all the IO on one side makes more sense 🙂 this way the pins are easy to connect to the IO expanders.

Now I just need to connect up the other pins and break out the other pins to connect to the Bluefruit board. I added a pin header to the end and connected up the ICs according to their data sheets.

Next I connected the Bluefruit board to the broken out pins. I did not plan out for the Reset pin so that one is just a direct connection. The USB is also soldered to the proto-board, you can just snip off the end of an old cable.

Fully connected!

This schematic diagram can be used to connect up your own board.

Mechanical Switches

I decided to use the Aliaz Silent switches that are sold by KBDfans and produced by Gateron. These switches have a tactile feel but are much quieter than a Cherry MX blue. This means that they can sill be used in an office environment without annoying all of your co-workers.

I was only able to get them in the 5-pin variant. This can be fixed easily by snipping off the two plastic pins if your PCB does not support them.

Now we can set up the stabilizers, plate and switches. Take some time to do this right as there is a lot to do and it is extremely easy to make a mistake. I accidentally forgot one of the stabilizers after I had soldered in the edge switches. This required me to desolder a few of them to sneak it under the plate. Several of the switches are located under the controller, so it needs to be removed before they are connected in. To prevent connections on the controller from contacting the PCB place tape or another insulating material between them.

Firmware

The software that runs on the keyboard needs to manage the key presses and combinations along with the bluetooth HID connection. Thankfully I do not need to roll my own software, there is an open source project dedicated to custom keyboard called Quantum Mechanical Keyboard Firmware (QMK). This software forms the base of the keyboard functionality and uses custom files to define the particular layout and key mapping for the custom keyboard.

Default QMK

To test that the PCB was set up correctly we will program the blue pill so that we can test that all the switches are working correctly. The firmware can be downloaded from the Cannonkeys website of built on the command line. I decided to just download it and use the dfu-util to program the board.

To do this, plug the keyboard into your computer, press the reset, and run the following command in the directory that contains the .bin file.

dfu-util -d 1eaf:0003 -a 2 -D "cannonkeys_practice60_default.bin"

Test the board to make sure all the connections are working before preceding .

Custom QMK Bluetooth Firmware

Now its time to write some firmware! The QMK website was very helpful in how to create a new keyboard. Since my keyboard is using some hand-wired elements I placed my design under the handwired category of the github repo. I forked the main QMK repo and created the necessary files for a keyboard project.

Since I had to use IO expanders to connect the matrix columns I needed some non-standard configurations. First I needed a custom matrix file that tells QMK how I want it to scan the switch matrix and I also needed a MCP23008 i2c driver. Thankfully another developer, that created the basics for the QMK bluetooth support also added an IO expander. I modified his code to support my IO expander and my layout.

His project can be found here: Building a Keyboard and his repo can be found on his github iota keyboard

To get my build you can use this link to clone my repo containing the ble_practice60 keyboard.

git clone https://github.com/Tschucker/qmk_firmware.git

ble_practice60 keyboard and switch to the ble_practice60 branch. Then run the following command to create the hex file.

make handwired/ble_practice60

The bluefruit board could not be programmed with the dfu-util, thankfully a companion program to QMK was created to program various kinds of micro-controllers that QMK supports. Download qmk-toolbox and select your created hex file, then press the reset and hit the flash button.

Keycaps

There are tons of options for keycaps, these can range anywhere from $10 to over $100 just for plastic caps, this section all comes down to personal preference.

I went for the MAXKEY York Chan 2600 from KBDfans. It is a fun color-way that has a futuristic look and cool space themed special caps. They are SA profile which means that they are a bit tall but the sculpted nature makes typing a breeze. They ended up being about $70 total, but the printing is not quite as vibrant as I would have liked.

Base set
Reverse color specials

Case

I was originally going to use a wood case for my custom keyboard but I decided to go with a cheaper white plastic case to cut costs. This color will go well with the 2600 color-way keycaps. I will also be able to modify the plastic case to fit all my additional components!

To get clean cuts when removing the ribbing, clip the ends with the flush cutters and use an x-acto knife to core the bottom edge a few times. Then just bend and it should just pop right off.

Remove enough plastic ribbing to accommodate the control board, proto-board, wires, and battery

Here is the final layout of the components, I added a Adafruit pushbutton power switch that is under the blue tape along with a small tactile push button to allow me to completely power off the board. I am really glad I went with the plastic case because I needed to drill a few holes for the power button and a power indicator LED, This can all be done with an X-Acto knife!

Now all you need to do is settle the keyboard down into the base and make sure none of the sharp solder joints on the back of the keyboard PCB pinch the wires or could hit the battery. Then just drop in the screws and you are done!

Final Result

Now this might seem like a lot of work for something that you can buy for around $100. But as something that I use every day, for a countless number of hours, it is a unique piece that I can enjoy, fixup, and improve forever 🙂

(This article was typed using this keyboard!)

Teacup for scale