KiCad keyboard PCB generator

jeroen94704

23 Apr 2020, 09:28

Hi,

I've been wanting to create my own custom keyboard PCB's for a while, but was always put off by the prospect of having to manually position dozens of switch footprints correctly. Therefore, I did what every self-respecting software engineer would do and created a script that takes a layout from the Keyboard Layout Editor and generates a KiCad project (schematic + layout) out of that. It's pretty bare-bones at this point, and still misses some features I think are required (ISO-enter, rotated keys), but I thought it might be of interest to some here anyway. You can find the generator on github:

https://github.com/jeroen94704/klepcbgen

If anyone tries it feel free to provide feedback (both good and bad), so I can make improvements going forward.

Here are a couple of renders of the first PCB I created using this script (it's currently on order):

Image
Image

Regards,

Jeroen
Last edited by jeroen94704 on 23 Apr 2020, 11:18, edited 2 times in total.

Findecanor

23 Apr 2020, 11:16

Cool stuff. I'll definitely take a look and steal your ideas. ;)
I've done something similar: creating KLE and DXF output from a Python program (computed layout).

BTW, You haven't posted a license/copyright information.

jeroen94704

23 Apr 2020, 11:33

Thanks, I indeed forgot to add the license. Fixed now.

What was the input of your program that you generate a KLE output from?

Findecanor

23 Apr 2020, 12:34

jeroen94704 wrote:
23 Apr 2020, 11:33
What was the input of your program that you generate a KLE output from?
Oh, they were hardcoded into the Python program. I had to express the relations of keys to other keys in various ways: to rotate them while avoiding that they bump into other keys.
It's your KiCad output code that I want to steal. :evilgeek:

jeroen94704

23 Apr 2020, 13:07

It's all based on Jinja templates, which I've come to like a lot. I'm still tinkering with it though, and right now I feel it's pretty fragile, in the sense that the code and the templates cannot change independent of each other. This is because of the way nets work in the kicad layout format. I'm sure there is a better way to handle that though, preferably by letting KiCad do the work for me.

User avatar
swampangel

23 Apr 2020, 22:19

Wow, thanks so much for sharing this. I had dreamed about building a tool like that, but never took it past learning the very basics of kicad. Excited to try this code. :D

User avatar
ddrfraser1

24 Apr 2020, 17:58

This is awesome! Unfortunately I can't get it to work (

For those of us who are not software engineers, how do you execute the script from the command line?
I tried from cmd prompt, that didn't work. Then I ran as administrator from the file directory where I saved the klepcbgen file but when I try to execute the command I get an error: No module named 'jinja2'

Findecanor

24 Apr 2020, 20:52

Ah. Is it for Python 2 or Python 3?

User avatar
ddrfraser1

24 Apr 2020, 22:38

Findecanor wrote:
24 Apr 2020, 20:52
Ah. Is it for Python 2 or Python 3?
Wasn't sure if you were replying to me. I tried it with python 3.8, did nothing. Error: invalid syntax

kelvinhall05

26 Apr 2020, 03:07

Very interesting, good work :D

jeroen94704

26 Apr 2020, 19:49

ddrfraser1 wrote:
24 Apr 2020, 22:38
Wasn't sure if you were replying to me. I tried it with python 3.8, did nothing. Error: invalid syntax
Oh, sorry about the incomplete info. I guess I should add a "prerequisites" section to the readme.

You need to install the jinja2 python module. This is most easily done using pip from the command-line:

Code: Select all

pip install jinja2
Hope this helps. If you need more info don't hesitate to ask.

Jeroen

pcaro

26 Apr 2020, 22:35

ddrfraser1 wrote:
24 Apr 2020, 22:38
Findecanor wrote:
24 Apr 2020, 20:52
Ah. Is it for Python 2 or Python 3?
Wasn't sure if you were replying to me. I tried it with python 3.8, did nothing. Error: invalid syntax
It is running with python3.

Just do:

Code: Select all


git clone https://github.com/jeroen94704/klepcbgen
cd klepcbgen/
python3 -m virtualenv venv
source venv/bin/activate
pip install jinja2
python klepcbgen.py example_layout.json mykeyboard
Great job @jeroen94704 !

jimbaker

27 Apr 2020, 12:25

Findecanor wrote:
23 Apr 2020, 11:16
Cool stuff. I'll definitely take a look here and steal your ideas. ;)
I've done something similar: creating KLE and DXF output from a Python program (computed layout).

BTW, You haven't posted a license/copyright information.
Yeah, I've noticed that too. I think you should add a license/copyright information here.
Last edited by jimbaker on 29 Apr 2020, 12:32, edited 1 time in total.

jeroen94704

28 Apr 2020, 12:17

jimbaker wrote:
27 Apr 2020, 12:25
Findecanor wrote:
23 Apr 2020, 11:16
Cool stuff. I'll definitely take a look and steal your ideas. ;)
I've done something similar: creating KLE and DXF output from a Python program (computed layout).

BTW, You haven't posted a license/copyright information.
Yeah, I've noticed that too. I think you should add a license/copyright information here.
There's a LICENSE file included in the repository

Post Reply

Return to “Gallery”