Giter VIP home page Giter VIP logo

kicad-kbplacer's Introduction

icon kicad-kbplacer

KiCad Repository Downloads CircleCI PyPI Coverage Status Weblate

KiCad plugin for mechanical keyboard design. It features automatic key placement based on popular layout descriptions from keyboard-layout-editor and ergogen.

Table of Contents

Motivation

All PCB's for mechanical keyboards shares common properties which creates great opportunity for scripting. Although this project does not aim to provide complete automatic PCB generation tool it speeds up development process by reducing tedious element placement and routing tasks.

Features

  • Automatic keys and diodes placement
  • Key rotation support
  • Basic track routing
  • User selectable diode position in relation to key position
  • Configurable additional elements placement

Warning

Ergogen support is new experimental feature and it has not been tested extensively

demo

Some examples can be found in examples directory.

Installation

As KiCad plugin

To install release version of this plugin, use KiCad's Plugin and Content Manager and select Keyboard footprints placer from official plugin repository.

pcm

To install development version, see how to use custom plugin repository. Custom repository is automatically updated with latest master branch builds and it is available here.

For development activities, it is recommended to checkout this repository and copy (or link) content of kbplacer directory to one of the KiCad's plugin search paths. For more details see this guide.

After installation, plugin can be started by clicking plugin icon on the toolbar:

plugin-icon-on-toolbar

or selecting it from Tools -> External Plugins menu. For more details about plugin usage see Use from KiCad section.

As python package

The kbplacer can be installed with pip:

pip install kbplacer

When installed this way, it can't be launched from KiCad as KiCad plugin. This option exist for usage via command line interface or for integrating with another tools.

Command line interface provides more options but generally it is recommended for more advanced users. For example it allows to create PCBs without schematic, which is non-typical KiCad workflow. For details see Use from CLI or from another tools section.

Important

Most of the kbplacer python package functionalities depends on pcbnew package which is distributed as part of KiCad installation. This means, that on Windows it is required to use python bundled with KiCad. On Linux, pcbnew package should be available globally (this can be verified by running python -c "import pcbnew; print(pcbnew.Version())") so it may not work inside isolated environment. To install inside virtual environment created with venv it is required to use --system-site-package option when creating this environment.

Note

Both installation methods can be used simultaneously. When installed as KiCad plugin, some scripting capabilities are still available, but in order to use kbplacer in another python scripts, installing as python package is required.

Use from KiCad

This is traditional way of using this tool. Before it can be used on kicad_pcb project file, user needs to create it and populate with footprints. In typical KiCad workflow this is started by creating schematic. When PCB file is ready, user can start kbplacer plugin in GUI mode from KiCad and run it with selected options. To use this tool in this way, it needs to be installed following plugin installation guide.

  • Create switch matrix schematic which meets following requirements:

    • Each switch has dedicated diode with same annotation number
    • Symbols are ordered by Y position
    • Diodes are column-to-row configuration (COL = Anode, ROW = Cathode)

    schematic-example

    [!NOTE] Other matrix configurations are also supported. Track router will attempt to connect closest (to each other) pads of switch and diode as long as both have same netname, i.e. are connected on the schematic

  • Create new PCB and load netlist

  • Obtain json layout file from keyboard-layout-editor or convert ergogen points file to json

    keyboard-layout-editor details

    kle-download

    Plugin supports internal kle-serial layout files and via files. Detection of layout format will be done automatically. Conversion between layout downloaded from keyboard-layout-editor and its internal form can be done with https://adamws.github.io/kle-serial or keyboard-tools.xyz/kle-converter

    [!NOTE] When using via layouts, switch matrix must be annotated according to via rules. If layout supports multiple layout of keys only the default one will be used by kicad-kbplacer.

    ergogen details
    • open your design in https://ergogen.cache.works/ and download points.yaml

      ergogen-points

    • convert yaml to json (this operation is not integrated with kicad-kbplacer source because it would require installation of third-party pyyaml package and there is no good way to manage plugin dependencies yet)

    • converted file should be automatically recognized in next steps

  • Run kicad-kbplacer plugin

  • Select json layout file and plugin options and click OK.

    plugin-gui

It is possible to run this plugin from command line. Everything which can be done via GUI can be also achieved using command line. Execute following command (in the directory where plugin is installed) to get more details:

python -m com_github_adamws_kicad-kbplacer --help

Important

On windows, use python bundled with KiCad

Options overview

