The circuitry handbook.
- PCB Designer Guide
- PCB Guide Part 1 - Preparations
- PCB Guide Part 2 - Beginning the project
- PCB Guide Part 3 - Creating the MCU schematic
- PCB Guide Part 4 - The rest of the schematic
- PCB Guide Part 5 - Creating the PCB
- PCB Guide Part 6 - Fill zones, decoration and production
- Example repo
- PCB Guide Part 7 - USB-C and LEDs
- Advanced Info
- Microcontroller Design
- Matrices and Duplex Matrix
- Routing Techniques
- Backlighting And RGB
- USB Type-C
- Good USB Routing Practices
- EMI Shielding and Reduction
- Breakaway Tabs
PCB Designer Guide
PCB Guide Part 1 - Preparations
This guide is intended as a direct replacement for the aging Ruiqi Mao's guide.
Credits go to that guide for serving as a base for this writeup.
If you spot any mistakes, please let me know either through Discord (ai03#2725) or email (firstname.lastname@example.org), and I will fix it to the best of my abilities.
ai03's Keyboard PCB Design Guide
So you want to design keyboard PCBs, or to make sure that you are doing things correctly.
We will build a similar 2x2 macropad in this introduction, but will do so in a more future-proof way compared to the other guides.
Step 1. Grab the requirements
We will be using KiCad for making the PCB.
Grab the program here:
As of the latest update to this guide, the latest update is 5.1.2.
There are various stories about KiCad being counter-intuitive and crashing often. However, most of these stories are a relic of ancient KiCad 4.0 variants, and the program runs very stable and smooth with recent updates.
However, just in case, you should always save often and use revision control (see below).
Now comes the download and install process. Grab a cup of coffee, for KiCad 5.1.2 is a whopping 1GB.
Install as you would any other program.
Also, this guide will be using Git/GitHub to manage progress.
If you are new to this, grab GitHub desktop here:
Install, then sign in or create an account as necessary.
Also, make sure to become familiar with GitHub, as it is very useful for open-source projects.
|If you already work with git, use whichever implementation you prefer, and replace all mentions of GitHub in this guide with your preferred methods.|
Finally, if you would like community support in case you get stuck, I recommend that you join my Discord server:
It is a designer haven, with references, datasheets, and designer chat channels.
Step 2. Repository Preparations
First, let's create a git repository for the PCB on GitHub
It is always nice to be able to roll things back in case things get out of hand.
Also, it is a simple and reliable way of sharing your work to the world.
Select File -> New repository,
Then create a repository.
Some of the important options:
- Name - The name of the project. For now, use something like keyboard-pcb-tutorial and whatnot.
- Description - Something so that viewers won't be completely confused as to what the repository is about.
- Readme - The "front page of the repository" that's displayed when people access it on GitHub. May as well generate a blank one.
- License - Places limits on what people can do with your project. For example, you can block commercial use, force derivatives to open-source as well, etc.
This will create a blank repository to begin work in.
Publish the repository,
Using whatever settings you prefer.
Uncheck "Keep this code private" if you want to have the data public and open-source to begin with.
Repository preparations are done.
Now, it's time for initializing the KiCad project.
PCB Guide Part 2 - Beginning the project
By this point, you should have a repository readied for the project.
Step 3. Creating the KiCad project
The previous page's setup should have created a folder in your home/Documents/GitHub folder with the project name.
We will be doing all work here.
Launch KiCad, and you will be greeted with the main menu.
From the options, select New Project.
Browse to your repository directory.
Make sure to uncheck "Create a new directory for the project". Otherwise, you will have your project in a useless subdirectory.
KiCad will generate the basic project files.
The default project only has two files:
- The .sch file - Contains the schematic, or the electrical layout. This is where you will add the parts and wire them together, so KiCad knows what you're trying to accomplish.
- The .kicad_pcb file - Contains the physical layout. This is where you take the data from the schematic, and position and connect them all together for production.
The basic workflow is to create the schematic first so that the electric side is all set, then to lay it out on a physical PCB based on that.
At this point, let's commit our changes.
Give the commit a name, commit, and push the changes.
This guide will occasionally remind you to commit after large milestones; however, it is recommended to do so often. Losing work is not an enjoyable experience.
Step 4. Add local libraries
KiCad is built around libraries - A collection of footprints, and often schematic components bundled with it.
Footprints are the building blocks of PCBs - The sets of copper pads that the components attach to.
KiCad ships by default with support for common electrical components, such as resistors, capacitors, microcontrollers, etc.
It does not ship with exotic things, such as Cherry MX footprints, very specific USB connectors, etc.
Let's take care of that.
KiCad supports two library install types:
- Global - The library is added to the computer. This means you only have to install the library once.
However, this has the massive downside of requiring that the library be installed to view the project on another computer. This can be a hassle, especially if having the project checked by others
- Local, or Project-Specific - The library is added only for the specific project. This means you will have to install the library each time; however, the project can be shared instantly without any worry about compatibility or missing libraries.
We will be using project-specific libraries.
First, we will need to pick which footprint libraries to use.
In this guide, I will be making use of the following repositories:
- My MX-Alps hybrid footprint library - For switches.
- My random keyboard parts library - Mainly for the USB connector.
We will be adding these to our project as Git Submodules - This allows us to pull new changes from them without having to manually download and overwrite the existing files.
Since the GitHub desktop application is fairly awful at managing submodules, we will opt for using the shell instead.
Then, run the following command:
git submodule add URL-OF-REPO
In this case, I will add the two repositories linked earlier.
The GitHub desktop GUI seems to have issues with committing submodules, so let's do it from the command line:
git add *
git commit -m "Add submodules"
The commands adds the new submodules to the commit, creates a commit with the given name, and pushes it to GitHub.
After the push finishes, you can see that the library repositories are linked in your GitHub repository.
Now that the files are there, let's add them to the project.
First, open up your schematic file,
Select Preferences -> Manage Symbol Libraries,
Select the Project Specific Libraries tab, select Browse Libraries (Folder icon),
And select the .lib files in each of the added libraries.
After checking that both are added, confirm the changes by pressing OK.
Close the schematic editor for now.
Open the PCB file,
Go to Preferences -> Manage Footprint Libraries, switch to Project Specific Libraries, and browse for the added .pretty folders.
For this guide, I will be using the MX_Alps_Hybrid style footprints.
Again, click OK to confirm changes, then close the PCB editor.
Commit these changes, and push the commit.
If both the fp- and sym-lib-table files are not showing up, make sure you hit OK when adding the libraries rather than simply closing the dialog.
Now you're all prepared for making your first keyboard!
Time to begin the schematic.
PCB Guide Part 3 - Creating the MCU schematic
By this point, you should have installed the programs, created the repository, and added the local libraries.
Step 5. Beginning the schematic
The schematic is used to set up the electronics side of things.
For this tutorial, we will be using the typical Atmega32u4 microcontroller, and building a 2x2 macropad with MX and Alps support.
Open up the schematic editor to begin.
One modification used during this guide is seting the grid size to half the default size.
This allows a bit finer grain control for wiring things.
From Preferences -> Preferences -> Display options, set the grid size to 10.
Also, if you want the super HD 8K experience while making your schematic, you can swap the graphics settings in the Common page.
From Ruiqi Mao's PCB guide, here is a nice commands reference:
m: pick the component up and move it g: drag the component up and move it while keeping wires attached to it c: copy the component e: edit the component r: rotate the component y: mirror the component del: delete the component esc: abort!
Also, these shortcuts are useful to know:
w - Begin drawing a wire connection k - Cut a wire and stop drawing it without clicking on an endpoint Ctrl + h - Place a global net
The microcontroller, or MCU for short, is the brain of the PCB.
It cannot function on its own, so we will build the circuit for it.
First, press A to open the "add symbol" menu, and search for atmega32u4.
Select the atmega32u4-au component.
Place it down in the schematic.
To set it up, we will simply follow two resources:
- The technical data provided by the official datasheet.
- An existing "tried and tested" schematic used on the PJRC Teensy.
Usually, both a technical datasheet and an existing implementation will exist for most components.
Search for both, and use both as reference.
To begin, let's tie UVCC, VCC, and AVCC to +5V, as specified by the datasheet.
Hit P to open the power symbols menu, and select the +5V symbol.
Place it above the VCC pins. If you misplace, you can move it by hovering over the component and pressing M.
Now, wire it together using the wire tool (hotkey W).
This binds the physical UVCC/VCC/AVCC pins on the component to the +5V net.
Net refers to a set of pads that should all be connected together.
Similarly, bind the GND and UGND pins to Ground by selecting the GND symbol in the power menu and wiring them together.
Protip: It is good practice to have positive power source symbols pointing up, and ground power symbols pointing down.
Now we will place some components.
The HWB pin requires a pull-down resistor, or a resistor connected to ground.
Open the components menu with A, and search for r_small, or the small resistor component (The large one is massive and will burn space on the schematic):
Now, place this parallel to the pin labeled HWB/PE2. You can rotate the component by pressing R.
Also, place a ground symbol.
Now, wire it together.
Congratulations, now the PE2 pin is connected to ground through the resistor.
Let's change the value of the resistor. Press the E key while hovering over the resistor to edit.
A 10k ohm resistor is fit for this task. Select the value field, and type 10k.
The component's value should now be updated.
The USB pins also need resistors. Repeat the previously described commands to place two 22 ohm resistors, and wire them.
In this case, I drew the wire out on the other side as well, and used the K hotkey to end the wire at those points.
Now, let's place needed capacitors.
Through the add components menu, search for c_small (Again, regular capacitor symbol is massive).
First, place a capacitor with value 1uF beside the UCAP pin, and connect the other end to ground.
Next, we want to set up our decoupling capacitors. These are important capacitors that filter out electrical noise coming from the microcontroller.
The official documentation states to have a 0.1uF by each VCC pin (Which would be 4 on a 32u4), and a 10uF overall.
However, the Teensy schematic uses only three 0.1uF, and a 1uF overall.
I personally combine them - three 0.1uF and one 10uF. This has been confirmed functional by my testing.
Place them in an empty space close to the microcontroller, and bind one end to +5V, one end to Gnd.
Protip: Build one 0.1uF capacitor, and clone it using C to save time.
Since this PCB will get its power from USB no matter, bind VBUS to +5V.
The crystal controls how fast the controller functions.
Search for the Crystal_GND24_Small component...
...and wire the non-gnd pins (1 and 3) to XTAL1 and XTAL2.
The crystal also needs load capacitors of its own.
Place two 22pF capacitors between each crystal pin and Gnd.
Also, wire the Gnd pins on the crystal to Gnd.
Also, an external pull-up resistor can prevent the reset pin from being read faultily, and accidentally resetting during use.
For this, a 10k ohm resistor can be placed between reset and +5V.
The AREF pin is ignored since we won't be doing analog readings.
Now let's place global nets on the USB lines - These connect wires together by name, removing the need for ugly wires that cut across the entire schematic.
Hit Ctrl+H, type the names, and place them on the other end of the USB positions.
Local nets also work, but I prefer global nets since they are much more visible.
A view of the completed MCU zone.
Now, it's time to complete the rest.
PCB Guide Part 4 - The rest of the schematic
By this point, you should have the MCU schematic zone complete.
Step 6. The rest of the schematic
The rest of the schematic is not as difficult as the MCU.
Let's power through it.
Only typical Mini-B USB will be covered here for simplicity reasons?
Type-C setups will be discussed in future sections.
Search for the molex USB connector in my library, along with polyfuse-small.
The polyfuse prevents your computer from exploding in case of a short circuit.
Connect VBUS -> Polyfuse, then Polyfuse -> +5V. Drop a VCC symbol pre-fuse. Change fuse value to 500mA.
The rest are self-explanatory. The data lines are connected using the global labels we set up earlier:
Now, let's add the switch matrix.
I will use the MX-NoLED symbol from my own library.
Combine it with a D_Small (small diode). Ignore the LED pads for now; that will be covered later.
Connect the anode of the diode to the ROW pin of the switch.
Now clone this four times as shown:
Then, drag a wire across the diode cathode and COL pins of each row and column, and terminate them using the hotkey k: