Learn how to make a small keyboard with KiCAD

So you want to make a keyboard PCB? Don't know where to begin or how to proceed? You've arrived at the right place!

Learn how to make a smll keyboard with KiCAD


Getting Started

KiCad will be required. Download it, install it, and you're good to go!

... nearly.

We'll need some libraries as well. Hasu's keyboard parts component library and footprint library are my favorites, and /u/techieee has a good switch footprint library.

Download them all and we should be good to go!

Check that you have the official KiCad libraries as well. These should be included with your KiCad setup.


Schematics

Launch KiCad and start a new project (File > New Project > New Project). Whatever you want to call the project. For this guide, I'll refer to it as an "example." I know you're very inventive.

We'll begin by sketching out our schematics. When you double-click you.sch file, you should see an empty schematic sheet:

Learn how to make a small keyboard with KiCAD

Let's start by adding our component library. Click Preferences > Component Libraries at the top of the window. Then, click "Add" and navigate to Hasu's library to locate the keyboard parts.lib file. Find the library you just added at the bottom of the component library list. We'd like to move it to the top of the list, so yours should look like this:

Learn how to make a small keyboard with KiCAD

We're ready to go now that we've clicked "OK." Buckle up, because we're about to get really technical.

To begin, here is a list of basic commands:

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!

Do Place > Component. Your cursor should now resemble a pencil. Place your cursor anywhere on the sheet. Look in the keyboard parts library for ATMEGA32U4:

Learn how to make a small keyboard with KiCAD

Click OK, then click again on the schematic sheet to position the component. This is our commanding officer. Change the reference from "U?" to "U1" in the component. This is the one-of-a-kind name we'll use to refer to this specific component.

The crystal, which tells the controller how fast to run, is the next component we'll need to install. Locate and install the XTAL GND component next to the controller. Replace the reference with X1.

Next, we'll want to add two decoupling capacitors (C SMALL). These capacitors will essentially help prevent too much noise from accumulating in the signal to the controller. There is a formula for calculating the capacitance required for these capacitors, but for the time being, we'll use a crystal with an 18pF load capacitance, so these decoupling capacitors will be 22pF. Change their values to 22p and rename them C1 and C2. Add a GND symbol to represent ground as well, and connect everything with the wire tool (green line on the right) as follows:

Learn how to make a small keyboard with KiCAD

Following that, we'll add decoupling capacitors for VCC, our power supply. We'll need one 0.1uF capacitor for each VCC/AVCC on the controller, as well as one 4.7uF capacitor for UVcc. In our case, we need four 0.1uF capacitors and one 4.7uF capacitor, as follows:

Learn how to make a small keyboard with KiCAD
 

Let's connect a reset switch. You'll need a switch (SW PUSH) named SW1 and a 10k pullup resistor (R) named R1. If you're wondering why we need a pullup resistor and what it even means, Sparkfun has a good explanation. But for the time being, here's how it should be connected:

Learn how to make a small keyboard with KiCAD

Put a 10k resistor called R2 on the HWB/PE2 pin and connect it to ground. A resistor is used here to tell the microcontroller that when we press the reset button, we want to enter the bootloader so that we can flash a new layout onto it!

Learn how to make a small keyboard with KiCAD

Let us now add our USB port. J1. Add the USB mini micro B component from the keyboard parts library. VUSB should be connected to VCC and Uvcc, and two 22 ohm resistors R3 and R4 should be placed between the D- and D+ connections. Connect GND and SHIELD to each other and to ground. Finally, connect UCap and GND with a 1uF capacitor C8:

Learn how to make a small keyboard with KiCAD

Let us connect all of the VCC and GND connections together. If you were using the built-in ADC (analog to digital converter), you would normally connect AVCC and VCC with a capacitor, but we don't care about that for a keyboard, so just connect them directly. At this point, everything looks like this:

Learn how to make a small keyboard with KiCAD

Let us now construct our switch matrix. For this guide, we'll just make a simple 2x2 matrix. For our switch and diode components, we'll want to use the KEYSW and D components, respectively. Simply connect them as you would a hand-wired board, and remember to name them. K1 should be the same as D1, K2 should be the same as D2, and so on:

Learn how to make a small keyboard with KiCAD

We need to connect this matrix to the controller now. Labels will be used for convenience (A with a green line underneath on the right). We'll use PF0 for row 0, PF1 for row 1, PF4 for col 0, and PF5 for col 1 in our example board:

Learn how to make a small keyboard with KiCAD

Finally, mark all unused pins as not connected. Click on all the unconnected pins on the controller and the ID pin on the USB port with the no connect tool (blue X on the right). This is also a good time to double-check that you didn't miss any VCC or GND pins earlier! Our final design should look something like this:

Learn how to make a small keyboard with KiCAD

 

Associating Components and Footprints

We must explain to KiCad what each of these components means. At the top, select the CvPcb icon:

CvPcb icon

If this is your first time using CvPcb, we'll need to import the footprint libraries that we downloaded earlier. Click Preferences > Footprint Libraries, and then use the "Append with Wizard" button in the window that appears to add the "keebs.pretty" and "keyboard parts.pretty" folders that we downloaded earlier. You may also need to add the built-in KiCad libraries manually. Your library list should now look something like this:

Learn how to make a small keyboard with KiCAD

All of our capacitors and resistors will be assumed to be 0805 imperial sizes. Our ATmega32U4 will be housed in a TQFN package. For our diodes, we'll use Hasu's library's very useful hybrid through-hole and surface mount footprint. /u/1u techieee's switch footprint will be used for switches. The crystal will be of the FA-238 series. The reset button will be from the TL3442 series, and the USB mini B port will be from the Hirose 5S8 connector. Go through the list of footprints for each component and double-click on one to associate it with the currently selected component. Here's how all the associations should look in the end:

Learn how to make a small keyboard with KiCAD

Save the assocations and close the window.

 

Generating Netlist

Now we'll create the netlist, which is essentially a list of the connections in our schematic. Select the netlist button:

netlist button

Simply click "Generate" in the dialog that appears. In the save dialog, use the default netlist name. KiCad should not ask you about annotations if everything was properly laid out and named. If this is the case, click "Cancel," double-check all of your references, and then try again.

 

PCB

We can now start designing our PCB! Save your work and exit the schematic editor. Return to your project and open your ".kicad pcb" file. You should be greeted by a blank PCB editor:

PCB Edtor

The first thing we'll do is double-check that all of our footprints remain. Check that all of the footprint libraries you imported earlier are still present in Preferences > Footprint Libraries Manager. If not, just import them again.

Next, we'll create our grid. Set Units to Inches and Size X and Size Y to 0.09375, as shown: Dimensions > Grid

Learn how to make a small keyboard with KiCAD

Then we want to instruct the PCB editor to use our custom grid. Change the top grid option to "User Grid."

Reading the netlist we generated earlier is the simplest way to get all of our footprints onto the board. Simply click on "Read Current Netlist" after clicking on the netlist button, which should look the same as before. A slew of messages should appear, and the dialog should look something like this:

Learn how to make a small keyboard with KiCAD

Now press the "Close" button. You'll notice that there are now a slew of footprints stacked on top of each other in the center of the screen:


Let's hide the ratsnest, which is essentially the lines that detail the electrical connections on the board, before we separate them. Uncheck "Ratsnest" under the "Render" tab on the right:

Learn how to make a small keyboard with KiCAD

Here are some useful commands for the PCB editor:

m: move the footprint
g: drag the footprint while keeping connectivity
e: edit the footprint
r: rotate the footprint
f: flip the footprint
del: delete the footprint
esc: abort!

Let's divide our footprints and place them on the proper side of the PCB. The switch footprints will be the only ones visible on the "front" of the PCB. Everything else will be on the "back" of the PCB, so make sure everything is turned off except the switches:

Learn how to make a small keyboard with KiCAD


Component Positioning

If you haven't already, arrange your switch footprints as shown. Then, for each of the switch footprints, change the "Move and Place" option to "Lock footprint" to prevent them from being accidentally moved:

