Master your custom keyboard journey

How to Build a Custom Keyboard From Scratch | Part 1 Layout and Design

Estimated read time: 1:20

    Learn to use AI like a Pro

    Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.

    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo
    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo

    Summary

    In this video from Casual Coders, viewers are guided through the initial steps of designing and building a custom mechanical keyboard from scratch. The process kicks off with understanding essential electronic components and interpreting data sheets for microcontrollers. The journey involves creating a detailed keyboard layout using a keyboard layout editor, where keys are arranged in a grid system using JSON for easy customization. The video also dives into setting up a switch matrix, which optimizes the design for microcontroller usage and prevents ghosting. The importance of selecting the right microcontroller and planning additional features like OLED displays and RGB LEDs is emphasized, laying the foundation for moving onto PCB design in the upcoming Part 2.

      Highlights

      • Learn the basics of designing a custom keyboard, starting with electronic components. ⚡
      • Master the keyboard layout using JSON formatting in a layout editor. 🖥️
      • Set up a switch matrix to efficiently use microcontroller pins and prevent ghosting. 🕹️
      • Select a microcontroller that fits your feature needs, like OLED displays or RGB LEDs. 🌈
      • Prepare for more in-depth steps on PCB design in Part 2! 🚀

      Key Takeaways

      • Understand essential electronic components before starting your custom keyboard build. 🔍
      • Use a keyboard layout editor to customize your key arrangement efficiently. 💻
      • A switch matrix is essential for optimizing microcontroller usage and preventing ghosting. 🔄
      • Choose the right microcontroller for your keyboard's needs, and verify compatibility with desired features. ⚙️
      • The journey continues with PCB design and assembly in upcoming tutorials! 📏

      Overview

      Building a custom keyboard is as cool as it sounds, but diving in headfirst is not for the faint-hearted. You start by familiarizing yourself with the critical components, from resistors to microcontrollers, making sure no electronic stone is left unturned. This first step ensures your foundation is rock solid as you embark on designing from scratch.

        Next, step into the world of layout design. Here’s where a keyboard layout editor becomes your new best friend. Tinkering with JSON might sound like a daunting task, but it's your gateway to a tailored keyboard feel. Setting keys, adjusting with modifiers, and exporting your work as PNG are all part of the artful science. All of this cleverly fits together to form the keyboard's core - the switch matrix.

          Choosing the right microcontroller is where your custom keyboard truly starts to take shape. Between factoring in voltage needs, extra hardware like displays or LED preferences, and understanding data sheets, your board’s brain is carefully crafted. With a solid schematic layout, Part 2 promises to dive into the intricacies of PCBs and bring your customized creation to life.

            Chapters

            • 00:00 - 00:30: Introduction to Custom Mechanical Keyboards This chapter introduces viewers to the process of designing, building, and programming a fully custom mechanical keyboard from scratch. It emphasizes the importance of having a basic understanding of electronic components such as resistors, capacitors, diodes, crystals, microcontrollers, and LEDs. The chapter advises doing some preliminary research on these components and learning to read and interpret data before beginning the project.
            • 00:30 - 01:00: Project Overview and Considerations The chapter titled 'Project Overview and Considerations' provides insights into developing a project using a microcontroller. It highlights the complexity and time-consuming nature of the project, suggesting that it may not be suitable for beginners or newcomers to electronics. The chapter breaks down the project into four main steps: layout, schematic, PCB, and assembly. While soldering is usually required during assembly, the option of machine assembly is available, which might be ideal for those lacking the time or skills for manual soldering. The tutorial will take the most challenging route for demonstration purposes.
            • 01:00 - 03:00: Keyboard Layout Design In this chapter, the focus is on designing a keyboard layout for DIY keyboard enthusiasts who might want to hand solder their own boards. The chapter emphasizes the importance of starting with a proper layout and introduces the Keyboard Layout Editor as a key tool, despite its complex graphical user interface. The process involves editing the raw JSON format to define the keyboard layout starting with square brackets and comma-separated lists of keys, illustrating that while the interface may seem intimidating at first, it is manageable.
            • 03:00 - 05:00: Switch Matrix Design This chapter explains the fundamentals of designing a switch matrix for a keyboard, using the numpad as a base example. The author demonstrates how to modify the width and height of keys using the 'W' and 'H' modifiers. The process involves adding these modifiers in curly braces next to the key, separating them with commas. The example given expands the 'two' key to be two units wide and the 'four' key to be two units high.
            • 05:00 - 07:00: Microcontroller Selection This chapter discusses methods of positioning and rotation in microcontroller selection. It explains how to utilize X and Y modifiers to adjust spacing and position. X modifier is used for horizontal adjustments while Y modifier shifts the positioning vertically. For example, adding 'X:1' creates space between components in the same row, and 'Y:1' moves a row downwards. These adjustments can be reversed using negative values, like 'Y:-1'. Additionally, the text briefly introduces the rotation capability using the R modifier.
            • 07:00 - 09:00: Additional Features and Considerations The chapter discusses how to apply rotation to a keyboard layout, using the example of rotating a row by degrees. It explains that using 'X' as the rotation axis causes the key to move in space, and suggests using 'RX' or 'RY' for horizontal and vertical movements relative to the rest of the keyboard. The chapter uses the Ergodox preset as an example, demonstrating how to work around rotation effects. It also mentions the availability of presets in the menu bar to help users start from a predefined layout, thereby reducing the amount of work needed to create a new layout.
            • 09:00 - 10:00: Conclusion and Next Steps This chapter offers guidance on concluding the keyboard layout design, emphasizing crucial steps like saving layout visuals as PNG and storing raw JSON data for further use. It highlights an essential consideration for choosing keycaps, encouraging users to ensure availability for their specific layout needs. The discourse humorously notes the difficulty in acquiring certain keycaps without a significant cost. The chapter sets the stage for the next major step in the keyboard building process—constructing the switch matrix, which is fundamental for the microcontroller to accurately register key presses in a limited capacity setup.

            How to Build a Custom Keyboard From Scratch | Part 1 Layout and Design Transcription

            • 00:00 - 00:30 so you want to make your own fully custom mechanical keyboard from scratch but don't know where to begin this video seeks to walk you through the process of Designing building and flashing your custom keyboard to begin it's important to have a basic understanding of some electronic components such as resistors capacitors diodes crystals microcontrollers and LEDs if you're unsure about any of these it's a good idea to do some research before starting this project additionally it's important to be able to read and interpret data
            • 00:30 - 01:00 sheets for at least your chosen microcontroller this project is likely to be complex and time consuming so it's probably not a good idea for beginners or those who are brand new to electronics this project can be broken down into four main steps layout schematic PCB and assembly while soldering is typically required for assembly it is possible to skip this step by using machine assembly this may be a good option for those who don't have the time or expertise to do the soldering work themselves this tutorial will assume the most difficult but you
            • 01:00 - 01:30 plan to hand solder the board yourself let's start with the most important part the layout whether you like 40 60 or 110 boards you need a template keyboard layout editor is the tool for the job which you can see here we're going to ignore the somewhat complicated GUI and just edit the raw Json it may look scary or complicated but it's really not that bad take a look we can start a row by opening square brackets and putting our keys in this comma separated list like so we can add another row by adding a
            • 01:30 - 02:00 comma to the end of the line and doing the same thing over again here I'm left with a simple approximation of a numpad to expand upon this we can use the W and H modifiers to change the width and height of our keys I'll modify my two key to be two units wide and I'll modify my four key to be two units high by opening a curly brace typing W colon 2 and closing the curly brace don't forget to add a comma to separate the modifier from the key text
            • 02:00 - 02:30 finally we can discuss positioning and rotation positioning uses the X and Y modifiers I can add a space between my one and two keys by opening a curly brace typing X colon 1 and closing the curly brace don't forget to add a comma similarly I can move my second row down by adding a y colon 1 at the beginning of my second row note that this moves the whole row it can be shifted back up by doing y colon negative one and rotation you can use the r modifier
            • 02:30 - 03:00 to apply a rotation in degrees note that this rotates the entire row using X causes our key to float out here in space we can use RX or Ry to move horizontally or vertically relative to the rest of the keyboard ignoring rotation see the ergodox preset for an example of this aren't with this knowledge you should now be able to complete your layout note that there are presets for boards up in the menu bar so you can save yourself some work by starting from a base once you've created a layout you're satisfied
            • 03:00 - 03:30 with download it as a PNG and save the raw Json we'll use the PNG image when we create our switch Matrix later one last important thing regarding layout pertains to keycaps make sure the keycaps are available for your chosen layout I've struggled to find f13 through f24 caps that don't cost at least one of my kidneys with our layout complete let's move on to the switch Matrix a switch Matrix is a grid of keys in rows and columns that allows a microcontroller to detect which keys are being pressed using a limited number of
            • 03:30 - 04:00 inputs and outputs IO this is necessary because most microcontrollers don't have a large number of eye opens making it impractical to assign each key its own pin by using a switch Matrix we can have many keys on fewer pins making the design more efficient good designs also include diodes which prevent ghosting ghosting can occur when multiple keys are pressed simultaneously causing the incorrect key to be registered open the key map you just exported from kle in your favorite gnu image
            • 04:00 - 04:30 manipulation program and draw some lines these lines will make up The Columns of our switch Matrix if you're using a more typical rectangular board the rows should be self-explanatory if not godspeed just kidding you should also draw rows note that only one key can exist on a given row and column color coding your lines should help with visibility but if you're a masochist use yellow on a white background to be maximally efficient you need to use a square for your switch Matrix in other words the number of columns must match
            • 04:30 - 05:00 the number of rows this can lead to a high degree of difficulty in routing however so it is recommended to use the smallest number of rows and columns that is reasonable and easy to Route keep in mind that wires need to connect between each key and if you're designing a PCB your wires cannot intersect for my example keyboard I get a map that looks something like this sum up the rows and columns because now it's time to talk microcontrollers this tutorial covers the qmk software but you're free to use
            • 05:00 - 05:30 any software you'd like if you plan to use qmk you'll need to pick up one of these supported microcontrollers the most common seems to be the atmega32u4 if you need a ton of i o for a large build like mine I'd recommend looking at the 1890 USB lineup or an stm32 this tutorial targets implementing a raw microcontroller but you can totally use a pre-made Dev board or module in fact that may be a better place to start if you don't have a ton of soldering experience but still plan
            • 05:30 - 06:00 to hand solder as the pads are larger and the tiny soldering work has been done for you start by selecting any of the listed microcontrollers that you can find in stock then take a look at its data sheet the most important feature to pay attention to is the gpio you'll need at least enough gpio to cover the rows and Columns of your switch Matrix now is also a good time to think about your microcontroller's package make sure it's something you can solder take some time to think about your desired feature set as well do you want an OLED display a rotary encoder RGB LEDs each of these
            • 06:00 - 06:30 features may impact your required i o or choice of microcontroller for example an OLED display such as the SSD 1306 will require a microcontroller that supports I squared C or SPI communication I squared C is generally easier to implement because it requires fewer connections but it may not be suitable for all types of displays or microcontrollers check your selected micros datasheet for more information you should also verify that qmk supports
            • 06:30 - 07:00 your chosen OLED a typical rotary encoder requires two dedicated i o pins for its rotation axes some encoders also have a push switch which can be included in your switch Matrix to conserve i o you can Matrix multiple encoders rotary axes together which is covered in more detail in the qmk documentation there are many types of RGB LED but my preference is the ws2812 LEDs as only a single wire is required to communicate with more than 100 LEDs this is because each LED
            • 07:00 - 07:30 communicates with the next in the chain additionally no special features are required to use these note that the more LEDs there are in the chain the lower their refresh rate up to 200 per change should be safe but refer to the data sheet for more information another very important property to pay attention to is your microcontroller's operating voltage if it takes 5 volts you can safely connect it straight to USB power but you'll be required to include a voltage regulator if it takes a different voltage such as 3.3 volts
            • 07:30 - 08:00 here's a small table that compares some of the more common options now that you know what your layout looks like what microcontroller you're going to use and the add-ons you'd like it's time to start the schematic which we'll do in part two subscribe if you found this helpful and let us know what I missed or what you'd like to see in the comments below