# MIDI Keypad

# Design your own MIDI keypad

Made by @KaiPereira

![Photo of Finished PCB](Images/midi-keypad/01-finished-pcb.webp)

Ever wanted to cook up and mix your own beats while simultaneously learning PCB design? Well look no further because your [local Kai](https://github.com/KaiPereira) is about to show you how to make your own custom MIDI keypad completely from scratch.

Now this is YOUR MIDI device, so please use this tutorial as a loose guide and come up with your own custom layout and features to make it awesome; go crazy!! 

We'll be using these core components, and you should use any amount and combination of them for your design:
- EC11 Rotary Encoders
- SK6812 MINI-E Neopixels
- Bourns Slide Potentiometers
- Kailh Choc Low-Profile Switches
- Any other components you want, but I won't walk you through wiring them

And then your actual MIDI keys will use capacitive touch which just uses exposed copper on the PCB which uses the electrical field from your body to detect presses!

## Setting up KiCad

We'll be using KiCad (which you'll need to install) for your PCB design, if you're not familiar with it, don't worry, because this tutorial is totally beginner friendly!

KiCad has tens of thousands of parts for you to use in the editor, but they're still missing a couple which we'll need to install. So [head on over to the library](https://github.com/KaiPereira/Hackclub-KiCad-Libraries) I've made, which includes instructions on downloading these parts we're missing!

Once you've installed the library, we can get right into creating your schematic! The schematic shows how the components on your PCB will be wired, but it doesn't physically place them on your PCB, which we do in another step!

So first launch KiCad and then go "file -> new project" and use the default template and call it whatever you want! Double click on this .kicad_sch file and it'll open up the schematic editor:

![KiCad dashboard](Images/midi-keypad/02-kicad-project-manager.webp)

![KiCad schematic editor](Images/midi-keypad/03-schematic-editor.webp)

There's a couple important keybinds to keep in mind when designing PCBs:
- "a" will open up the symbol library where you can search for symbols/components
- "w" will allow you to create a wire which you'll connect symbols with
- "l" will place a net label down, which essentially says this thing connects to this, similar to a wire, but looks more clean in larger schematics
- "e" will allow you to modify the details of symbols
- "q" will add a no-connect flag (which looks like a blue X) which essentially says nothing wires to this pin which makes your schematic look cleaner and you'll notice me use it a little bit

## Building Your Schematic

### The Microcontroller!

The first thing we're going to add into our schematic, is our MCU or microcontroller. You have 2 options for microcontrollers:
- The [XIAO ESP32-S3](https://wiki.seeedstudio.com/xiao_esp32s3_getting_started/), less IO, cheaper, smaller
- The [Waveshare ESP32-S3-Zero](https://docs.waveshare.com/ESP32-S3-Zero), more IO, more expensive and larger

Add in your chosen MCU in the symbol library using that "a" keybind we talked about:

![MCU in schematic editor](Images/midi-keypad/04-mcu-symbol.webp)

Next, we're going to wire up our power pins, because we'll be using these quite a lot in other spots on our schematic. These are called power labels and you can just find them in the symbol library:

![MCU in schematic editor with power symbols](Images/midi-keypad/05-mcu-power-symbols.webp)

Your voltage labels should always point upwards, and your ground labels should always point downwards because once you make more complicated PCBs, it makes it really easy to read your schematics. You should also never have overlapping wires or text in your schematics, that again makes it hard to read!

### Other Components

Next you have the option of adding your own components for your own customizable MIDI keypad! I'll show you how to wire a couple of these components, and please make your own combination of them, you have total creative freedom:

#### Capacitive Touch Keys

On our MIDI keypad, we can add capacitive touch keys. These use the electrical fields generated by your body to detect if they're being touched and look awesome on your PCB!

![Photo of capacitive keys on my PCB](Images/midi-keypad/06-capacitive-keys-3d.webp)

To wire it, we'll use pin headers to represent each of our keys, so a 01x07 pin headers for 7 keys for example:

![Capacitive keys connector in the schematic editor](Images/midi-keypad/07-capacitive-keys-connector.webp)

All the GPIOs except RX/TX on our Waveshare ESP32-S3-Zero can be used for capacitive touch, but only a couple on the XIAO ESP32-S3 can be used so [check the pinout](https://wiki.seeedstudio.com/xiao_esp32s3_getting_started/) for that MCU.

We'll use net labels to wire these together, so tap "l" and add them in:

![Wiring the capacitive keys](Images/midi-keypad/08-capacitive-keys-wired.webp)

Always add nice wires underneath your net labels so they're easy to read.

#### Low-Profile Switches

If you want to make part of your MIDI keypad have nice keyboard switches, we can easily add some in! You can just wire the switches to ground and if you want even more switches, you should look into wiring them [as a matrix](https://www.dairequinlan.com/2020/12/the-keyboard-part-2-the-matrix/) instead which needs some diodes but lets you have TONS of keys by using up less GPIOs. 

*You would want to get some nice keycaps for your switches.*

![Photo of the low-profile keys in the PCB viewer](Images/midi-keypad/09-switches-3d.webp)

*Note that RX and TX on the Waveshare MCU can be reprogrammed in your firmware to just be normal GPIO pins so they're fine to use for your switches and any other component except the capacitive touch keys which need special IOs.*

![Photo of the keys in the schematic editor](Images/midi-keypad/10-switches-wired.webp)

#### EC11 Rotary Encoder 

The EC11 rotary encoder has both an encoder and a switch if you want to wire it so you can also press it down. I'm only using the encoder part because I don't have much IO left and want to add some more stuff.

![3D model of the rotary encoder](Images/midi-keypad/11-rotary-encoder-3d.webp)

It's pretty easy to wire, it's just 2 IO pins for each direction of the pin and then a ground connection, and you can wire the switch looking part of the symbol like a normal switch or part of a matrix.

![Rotary encoder wired in the schematic editor](Images/midi-keypad/12-rotary-encoder-wired.webp)

#### Bourns Slide Potentiometer

The Bourns slide potentiometer is a large slider you can add to your PCB. You can just wire pins 1 and 3 to ground and +3V3 respectively, and then wire pin 2 to an analog IO to detect its state and then the mounting pins can just be grounded. 

Adding the slide potentiometer will probably increase the cost of your project a fair amount because you can't source it on Aliexpress, but you might be able to find an alternative or something.

*Your slider needs to be wired up to an analog capable pin on your MCU, so check the pinouts  on your MCU again and make sure the pin is ADC capable*

![3D model of the sliders](Images/midi-keypad/13-sliders-3d.webp)

You'll want to use the "R_Potentiometer_MountingPin" symbol for this, and I've renamed my symbols here to make it more obvious what they're actually being used for.

![Sliders wired in the schematic editor](Images/midi-keypad/14-sliders-wired.webp)

#### SK6812MINI-E Neopixels

The SK6812MINI-E neopixels let you add RGB lighting to your keypad. Just wire up the power and ground pins, and then you can chain them together like so. When programming these neopixels, you'll be able to program them as the chain and can control each individually with just that singular pin. 

*These mount on the backside of your PCB and have a hole through the PCB so they can shine through the board*

![3D model of the neopixels](Images/midi-keypad/15-neopixels-3d.webp)

![Neopixels wired in our schematic editor](Images/midi-keypad/16-neopixels-wired.webp)

### Assigning Footprints

Now that we've finished our schematic, which shows the electrical connections between components, we need to assign the footprints which are the actual physical representations of the component on your PCB.

To assign the footprints, tap the "assign footprints" button in the top toolbar. Some of your symbols might already have their footprints assigned, but we still need to assign the ones we're missing:
- The switches (SW_PUSH) can just be assigned the "Kailh Choc Low-Profile Switches" which is inside of the footprint library you downloaded at the start of this tutorial
- The rotary encoder can be assigned the vertical EC11 footprint
- The slide potentiometer can be assigned any size Bourn slide potentiometer you want
- The SK6812MINI-E is auto-assigned
- Leave your capacitive keys footprint empty for now, we'll be making a custom footprint for this!

This is what my footprints look like after:

![Footprint assign window in KiCad](Images/midi-keypad/17-assign-footprints.webp)

## Designing the Actual PCB

Now that you've assigned your footprints, we can start designing the actual PCB. Import all your parts by first tapping "Switch to PCB" in the top toolbar of the **schematic editor**, and then tap "Update PCB from Schematic" in the PCB editor and then update your PCB:

![Components imported into the PCB editor](Images/midi-keypad/18-pcb-imported.webp)

### Creating Our Capacitive Keys

Now the only footprint we're missing is our capacitive keys! Open the KiCad footprint editor (there's a button in the top toolbar of the PCB editor for it), and then go "file -> new footprint":

![Opening the footprint editor](Images/midi-keypad/19-footprint-editor.webp)

Set your grid to 1.0mm in the top toolbar, so it's easier to make precise geometry for your footprint. I would suggest changing your grid constantly to keep accurate and symmetrical geometry, don't make an ugly footprint.

Now this is where you have a lot of freedom. You can make your capacitive keys any shape you want, squares, circles, rectangles, polygons, even drawings if you so wish (you can search up how to do so). I'm gonna make mine look like piano keys for the sake of simplicity, but go crazy.

So go to your right hand toolbar, and add a pad:

![Pad in the footprint editor](Images/midi-keypad/20-footprint-editor-pad.webp)

Tap your pad, and then tap "e" to bring up all of its properties. This is where you can customize your pads to look however you want but you need to do 2 things first:
- Set your pad type to SMD which removes that hole in the pad
- Uncheck the F.Paste layer, which is if you get automated PCB assembly or buy a stencil, which prevents the pads from having solder applied to them

Then set the pad number to 1 for the first pad, this just maps pin 1 on the symbol, to this pad of the footprint, so if you have 7 keys we'll be adding 7 pads labelled 1 through 7.

![Editing the pad in the footprint editor](Images/midi-keypad/21-pad-properties.webp)

Then, you just manipulate the sizes of the pad and move them around to create your footprint. I've gone ahead and built a key footprint by using a bunch of squares and vectors, but just make your capacitive keys any shape you want, just make sure the spacing between copper is at least 0.2mm!

I'd also suggest iterating over your footprint if it doesn't fit your PCB nicely once you add it in. 

![Finished footprint in the footprint editor](Images/midi-keypad/22-capacitive-keys-footprint.webp)

You should also add a courtyard, which just prevents you from putting components physically on-top of your footprint, but if you're careful, you don't necessarily need it, but I'd highly suggest having one: You can add one by tapping the F.Courtyard layer and then drawing something onto it.

*The courtyard is the pink boundary around the footprint*

![Courtyard around the footprint](Images/midi-keypad/23-capacitive-keys-courtyard.webp)

Next, you'll need to create your own footprint library to save this to because the default one is read only and you don't have write permissions for it.

So go "file -> new library" and just call it whatever. I call mine "Kai's Library" and once you save it (I would also name it something like "Capacitive Keys"), you'll notice it show up in your library on the left hand side if you search for it. 

Then go back to your schematic editor and assign the footprint:

![Assigning the new footprint in the footprint selector](Images/midi-keypad/24-assign-capacitive-keys-footprint.webp)

Go back to the PCB editor, and then import it in using the update PCB from schematic:

![Importing the capacitive keys into the PCB editor](Images/midi-keypad/25-capacitive-keys-imported.webp)

### Designing the PCB 

Now the first thing you want to do on your PCB is nicely lay out your components on the PCB, into the general shape you want it to look like. I'd suggest making it under 100x100mm because it makes the PCB cheaper to order, but you have complete creative freedom. Just make sure that if you have neopixels, to flip what side they are on your PCB (using "f") so that they're reverse mounted and shine through the PCB:

![Laying out the components in the PCB editor](Images/midi-keypad/26-pcb-layout.webp)

PCB design is a constantly iterative design process, so when laying out your board, routing it, etc, feel free to move stuff anytime. I would take advantage of the different grids you can use in KiCad to nicely align stuff, this board is mostly made with 1mm, 0.5mm and 0.25mm grids.

Now the first thing I'm actually going to do, is modify the net labels on my schematic so that it's easier to route the boards, and to reduce the amount of those straight blue lines/unrouted traces that we call ratsnest, intersecting:

![Re-wiring our MCU in the schematic editor](Images/midi-keypad/27-mcu-rewired.webp)
![Updating the ratsnest](Images/midi-keypad/28-pcb-ratsnest.webp)

I'm quite experienced at routing PCBs so I'm pretty good at just looking at my board and doing this, but feel free to do it iteratively if you ever have weird crossing traces that aren't the prettiest. 

Next, we'll add in our PCB board edge. Tap the edge.cuts layer on the right hand side, and then tap on the square or whatever shape you want your PCB. I'd suggest putting the USB-C receptacle of your MCU over the board edge so it's easy to plug in, and it'll be handy when you make the case for your keyboard. I'd also suggest rounding your edges, by tapping the outline, tapping "e" and then modifying the corner radius value so your board looks prettier:

![Adding the board edge in the PCB editor](Images/midi-keypad/29-board-edge.webp)

Now we get to actually route the traces for our PCB! You can tap the route button on the right hand toolbar, or you can just tap "x" to start routing. I'm not going to walk you through this, but there's a couple things you should keep in mind:
- Try to avoid 90 degree traces, they're ugly and they become a bigger concern when doing high speed design (we're NOT doing any though) so it's not great to get in the habit of doing it. They are slightly important for the capacitive touch keys because of the nature of those signals, but it's not a major concern
- Don't be afraid to re-route/delete and re-do traces if it's difficult to get somewhere or ugly to do so, it's very common in PCB design. You can tap a trace, and then tap "u" to highlight and delete the entire thing at once.
- Keep the capacitive touch traces away from the other traces because they're sensitive to the noise induced from other signals
- If you add a ground plane to your PCB, don't fill near the capacitive touch keys, or at least pay attention to it, because it'll dampen the signals (if you don't know what I'm talking about, don't worry about it)

You get 2 layers to route your PCB on, the F.Cu and B.Cu layer. You can transition between these layers by placing down a via (which is essentially a tiny plated hole on your PCB) while routing on one of them, so while routing, you can just tap "v" and it'll add a via to the end of your trace, and once you place it down, you'll transition to the other layer.

You'll want to route all of your capacitive touch keys first, and try to minimize their length, and just pay attention to them. I'd suggest routing those traces on the front layer, and then routing all the other traces on the back layer. I'm experienced at routing PCBs so don't worry if your boards are a bit uglier:

![Starting to route the top layer](Images/midi-keypad/30-routing-started.webp)

I'm a bit of a perfectionist, so this is what my final board routing looks like:

![Finishing routing the top layer](Images/midi-keypad/31-routing-top-layer.webp)

![Finishing routing the bottom layer](Images/midi-keypad/32-routing-bottom-layer.webp)

![Final photo of the board routed](Images/midi-keypad/33-routing-finished.webp)

### PCB Art and Finishing Touches!

Next, it is an absolute necessity to make our PCB look beautiful by adding art. We do this by moving to the silkscreen layer! F.Silkscreen is the front art, and B.Silkscreen is the back art.

The KiCad project manager window has an image converter which is really useful for converting your images to silkscreen! 

![Top silkscreen on the PCB](Images/midi-keypad/34-front-silkscreen.webp)

![Bottom silkscreen on the PCB](Images/midi-keypad/35-back-silkscreen.webp)

![3D viewer of our art on our PCB](Images/midi-keypad/36-silkscreen-3d.webp)

Next, we need to verify that our PCB is ready for manufacturing. We can test this by the "DRC" or design rules check in the top toolbar. So tap the button and check for errors:

![Running DRC in the PCB editor](Images/midi-keypad/37-drc.webp)

All the warnings can be ignored and same with the board edge clearance violations for the *neopixels*. Those are essentially just saying that our pads might be slightly cut off during manufacturing, but that's fine because they're large pads and we'll be hand-soldering them.

So if everything's good, we're onto the final steps!

### 3D Models

Let's add all the 3D models in for our components that don't have one yet. This will make it easier to design the case for our keypad, and will also let us take polished photos of our project. I've added all the 3D models [into the GitHub repository](https://github.com/KaiPereira/MIDI-Keypad/tree/master/PCB/models) for this tutorial, so go ahead and install the ones you need!

If you only have a couple of the component on your board, you should just tap the footprint, tap "e" and then go to the 3D model tab, and then add in the model and move it, for each footprint. But if you have quite a few of that footprint, I would suggest making a copy of the new footprint with the 3D model to your library and then just selecting it for all of that footprint on the board.

![Adding in the rotary encoder 3D model](Images/midi-keypad/38-rotary-encoder-3d-model.webp)

And just like that we're done our PCB!

![PCB is finished](Images/midi-keypad/39-pcb-finished.webp)

## Fabrication

Now that we're done our PCB, we can actually prepare it for manufacturing.

Before we do anything, make sure that you've run DRC and it's clear of errors that matter, and that your PCB looks fairly polished and nice :D

Next, we're going to install the JLCPCB fabrication toolkit, which is essentially a one-click button that exports all the files we need in order to manufacture our project. The repository nicely goes over how to install it: https://github.com/bennymeg/Fabrication-Toolkit

Once you reload KiCad, you'll see the button pop up at the end of the top toolbar, or you can go "tools -> external plugins -> Fabrication Toolkit" to open it up. And then just simply click generate and it'll make all your production files. If you ever edit your PCB again, make sure to re-generate your fabrication files:

![Running the JLC fabrication toolkit in the PCB editor](Images/midi-keypad/40-fabrication-toolkit.webp)

And now if you go into the /production folder it generated, you'll see the:
- Gerbers which is the zip folder and contains all the data for the layers on your PCB
- The bom.csv or "bill of materials" which has all your components in it
- the positions.csv which essentially just says the orientation and placement of those components on your PCB

And there's some other files, but you don't need to worry about those. 

![File finder with my production files](Images/midi-keypad/41-production-files.webp)

Now we can go over to https://jlcpcb.com/ to order our PCB. Just tap order now, and then upload your gerbers zip file:

![Importing the files into JLCPCB for a quote](Images/midi-keypad/42-jlcpcb-quote.webp)

For ordering your PCB, I would suggest:
- Changing your shipping to whatever's cheapest to minimize the cost
- If it's cheap, selecting ENIG surface finish so that the exposed copper on your keys doesn't oxidize which can look a bit ugly. If you use ENIG, you should try some exposed copper art on your PCB because it'll look nice and golden! 
- Any other customizations you'd like within budget :D

## Final Steps

You're on the final steps, and you just have to do a couple more things to get your project ready to be shipped!

You need to make a proper BOM or Bill of Materials for your project. This is just a spreadsheet you can export as a .csv with all your parts, where you're going to buy them and their price. I would take a look at [Sourcing Parts](/docs/sourcing-parts) on how to do this!

And then you should make a basic firmware file for your project so it's easy to program once you receive your parts and have soldered your PCB. I would suggest using [KMK](https://github.com/KMKfw/kmk_firmware/blob/main/docs/en/Getting_Started.md) for this but you're free to use whatever, just make sure your firmware supports the ESP32-S3.

And then finally, you need to properly ship your project. Take a look at [Shipping step-by-step](/docs/shipping-steps) to see how to do this!

Once you receive your parts, it's relatively easy to solder them. Just watch a couple videos online on how to do so, and you'll be golden!

Congrats on making your MIDI keypad :D If you liked this tutorial, you'll probably like some of my other work too and should consider [giving me a follow](https://github.com/KaiPereira) on GitHub and [starring the repository](https://github.com/KaiPereira/MIDI-Keypad) for this tutorial.

Happy hacking, and I'd love it if you sent me your finished builds of your MIDI keypads on Slack (@Kai the Jolly Guy) or by email which you can find on [my website](https://kaipereira.com/). 