Section Label Description
Switch settings Footprint Annotation The switch footprint annotation format with single replacement field {} which will get replaced with incremented footprint number. This string is internally used by python's str.format function.
Keyboard layout file Layout file path. Supports keyboard-leyout-editor json layouts in both raw and internal form, via json layouts and ergogen canonical yaml points files converted to json.
Can be empty to run without switch footprints placement.
Step X / Step Y Distance (in millimeters) of 1U between two switches in X and Y directions.
Switch diodes settings Allow autoplacement Enables automatic diodes positioning. When turned on, each diode will be placed next to the switch footprint of the same annotation number, according to the position settings. When disabled, diodes will not be moved.
Route with switches Enables automatic routing of switch-diode pairs. If user manually route first pair, then it replicates the connection for remaining pairs. If not, uses automatic internal router. When automatic router used, attempts to connect only two closest pads of the same net.
Footprint annotation The diode annotation format. Same rules as for switch footprint annotation applies.
Position Diode position option with three possible choices:
Default - positions diodes to default position
Custom - positions diodes based on user defined values
Relative - uses first switch-diode pair to get relative position between them and uses that as reference position for remaining pairs
Preset - uses provided kicad_pcb template file to get relative position and tracks for replication for all switch-diode pairs
Offset X/Y Distance (in millimeters) from the center of switch footprint to the center of diode footprint. Accepts floating values with . (dot) decimal separator.
Applicable only for Custom position option.
Orientation Angle (in degrees) of diode footprint. If switch is rotated it will be automatically adjusted to match switch rotation
Applicable only for Custom position option.
Side Selects Front or Back side of the board.
Applicable only for Custom position option.
Load from
/
Save to
The preset kicad_pcb file path to use when position option is equal Preset or optional file path to store current position and tracks when position option is equal Relative.
Additional elements settings - This is equivalent of Switch diodes settings section with these exceptions:
1) It is possible to add/subtract elements from the list using +/- buttons
2) Allow autoplacement option is missing, footprints which should not be moved should not be added to the list
3) Footprints from this sections are not routed
Other settings Route rows and columns Enables/disables automatic routing of keyboard switch matrix. Works by finding all pads with nets matching COL(\d+) and ROW(\d+) regular expressions (ignoring case) and connecting them using simplified internal router. Configuration of row/column naming scheme is not yet supported.
Controller template circuit file Path to kicad_pcb template file which can be used for placing/routing repetitive parts of the PCBs. It is expected that user creates own templates.
This is optional and not very well documented process.

Diode placement and routing

By default diodes are placed like shown below. This placement may not work for all switch and diode footprints combinations.

Before After
default-before default-after

To use custom diode position there are two available options. Either select Custom in Position dropdown and define X/Y offset, Orientation and Front or Back side:

custom-position-example

or manually place D1 diode to desired position in relation to first switch and run plugin with Relative Position option selected.

current-relative-position-example

Remaining switch-diode pairs will be placed same as the first one. To save current template, set Save to path. This can be later re-used with Preset Position option.

Before After
custom-before custom-after

Some custom diodes positions may be to difficult for router algorithm. In the above example it managed to connect diodes to switches but failed to connect diodes together.

Switch-to-diode routing is not done with proper auto-routing algorithm and it is very limited. It attempts to create track in the shortest way (using 45° angles) and doesn't look for other options if there is a collision, leaving elements unconnected.

Track templating

If first switch-diode pair is routed before plugin execution, as shown below, kicad-kbplacer instead of using it's built in routing algorithm, will copy user's track. This allow to circumvent plugin's router limitations. This is applicable only for Relative Position option. When Save to path defined, tracks will be stored in template. Then it can be re-used when using Preset Position option.

Before After
custom-with-track-before custom-with-track-after

Note

Track templating is recommended for more complicated switch footprints, for example reversible kailh. When switch footprint has multiple pads with the same net name, automatic router would try to connect only the two closest pads between diode and switch.

Below example shows more complicated custom diode position with track template pre-routed by the user. Manual work needs to be done only for first switch-diode pair, plugin will replicate layout for the remaining pairs:

track-template-comples

Warning

All footprints for diodes and switches must have same pad layouts, otherwise connection replication may yield unexpected results

Additional elements placement

In case additional elements need to be automatically placed next to corresponding switches (for example stabilizer footprints if not integral part of switch footprint, or RGB LEDs), define entries in Additional elements settings section. It behaves very similarly to switch diodes options with few exceptions:

  • there is no default position defined
  • there is no track routing

Run without layout

Creating tracks or placing switch associated elements (like diodes) does not require layout file. With empty Keyboard layout file field, switch placement is simply skipped. Placing and routing of other elements will use already placed switches as reference points and won't move them. This might be useful for PCB files generated by other tools, for example ergogen.

This works with custom diode positions and track templating.

Use from CLI or from another tools

Run as a script

The kbplacer module might be executed as a script using python's -m command line option.

python -m kbplacer

This is command line equivalent of running this tool as KiCad plugin but without GUI interface. Run it with --help option to get more details about options and CLI usage.

Use in python projects

Some kbplacer functionality might be reused in another projects. For example, to parse raw KLE data to it's internal form run:

from kbplacer.kle_serial import parse_kle
keyboard = parse_kle([["", ""]])
print(f"This keyboard has only {len(keyboard.keys)} keys")

It can also create and manipulate kicad_pcb files. This enables non traditional KiCad workflows where schematic preparation can be completely skipped. For example see keyboard-pcbs repository. It demonstrates how to create .kicad_pcb file with switch matrix from scratch.

Warning

This is work in progress. Creating keyboard PCBs without schematic is not recommended for inexperienced users. Internal kbplacer API is not stable.

This package is also key component of keyboard-tools project.

Demo keyboard project

For example keyboard project see demo directory. This project contains 4x4 switch matrix with layout json files in raw (kle.json) and internal (kle_internal.json) formats. It requires keyswitch-kicad-library to be installed. Use this project to validate plugin installation.

Troubleshooting

Plugin does not load

If plugin does not appear on the Tools -> External Plugins menu and its icon is missing on toolbar, launch python scripting console Tools -> Scripting Console and type:

import pcbnew; pcbnew.GetWizardsBackTrace()

This should return backtrace with an information about the fault. Include this information in bug report.

Plugin misbehaves or crashes

  • Read stacktrace in error pop-up
  • See kbplacer.log file, created in PCB directory

For bug reports please use this template.

kicad-kbplacer's People

Contributors

adamws avatar weblate avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.