Onboard MCU (ATMEGA32u4)
Kicad: 6.99
Date: 2022
Disclaimer
This guide is not the first, nor is it the most comprehensive for keyboard PCB creation. The reason I'm writing this is to help people who want to start making keyboard PCBs but have no clue where to start. When I started, I had a really hard time finding information, and understanding the process. I have no formal education in software design and if you don't either then no worries. I hope that this will guide will shed some light on how this whole process works.
Getting started
This Guide assumes that you know the fundamentals. I am going to be using the PCB that we created from the previous guide. If you would like to download that PCB so you can start from the same point as me, you can download it from here.
Cheating...
It is possible to download the created file at the end of the guide, highlight everything, then copy and paste from my project to yours. By doing so you risk that something copies incorrectly. For example, Symbols could generate labels differently, and footprints might not link properly. Be prepared for the weirdness to occur, though if you are comfortable troubleshooting and confirming that everything is correct, by all means, get it done.
Adding The Onboard 32u4
Opening the schematic file will look like this. In the previous guide, we used a teensy 2.0 as our MCU. With the teensy 2.0, we didn't have to worry about the MCU logic, or about adding a USB connection. Though using something like the teensy makes things easy, it is often better to use an onboard MCU.
1. The teensy 2.0 is getting rather expensive.
2. Using an onboard MCU means that the manufacturer will solder the chip onto the board for us.
3. We will have access to more pins on the MCU. Which is important for a larger keyboard matrix.
4. Lower profile, the teensy requires a lot of space.
Let's start off by deleting the symbol for the teensy 2.0
Let's press (A) and search for the: ATmega32U4-AU, and add the symbol to our board. The symbol is located in: "MCU_Microchip_ATmega/ Atmega32u4-AU" . Also lets link the footprint to “atmega32u4-au-and-mu” located in: "random-keyboard-parts/ atmega32u4-au-and-mu". The settings should be as follows.
We are adding this footprint for a couple of reasons. At the time of writing this article, there has been an MCU shortage, causing prices to skyrocket. By using this footprint, we will have access to use either the AU or MU variant of the 32u4. Each of these essentially does the same thing, but the MU variant is smaller than the AU variant. the end, we will be able to pick the component we want based on availability and cost.
Though we have added the MCU, we still need to add all of the logic to our schematic to make the PCB work correctly. First, let's get some "best practices" out of the way. We are going to be adding power symbols to our PCB. VCC or power (+) symbols should be pointing upwards, and GND or (-) symbols should be facing downward.
Shortcut Reminders:
(W) is my shorthand for pressing the W button, to allow for the connecting of a wire|
(A) is my shorthand for pressing the A button, to open the symbol library
(P) is my shorthand for pressing the P button, to open the power menu
Connecting VCC
Let's connect all of our VCC at the top
(P) and search for "+5V" and add it to the board.
Now connect the components like so.
Connecting Reset Button
Now let's work on our reset button. This is not required, but by adding a reset button, we will be able to set the MCU to bootloader mode with the push of a button.
(A) and search for "r_small" and add it to the board.
(A) and search for "SW_PUSH" and add it to the board
(P) and search for "+5V" symbol and add it to the board
(P) and search for "Gnd" and add it to the board.
On the top menu, "Place / Add Global Label" and name it RST
Now connect the components like so.
Now double-click on the "R1"
In the value section, write "10k"
In the footprint section, write "Resistor_SMD:R_0805_2012Metric"
Now double-click on the "SW1"
In the footprint section, write "Button_Switch_SMD:SW_SPST_TL3342"
Connecting Crystal
Now let's add the crystal. This is important for timings and clock cycles.
(A) and search for "Crystal_GND24_Small" and add it to the board.
(A) and search for "C_Small" under the device tab, and add it to the board
(A) and search for "C_Small" under the device tab, and add it to the board
(P) and search for "Gnd" and add it to the board.
Now connect the components like so.
Now double-click on the "Y1"
In the value section, write "16MHz"
In the footprint section, write "Crystal:Crystal_SMD_3225-4Pin_3.2x2.5mm"
Now double-click on the "C1"
In the value section, write "22pF"
In the footprint section, write "Capacitor_SMD:C_0805_2012Metric"
Do the same for "C2"
Connecting VBUS
Now let's add our VBUS to 5V
(P) and search for "+5V" symbol and add it to the board
Now connect the components like so.
Connecting Data Lines
Now let's prepare our data lines.
(A) and search for "r_small" and add it to the board.
(A) and search for "r_small" and add it to the board.
On the top menu, "Place / Add Global Label" and name it D+
On the top menu, "Place / Add Global Label" and name it D-
Now connect the components like so.
Now double-click on the "R2"
In the value section, write "22"
In the footprint section, write "Resistor_SMD:R_0805_2012Metric"
Do the same for "R3"
Connecting UCAP
Now let's prepare UCAP
(A) and search for "C_Small" under the device tab, and add it to the board
(P) and search for "Gnd" and add it to the board.
Now connect the components like so.
Now double-click on the "C3"
In the value section, write "1uF"
In the footprint section, write "Capacitor_SMD:C_0805_2012Metric"
Connecting Grounds
Now let's group our grounds.
(P) and search for "Gnd" and add it to the board.
Now connect the components like so.
Connecting ISP Tags
Now it's time to add our ISP tags. This is important because when an MCU comes from the factory, they do not usually have a bootloader. We will have to flash one when the PCB comes in. The process of ISP flashing is so much easier when there is easy access to SP Flashing Pins. Note, you can still add column or row matrix positions to PB1, PB2, and PB3. These pins can play double duty as when we are ISP flashing we won't be using the keyboard.
On the top menu, "Place / Add Global Label" and name it SCK
On the top menu, "Place / Add Global Label" and name it MOSI
On the top menu, "Place / Add Global Label" and name it MISO
Now connect the components like so.
Connecting HWB
Now let's prepare HWB
(A) and search for "R_Small" and add it to the board
(P) and search for "Gnd" and add it to the board.
Now connect the components like so.
Now double Click on the "R4"
In the value section, write "10k"
In the footprint section, write "Resistor_SMD:R_0805_2012Metric"
Adding The Capacitor Bank
We have one more part of the MCU to add, the capacitor bank.
(A) and search for "C_Small" under the device tab, and add it to the board
(A) and search for "C_Small" under the device tab, and add it to the board
(A) and search for "C_Small" under the device tab, and add it to the board
(A) and search for "C_Small" under the device tab, and add it to the board
(P) and search for "+5V" symbol and add it to the board
(P) and search for "Gnd" and add it to the board.
Now connect the components like so. You will notice that it is not physically attached to the PCB.
Now double-click on the "C4"
In the value section, write "0.1uF"
In the footprint section, write "Capacitor_SMD:C_0805_2012Metric"
Do the same for C5 and C6
Now double-click on the "C7"
In the value section, write "10uF"
In the footprint section, write "Capacitor_SMD:C_0805_2012Metric"
Adding Additional Components
Adding the ISP Pads
Earlier I mentioned that the onboard MCU will most likely not have a bootloader installed on it from the factory. We will need to use an ISP programmer to flash the bootloader for the first time. Let's add some dedicated pads.
(A) and search for "AVR-ISP-6" under the device tab, and add it to the board
On the top menu, "Place / Add Global Label" and name it SCK
On the top menu, "Place / Add Global Label" and name it MOSI
On the top menu, "Place / Add Global Label" and name it MISO
On the top menu, "Place / Add Global Label" and name it RST
(P) and search for "+5V" symbol and add it to the board
(P) and search for "Gnd" and add it to the board.
Now connect the components like so. You will notice that it is not physically attached to the PCB.
Now double-click on the "J1"
In the footprint section, write "Connector_PinSocket_2.54mm:PinSocket_2x03_P2.54mm_Vertical"
Adding The JST Connector
There are many different ways to connect the PCB to the computer. The teensy uses a mini USB port. A pro micro uses a micro USB Port. Many modern devices use a USB C port. I personally think the best port to use is the JST connector. The JST port has a small footprint and can be manually wired to work with most port sockets after the fact. My choice method is to use a Unified Daughter board, for easy access to USB C. Doing things this way means we can replace the port if it ever brakes off.
(A) and search for "Conn_01x04_MountingPin" under the device tab, and add it to the board
(P) and search for "+5V" symbol and add it to the board
(P) and search for "Gnd" and add it to the board.
On the top menu, "Place / Add Global Label" and name it D+
On the top menu, "Place / Add Global Label" and name it D-
Now connect the components like so. You will notice that it is not physically attached to the PCB.
Now double-click on the "J2"
In the footprint section, write "Connector_JST:JST_SH_SM04B-SRSS-TB_1x04-1MP_P1.00mm_Horizontal"
Here is how my schematic looks after everything is said and done.
PCB Side
Opening the PCB we will find the finished product from the last guide, looking exactly how we left it. Let's remove all of the traces and components that we are no longer using. This can be done by hovering over the component you want to delete and hitting the backspace button.
Now let’s update the PCB, with the changes to the schematic. Press the update button on the top right.
You might remember from the last guide, that kicad is going to dump all of the footprints onto the screen. I am going to hit the hide ratnest button to get rid of the annoying connection guides for now.
Now I'm going to highlight all of the components added to the PCB and hit (F). Most manufacturers will charge more money to add SMD components to both sides of the PCB. For this reason, we are gooing to make sure all of our SMD components are mounted to the backside. The reason we have chosen the backside rather than the front is that the switch diodes must be on the back to not interfere with switches when placed on the PCB.
I'm going to set my grid to 0.1mm, to make placing things a little more precise.
Now it is time to connect all of the logic to the MCU. There are two methods I use to find the components I want. The first is the highlight method and the ratnsnets method
The hilight method
When you are viewing the PCB/ schematic files from inside the “pro” file, and not just selecting the icons, you will have the ability to click the PCB/ or schematic icons at the top of the screen.
Using these two buttons we can quickly swap back and forth between the PCB and schematic. By highlighting or clicking on an item in the schematic file, you will be directly moved to view the same component on the PCB. This also works in reverse when using the (~) button to highlight. With this, we have quick access to the components that we are looking for.
In the photo below I'm showing you how I found R3, the first component I'm looking for. I have the PCB screen on the left and the schematic on the right for an easy switching back and forth.
The ratsnets Method
The ratsnet will show gray lines meant to show what components should connect with one another. This can be useful, expressly for when a project is coming close to completion. Though, In the beginning, stages of a project, when there are many unconnected pads, the ratsnets seams to distract and confuse more than it helps. I tend to keep the restsnest off for the majority of the project.
MU and AU footprint
The footprint of the MCU we are using is both MU and AU compatible. For that reason, we are going to have to connect the pads for each.
The MCU VCC Pads
All VCC must be connected together. I am going to use the space between the MU and AU pads to do this. (This is not required and you can connect VCC pads on the exterior of the footprint also. You are going to notice that I have little holes in the middle of my traces. These are called via, and they act as little anchor points in the PCB that are connected to both the front and back. When a via is made, you can connect both blue and red wires to them. To make a via, while using the trace tool, hit the letter (V). Note: Do Not put vias on top of pads! During the manufacturing process, this can lead to pads without copper.
Here is how I connected the VCC pads.
The MCU Ground Pads
All Ground pads must also be connected together. I am going to use the center area of the footprint. Currently, the center area is not set to be ground, so let's change that by double clicking the center area. I am then going to change the net name to GND.
Now I'm going to connect my ground pads like so.
The MCU Remaining Pads
Now I'm going to connect the rest of the pads on the MCU to one another. This is a tight squeeze. I had to move my vias a little with (M) while selecting them. This is my end result.
Connecting Data Lines (Pin 3 and 4)
Pin 3 corresponds with the D- Resister Denoted as R3 on my PCB
Pin 4 corresponds with the D+ resister denoted as R2 on my PCB
Connecting these components should look something like this.
Connecting Cap (Pin 6)
Pin 6 corresponds with a 1uF Cap, denoted as C3 on my PCB
We will connect the other end to ground on pin 5
Connecting these components should look something like this.
Connecting Crystal (Pin 16 and 17)
Before we add the crystal to the MCU, let’s get it a little more set up. Find the following pieces, on my PCB these are:
Y1 - For the Crystal
C1 - for capacitor 1
C2 - for capacitor 2
Let's connect these things together like so before we continue
Alright, let's drag and attach it to the MCU. Note I'm trying to make enough space to allow access to the other pads.
For a simple PCB like ours, it won't matter much that we can get to every pad, but it's good practice as a full PCB will often require most pads. Below I am showing how every pad can be traced to.
Connecting Cap (Pin 14)
We are going a bit out of order on this one, but it's much easier to place this capacitor now that the crystal is in place. Pin 14 corresponds with VCC, and we are going to add a 0.1uF Cap, denoted as C4 on my PCB.
We will connect the other end to the ground on pin 15.
Connecting these components should look something like this.
Connecting Cap (Pin 24)
Pin 24 corresponds with VCC, and we are going to add a 0.1uF Cap, denoted as C5 on my PCB.
We will connect the other end to the ground on pin 25.
Connecting these components should look something like this.
Connecting Cap (Pin 34)
Pin 34 corresponds with VCC, and we are going to add a 0.1uF cap, denoted as C6 on my PCB.
We will connect the other end to the ground on pin 35.
Connecting these components should look something like this.
Connecting Resistor (Pin 33)
Now that that cap is in place we can add the 10k resistor on pin 33, denoted as R4 on my PCB.
We will connect the other end to the ground on pin 35.
Connecting these components should look something like this.
Connecting Cap (Pin 44)
Pin 44 corresponds with VCC, and we are going to add a 10uF Cap, denoted as C7 on my PCB.
We will connect the other end to the ground on pin 43.
Connecting these components should look something like this.
Now our MCU is properly connected. Here is how mine looks.
Placing our components on the board.
Now it's time to place our ISP ports, JST Connector, and MCU on the board. Do so in any way that fits.
Note you will want your JSP connector to be clear of resistors or switches, as a cable will be coming out of it. Here is how mine looks.
I am going to add another footprint here to add mounting holes for the unified daughter board. Its footprint is located in “random-keyboard-parts/Unified Daughter Board Mounting Holes”.
Some things to keep in mind:
D+ and D- traces should be as close to the same length as possible, to insure USB stability.
Try to keep things clean, and uses as few vias as possible.
After finish up your taces, run the "clean up tacks and vias" option in the tools menu
Make sure to run DRC, and understand any errors and warning you are getting.
Remember to add labels to the MCU in the schematic. Do so in a way that makes sense for the orientation of your MCU on the PCB. After any changes to the shcmatic file you will need to also update the PCB. I am going to pick as follows:
Col0 - Pin 41
Col1 - Pin 40
Col2- Pin 39
Row0 -Pin 38
Row1 - Pin 37
Row2 -Pin 36
After that, all you have to do is connect things. Here is how I did mine.
From here you should be all set, you can go back to the previous guide to see how to generate fabrication files.
Parts References:
Atmega 32u4 - MU (C112161)
Atmega 32u4 - AU (C44854)
Diodes - (C2099)
JST - (C160404)
Other parts should be auto-picked by JLCPCB