Learn how to make a small keyboard with KiCAD

First, we'll place our diodes beneath our switches (THIS PLACEMENT WILL ONLY WORK FOR SMD DIODES). Ascertain that each diode corresponds to its respective switch:

Learn how to make a small keyboard with KiCAD

Let's move our microcontroller next to the switches, like so:

Learn how to make a small keyboard with KiCAD

The crystal is the most important component of PCB design. We must ensure that the traces to the crystal are as short as possible and roughly the same length. Using the "highlight net" tool on the right is an easy way to see which pads are supposed to connect to which pads. You use the tool and simply click on a pad to highlight it and the pads it connects to. For this example, I positioned the crystal 45 degrees above the microcontroller:

Learn how to make a small keyboard with KiCAD
 

Then place the 2 decoupling capacitors next to their respective pads:

Learn how to make a small keyboard with KiCAD

You don't need to connect the ground to any other grounds because we'll be putting a ground plane underneath all of the components. More on that in a moment.

The decoupling capacitors for VCC will be placed next. Connect a 0.1uF capacitor to each VCC and AVCC, and a 4.7uF capacitor to UVCC. At this point, I realized that the microcontroller was too close to the switches, so I moved it further away:

Learn how to make a small keyboard with KiCAD

Let's put our last capacitor on, which will fit nicely between C5 and C7:

Learn how to make a small keyboard with KiCAD

Place our mini USB connector and reset switch now. This is where I kept mine:

Learn how to make a small keyboard with KiCAD

The resistors are our final component. Place them in such a way that later routing traces will be easier. This is how I did mine:

Learn how to make a small keyboard with KiCAD

To allow for finer positioning, my grid sizes are currently set to 0.0234375" in each dimension.


Edge Cuts

Let's draw the outline for our board now! Go to the right-hand "Layer" tab and click next to "Edge.Cuts" to move the blue arrow down to it, effectively selecting it as the layer we'll draw on:

Learn how to make a small keyboard with KiCAD

Draw an outline for the PCB using the drawing tools on the right:


Here's how I cut mine:

Learn how to make a small keyboard with KiCAD

Ground Plane

We intend to include a ground plane on the PCB. A ground plane is simply a large piece of copper that is connected to the ground on both sides of the PCB. It comes in handy when we have a large number of components connected to the ground, such as on our PCB. To accomplish this, we will employ the zone tool:

zone tool

Make sure the blue arrow in the Layers tab is back on "F.Cu." Then, select the zone tool and click on one of the edge cuts' corners. A dialog box will appear asking you to select which network the zone should be associated with. Choose GND and press "OK":

Learn how to make a small keyboard with KiCAD

Now, draw a border around the edge cuts. When you return to the beginning, double-click. A red hatch pattern will appear around your PCB. Now, right-click on the zone's edge and choose Zones > Duplicate Zone onto Layer. The same dialog will appear; however, this time, select B.Cu on the left and press "OK." Your PCB now has a red and green hatch pattern around it:

Learn how to make a small keyboard with KiCAD

Now, right-click each zone and select Zone > Fill Zone for each zone. On the left, make sure the option to show filled zones is selected:


And your printed circuit board should now look like this:

Learn how to make a small keyboard with KiCAD

Select the option to hide filled zones. We don't want them around while we're routing.


Routing

We'd like to do some routing now. We want to route using the "add tracks and vias" tool:

"add tracks and vias" tool

For this part, I would also recommend setting your grid size to 0.25mm.

First, let's clear up some terminology:

  • A trace is a physical copper electrical connection. Just like a wire.
  • A via is a hole that runs through both sides of a printed circuit board. This is useful because when routing traces, we will encounter collisions where one trace cannot be routed through another. A via allows us to jump to the other side of the PCB and continue the trace there. 

While routing, you can switch layers and create a via by pressing "v".

Now that that's out of the way, let's establish some ground rules. Well, there is one ground rule. Namely, no vias between the crystal and the controller. Vias can potentially cause a small amount of capacitance that can affect the operation of our crystal, so they are a no-no.

