How I Made: A PCB Mechanical Keyboard

By Ian Dunn. Posted

I made an 87-key mechanical keyboard with a conventional key layout, constructed from three layers of FR-4 PCB. While making a keyboard from PCB material may sound a little unconventional, I think it’s ideal; it’s strong, easily customised, and very easy to clean. What makes this keyboard really unique is its open-source firmware written in the Arduino IDE that can run on the Raspberry Pi Pico.

AN OVERVIEW OF MY PROCESS 

Briefly put, I started by designing a layout, turned the layout into a schematic, and then placed 87 keys in the correct place on a PCB. Once the layout was complete, I placed a diode reasonably close to each switch. The circuit isn’t complicated, but it is a really large circuit and a big PCB. If you want to take on this challenge, this article will save you from making some of the beginner mistakes that I made. I’ve open-sourced my schematic and key layout for you to use as a reference, or to customise to your own liking without you having to start from scratch, at this link: boltind.com.

DESIGNING A LAYOUT

I recommend designing your layout with: keyboard-layout-editor.com. This is a handy tool that allows you to drag and drop keys where you want them, adjust the  size to your liking, change the legends, and otherwise customise your keys.

The other tool I used is the Keyboard Firmware Builder, at kbfirmware.com. You can copy and paste the ‘raw data’ from Keyboard Layout editor into this nifty tool and it will give you a schematic diagram of how your rows and columns should be laid out. It also generates custom firmware, but I don’t recommend using it for this. It’s no longer maintained and there are better ways of building firmware, which I’ll get to later on. 

Once you’ve got your layout planned, you can draw a schematic in your preferred EDA software. I recommend EasyEDA if you’re a first-time EDA user. EasyEDA is really simple, yet it’s packed with every feature you could ask for. You’ll want to start by locating a switch symbol with a CHERRY MX-style PCB footprint. This form factor is pretty much the gold standard for mechanical keyboard switches, and makes it easy to place a switch on the schematic for every button on the keyboard based on your layout. 

Start with the first row of keys. Label each one carefully before moving on to the next row. The prefix naming conventions can get a little confusing, because EDA software usually names components ‘R-1, R-2, R-3’ and so on. If you label the F1 key as ‘F1’, then you will find that you’ve already got an F1 when you place the letter F key. Just find a naming convention that works for you, and be careful not to place the ‘F1’ key in the place of the letter F key when you layout your PCB. I’ve been there, done that!

KEYBOARD MATRIX 

Once you’ve got the switches placed on the schematic, draw the matrix. Unless you’re designing a macro pad, you’ll find there’s not enough pins on any microcontroller to have each key on its own GPIO. This means that you have to use a matrix to scan each row and column, one at a time. For the matrix to work properly, a diode is required for each key. Place a diode for each switch. The 1N4148 switching diode is the only way to go. It’s economical and it comes in through-hole, as well as surface-mount, packages. It’s important to note that the direction of the diode depends on the firmware. Most firmware will allow you to select the direction of the diode. If you’re going to use BMK, my Arduino IDE firmware, the diodes must be placed from column to row. See Figure 1

KEYBOARD LAYOUT IN AN EDA PROGRAM 

A small gap between keys is required so that the keys don’t rub against each other.  Typically, the ‘unit’ on a keyboard is ¾”. This means the keys are spaced ¾” on centre, and every key size is some multiple (or fraction) of ¾”which is equal to 750 mils (for anyone more familiar with metric than imperial measurements, a mil in this context is a thousandth of an inch, NOT a millimetre). For example, the square letter keys are spaced 750 mils on centre and the rows are offset by some fraction of 750 mils. When laying out keys, we can just assume each key is 750 mils and we’ll end up with the correct spacing between keys because the key caps are a little less than 750 mils. 

The exception is the larger keys, like the SPACE bar, TAB, CAPS, SHIFT, ALT, etc. These keys can be 1.25, 1.75, 2, 2.25, or 2.5 units wide. Because the key sizes are in increments of .25 ‘units’, and the rows are offset from one another, you will need to set your snap size to 93.75 mils while laying out the keys because 93.75 mils is ⅛ of a ¾” key. Also, set the grid to 750 mils. 

STABILIZERS

Once you’ve got your keys laid out, you will need to add stabilizers. Stabilizers come in two sizes: 6.25 units and 2 units. The former stabilizers are for the SPACE bar. The two-unit stabilizers are for SHIFT, ENTER, and BACKSPACE. There’s also seven-unit stabilizers out there, but every SPACE bar I’ve ever come across is 6.25 units.  

TOP AND BOTTOM TRIM

The next step is to route your PCB traces. You could stop here and have a working keyboard, but I highly recommend adding a top and a bottom made from FR-4 PCB. This will cover up all the components in a way that looks attractive and will add a lot of rigidity. To screw the three layers together, you’ll want to use M3 × 8 mm screws, M3 nuts, and M3 × 10 mm standoffs that are tapped all the way through. Screw everything together tightly so that the finished keyboard will be nice and stiff.

To create a top or bottom, copy the main layer and then make changes accordingly. For the top, trace the 750 mil outline of all the switches with a board outline trace. Don’t worry about adding a gap; key caps aren’t quite 750 mils wide. Once you’ve got every ‘group’ of keys traced, delete all of the switches and you should have a finished top trim. The top trim is a great place to add legends for your custom Macro or Unicode keys. 

The bottom can be identical to the main layer to save cost, or you can make another board with the same outline and no components. If you added screw holes to the main layer, just leave them in the same place when you copy the main layer for the top and bottom and they’ll line up perfectly. 

CONNECTING TO USB 

You can certainly use the USB port on your microcontroller, but I found that the Pico fits best between rows, horizontally. This means that the micro USB would awkwardly stick out the side of the keyboard. To get around this, you can connect a separate USB port to the USB pins on the bottom of the Pico. They are labelled TP2 and TP3. TP2 is D- and TP3 is D+. Making a USB device can get really complicated, but the main thing to know is that the D+ and D- lines need to be right next to each other, and they must have identical impedance. If you follow these two rules, and don’t try to do anything too fancy, you shouldn’t have any problems. 

Most USB connectors require very fine surface-mount soldering. I’ve come across three through-hole USB connectors that I like. All three of them can be purchased from LCSC. See Figure 2.

The first (A) is a USB-B plug. This one is big and ugly, but it’s really easy to solder. Its part number is USB-BF90 from Valuepro. You could also salvage one from just about any old printer. 

The next (B) is a USB-mini B connector. Its part number is 920-462A2021D10102 and is also from Valuepro. This one is perhaps the best option because it’s reasonably compact but still easy to solder. 

The last (C) is a USB-C connector. Its part number is U264-141N-4BAC10 and is from XKB Connectivity. This one is nice because it’s USB-C, but it’s also the most difficult to solder. Its footprint is as small as through-hole soldering gets. It is a through-hole part, but it’s not any bigger than most surface-mount USB connectors. You’ll need a needlepoint soldering iron and some very small solder. USB-C is normally a USB 3.0 connector, but this one is USB 2.0 only. The power, D+ and D-, need to be connected in two places each. You may also want to add a 5.1KΩ pull-down resistor to each of the two CC pins. This will tell the upstream USB 3.0 device that the keyboard is a peripheral device. Once enabled, you can plug your keyboard directly into your USB-C phone or tablet and it will work like magic. 

I also added a two-port USB 2.0 hub to my keyboard. This is really handy, because you can plug your USB peripherals directly into your keyboard. You can even plug a mouse into the keyboard while it’s connected to your phone, so you can have the use of a mouse and a keyboard on your phone.

FIRMWARE

The final step is to flash a firmware to your Pico. A good friend of mine, Brian Di Donna, wrote what I call ‘BMK’ – an abbreviation for Bolt (Industries) Mechanical Keyboard. BMK is cool because it’s all done in the comfort of the Arduino IDE. BMK can do just about anything a regular keyboard can do, but is completely customisable so it offers endless possibilities. It’s really fun to write keyboard macros in the Arduino IDE. 

Another firmware candidate is KMK. KMK runs on CircuitPython, so it works nicely with the Raspberry Pi Pico. Once you’ve got KMK installed, making changes to your keyboard is just as simple as opening a text document on the Pico ‘flash drive’. Simply make your changes and press Save.

I hope you’ll experience the satisfaction I have found as you build something just right for you.

From HackSpace magazine store

Subscribe

Subscribe to our newsletter