# Designing your PCB

## Setup
For this guide we're going to be using [KiCad](https://www.kicad.org), which is an open source PCB designer tool.

KiCad comes with a bunch of libraries of common components, but not all are included. For this guide, we'll have to download the symbol and footprint for our Seeed Studio XIAO ESP32C3, go to [the Seeed docs page](https://wiki.seeedstudio.com/XIAO_ESP32C3_Getting_Started), and near the bottom, download the KiCad Footprints and KiCad SCH Symbols.

Once you have those downloaded, open KiCad and make a new project. `File - New Project`

Now we can tell KiCad about those new symbols and footprints we downloaded. Go to the Manage Symbol Libraries tab `Preferences - Manage Symbol Libraries...` and add a new row linked to your `Seeed_Studio_XIAO_Series.kicad_sym` file. Do the same in the Footprint Libraries tab, add a new row linked to `Seeed_Studio_XIAO_Series.pretty`.

## Drawing the schematic

**Note before we start** - Make sure you're not following this guide 1:1, you should have something unique about your clock, could just be something as simple as a unique layout, but if you find yourself copying directly, stop yourself!

The schematic of a PCB is what defines all the different connections of your PCB, so we're going to start with it first!

First, open up KiCad and create a new project, then click on the `Schematic Editor` button:

![schematic-editor](Images/schematic-editor.webp)

This should open up the schematic editor. Once you're in, press the A key on your keyboard. This should open up a menu where you can add components. Search for the following and add them:

- `XIAO-ESP32-C3-SMD` (This will be our microcontroller!) (Ignore the SMD, it's the same for both!)
- `SW_Push` (this will be our switch! copy this 4 times)
- `Buzzer` (self explanatory)
- `Conn_01x08_Pin` (This will be our screen!)
- `MountingHole` (Holes for our screws, copy this 4 times)

After, your schematic should look something like this:

![schematic-unwired](Images/schematic-unwired.webp)

Next, we need to actually wire these components together! To do so, press the `W` key on your keyboard. This should make a green wire start to appear.

![schematic-wired](Images/schematic-wired.webp)

* To get the GND and +3V3 symbol, press `P` and search for it!
* To get the labels, like SCL and SDA, press `L` and type what you want to name it! Labels are kinda like wireless connections, and they make it much easier to keep a clean schematic!
* Press `R` to rotate components
* Press `Q` over pins to mark them as "no-connect" with a little x

**Note** - I connected all of my display wires to GPIO pins because I had enough, if you're using more switches and find yourself running out of GPIO, you can connect BL to GND and RST to 3.3V.

Once all the components are connected, we can start assigning footprints to the symbols we have here. Footprints are what gets physically drawn on the PCB. To do this, click the `Run footprint assignment tool` in the top right.

![footprintassign](Images/footprintassign.webp)

This should open up a window where you can assign different footprints to your components! Assign them based on the image below:

![footprint-assign](Images/footprint-assign.webp)

Once you're done, you can hit apply & save schematic. We're now officially done with the schematic! Onto making the physical PCB itself:

## Route the PCB

Go back to KiCad project page, and hit the `PCB Editor` button. Once the PCB editor is open, hit the `Update PCB from schematic` button in the top right:

![updatepcb](Images/updatepcb.webp)

It should have dumped all the components on the page. Right click the ESP32, buzzer, and 8 pin connector, and click "flip side". This should flip the footprint to the other side - this means when soldering, the keyswitches will be on the front of the pcb, and the rest will be on the back (inside the case)

After that, arrange all the components like so:

![pcb-unrouted](Images/pcb-unrouted.webp)

Now it's time to route the PCB! Hit X on your keyboard and hit any pad with a blue line coming off it. It should dim the entire screen and show you where to go. Route the PCB like so:

![pcb-routed](Images/pcb-routed.webp)

(to get the blue lines, change the layer on the right from `F.Cu` to `B.Cu`, or press `V`!)

Our PCB is almost done, but we need one final step; we need to actually define the size of the board! Head on over to `Edge.Cuts`, and draw a rectangle outline for our board:

![pcb-boxed](Images/pcb-boxed.webp)

(you can use the `Measure Tool` on the right sidebar to see the size of your PCB! Make sure it's under 100mm in both directions)

## Finishing up

After I'm happy with my routing, I like to make some small changes to help make my board more polished and unique! For this board, I just rounded the corners and did some edits to the silkscreen.

![pcb-finished](Images/pcb-finished.webp)

(PS: You can hit the `3D Viewer` button in the top right(ish) for a cool view of your PCB!)

![pcb-render](Images/pcb-render.webp)

Some of your footprints might not automatically have 3D models associated with them, to add one, go to the footprint properties (Right Click - Properties, or `E`), `3D Models` tab, then find your model in the file explorer.

You can find 3D models in many places, my favorite is [GrabCAD](https://grabcad.com/library), just search for what you need and sort by popular!

* Note - I'm SMD soldering my XIAO, so it's sitting right on the board, if you're using header pins to solder yours, it will sit a bit further away from the board.

## Exporting

Once you're happy with your PCB, it's time to export the files!

Files you'll need:
- `.kicad_pcb` - PCB design file
  - In project source file
- `.kicad_sch` - Schematic design file
  - In project source file
- `.kicad_pro` - KiCad project file
  - In project source file
- `Gerber` files - How you'll make your PCB! PCB manufacturers like JLCPCB take a .zip file of your gerbers to know how to make your PCB. 
  - `File - Fabrication Outputs - Gerbers - Generate Drill Files and Plot`
- `.step` of PCB - 3D model
  - `File - Export - STEP`


If everything was done correctly, you are now officially done with the PCB!