Let's get started with the routing. The crystal and the decoupling capacitors next to it should always be routed first. Fortunately for us, this is quite simple. To begin, ensure that the B.Cu layer is selected, as this is where the majority of our components are located. This is how I did mine:

Learn how to make a small keyboard with KiCAD

Let us now route the VCC lines. Make sure the decoupling capacitors are connected to the correct VCC pins on the microcontroller. Don't forget to connect to the USB port!

Learn how to make a small keyboard with KiCAD

Let us now route the UCap capacitor and the remaining resistors. Keep in mind that a well-designed PCB will also be visually appealing. I routed the remaining capacitor and resistors as follows:

Learn how to make a small keyboard with KiCAD

I changed the switch's routing to accommodate the traces for the USB data resistors. You can also enable the ratsnest in the Render tab on the right to check for any connections you may have missed or accidentally broken while tracing routes. Ignore the connections to the diodes and switches. Those will be routed next. As it turned out, I had forgotten to connect all of the VCC pads and had broken a few ground connections. This is how my PCB looked after I fixed all of the missing connections:

Learn how to make a small keyboard with KiCAD

Now we'll connect the diodes and switches. Before touching the controller, connect the diodes and switches as follows:

Learn how to make a small keyboard with KiCAD

And finally, we'll route the controller to the rows and columns:

Learn how to make a small keyboard with KiCAD

Turn on your zones, fill in any missing ground planes, and then press b to update the zones.

Learn how to make a small keyboard with KiCAD

Using the DRC (design rule check) tool, double-check that all connections have been made:

DRC

Check for errors before clicking "Start DRC." Then, click "List Unconnected" to look for any unconnected networks. If neither section is filled out, then...

Your PCB is complete!

Navigate to View > 3D View and enable Preference > Realistic Mode. Turn up all of the settings, choose a background color, and you'll have a nice render of your PCB! You can even put your name on your PCB by using the Text tool and the B.SilkS layer:

3D View

Holes for Mounting

With a standard PCB, you'd want to add some mounting holes. You would add those by designing custom footprints with NPTH (non-plated through hole) pads and including them on your PCB. This is beyond the scope of this guide, but it is very simple to Google!

 

Production

You want to have your PCB manufactured now that you've finished designing it, right? Let's get you going on that.


Gerber Files

The first step is to create our "gerbers," which are files that tell the PCB manufacturer what is on each layer. Select the "plot" icon:

"plot" icon

Specify a directory for your gerber files and ensure that the F.Cu, B.Cu, B.Paste, F.Paste, B.SilkS, F.SilkS, B.Mask, F.Mask, and Edge are all present. Layers of cuts are chosen. Check the box next to "Use Protel filename extensions," and make sure the format is "4.6 (unit mm)":

Learn how to make a small keyboard with KiCAD

To generate your files, click "Plot."

Then, select "Generate Drill File." Set the output directory to the same location as before, the drill units to "Inches," and the Drill Map File Format to "PostScript." Check the box next to "Mirror y axis," then click "Drill File":

Learn how to make a small keyboard with KiCAD

Now close the dialogs.

Put all the files you just generated into a zip file:

Learn how to make a small keyboard with KiCAD

Upload your files to http://www.gerber-viewer.com/ and double-check that all of the layers are correct. If this is the case, you're ready to send your PCB to the manufacturer!

 

Manufacturer

There are numerous options available here. I've had great success with PCBWay (referral link), but there are plenty of other low-cost PCB prototyping services available, including EasyEDA, OSH Park, JLCPCB and DirtyPCBs.

All of these services require you to select some options for how your PCBs will be manufactured (the default settings are fine for all of them), then upload the zip file you just created. If you want to change the color of your PCB, you should look for the "solder mask color" option. The text on your PCB will be in "silkscreen color."

When you receive your PCBs, all you need is some solder paste and a hot air rework station to put it all together! If you're not sure how to do this, there are plenty of online resources that can teach you the fundamentals of SMD soldering.

Good luck and have fun building your own PCBs!

[source]

Next Post Previous Post
No Comment
Add Comment
comment url