Create a loop antenna pattern in Python in KiCad

1.First of all

It became necessary to create a spiral coiled conductor pattern on a printed circuit board. The printed circuit board CAD KiCad [^ 1] does not have such a function. It's a lot of work to create by hand, and it's difficult to create regular patterns. It is realized as a footprint using an independent tool. test3.png

2. Find software tools

Find the published tool. A web search will give you those images and hints. Spiki [^ 3] was introduced on the page [^ 2] that introduces the plugin, but I gave up because it required Python2 and PyQt4 and it was difficult to maintain the operating environment. I searched GitHub and was able to use the latest kicad-coil-generator [^ 4].

3. Install Python

Download the installation program [^ 5] and run it. The default seems to be the 32-bit version. This time I chose the 64-bit version. Enable the PATH addition option during installation and also perform the process of removing the character limit of PATH. I also created a virtual environment with venv.

C:\Users\user_name>python -m venv venv_kicad
C:\Users\user_name>call venv_kicad/scripts/activate.bat
(venv_kicad) C:\Users\user_name>

Being addicted

--Confused venv (standard with Python3) and virtualenv (provided by a third party). --Line 1: Running the "python3" command at the Windows 10 command prompt does not run python and does not cause an error. The venv folder is also not created. I found that losing the command parameters led to a Python installation in the Windows Store.

4. Kicad-coil-generator preferences

Clone kicad-coil-generator from github and install the Python library according to the README.md. I was angry that I didn't have a wheel, but KiCadModTree was installed.

(venv_kicad) C:\Users\user_name\kicad_coil_generator>pip install wheel
(venv_kicad) C:\Users\user_name\kicad_coil_generator>pip install -r requirements.txt
(venv_kicad) C:\Users\user_name\kicad_coil_generator>

5. Confirmation of operation of kicad-coil-generator

Display help.

(venv_kicad) C:\Users\user_name\kicad_coil_generator>python coil_generator.py --help
usage: coil_generator.py [-h](-r R_INNER | -d D_INNER) (-R R_OUTER | -D D_OUTER) -n N_TURNS -w LINE_WIDTH [--direction {counter_clockwise,clockwise}]
                         [-p {SMT,THT,CONNECT}] [-x DRILL_RATIO] [-a RING_WIDTH] [--points_per_turn POINTS_PER_TURN]
                         file_name {spiral,square}

Generates KiCad footprints of spiral/square coils.

positional arguments:
  file_name             path to the file in which to save the footprint; will overwrite previous file (this program cannot addmultiple footprints to the same file, so
                        files have to be concatenated manually)
  {spiral,square}       type of the coil created

optional arguments:
  -h, --help            show this help message and exit
  -r R_INNER, --r_inner R_INNER
                        inner radius of the coil [mm]
  -d D_INNER, --d_inner D_INNER
                        inner diameter of the coil [mm]
  -R R_OUTER, --r_outer R_OUTER
                        outer radius of the coil [mm]
  -D D_OUTER, --d_outer D_OUTER
                        outer diameter of the coil [mm]
  -n N_TURNS, --n_turns N_TURNS
                        number of turns of the coil
  -w LINE_WIDTH, --line_width LINE_WIDTH
                        width of the copper path used [mm]
  --direction {counter_clockwise,clockwise}, --dir {counter_clockwise,clockwise}
                        direction in which the coil turns (starting from outer part)
  -p {SMT,THT,CONNECT}, --pad_type {SMT,THT,CONNECT}
                        type of the pads drawn at the ends of coil's path
  -x DRILL_RATIO, --drill_ratio DRILL_RATIO
                        ratio of the drill in pad to line width (only for SMT/THT pads)
  -a RING_WIDTH, --ring_width RING_WIDTH
                        Width of the ring around the drill
  --points_per_turn POINTS_PER_TURN
                        (spiral only) number of arcs used for each full turn of the coil

(venv_kicad) C:\Users\user_name\kicad_coil_generator>

Being addicted

It cannot be executed by using py instead of the python command.

(venv_kicad) C:\Users\user_name\kicad_coil_generator>py coil_generator.py --help
Traceback (most recent call last):
  File "coil_generator.py", line 12, in <module>
    import KicadModTree as kmt
ModuleNotFoundError: No module named 'KicadModTree'

6. Pattern creation with kicad-coil-generator

I created two types, spiral) and square, with an inner radius of 35 mm, an outer radius of 45 mm, 20 turns, and a pattern width of 0.25 mm. Kicad footprint format files "test1.kicad_mod" and "test2.kicad_mod" have been generated.

(venv_kicad) C:\Users\user_name\kicad_coil_generator>python coil_generator.py test1 spiral -r 35 -R 45 -n 20 -w 0.25
Line spacing = 0.250 mm

(venv_kicad) C:\Users\user_name\kicad_coil_generator>python coil_generator.py test2 square -r 35 -R 45 -n 20 -w 0.25
Line spacing = 0.276 mm

(venv_kicad) C:\Users\user_name\kicad_coil_generator>dir
There is no volume label for drive C.
Volume serial number is 6A6D-1120

 C:\Users\user_name\kicad_coil_generator directory

2020/07/18  13:55    <DIR>          .
2020/07/18  13:55    <DIR>          ..
2020/07/18  12:59             6,999 coil_generator.py
2020/07/18  12:59               808 README.md
2020/07/18  12:59                58 requirements.txt
2020/07/18  12:59    <DIR>          screens
2020/07/18  12:59             4,978 spiral.py
2020/07/18  12:59             2,086 square.py
2020/07/18  13:54             8,128 test1.kicad_mod
2020/07/18  13:54             7,743 test2.kicad_mod
2020/07/18  13:23    <DIR>          __pycache__
7 files 30,800 bytes
4 directories 194,298,355,712 bytes of free space

(venv_kicad) C:\Users\user_name\kicad_coil_generator>

Import the generated footprint file into KiCad's footprint editor for viewing. "test1.kicad_mod" test1.png "test2.kicad_mod" test2.png I feel it is a beautiful pattern.

7. Creating a footprint

Based on the generated pattern, I created a footprint with swirls placed on both sides and a via connection in the center. test4.png

Being addicted

The tip of the coil is a "connector", but if it is left as it is, it will not be possible to connect the wiring after placing it in the printed circuit board editor. I think this is because there is a prohibited area around the coil pattern. The shape of the connectors on both ends has been changed to a "custom shape (circular anchor)" and modified to draw out from the coil pattern.

8. Conclusion

KiCad has the feature that the data is in text format and can be modified or completed by an external program. Many people create and publish useful external programs. I would like to thank these people and make effective use of their assets. I hope I can provide some useful tools in the future.

Recommended Posts

Create a loop antenna pattern in Python in KiCad
Create a function in Python
Create a dictionary in Python
Create a DI Container in Python
Create a binary file in Python
Create a Kubernetes Operator in Python
Create a random string in Python
Create a simple GUI app in Python
Create a JSON object mapper in Python
[GPS] Create a kml file in Python
Create a Python module
Visitor pattern in Python
I want to create a window in Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Rewriting elements in a loop of lists (Python)
Create a simple momentum investment model in Python
Create a new page in confluence with Python
Create a datetime object from a string in Python (Python 3.3)
Create a package containing global commands in Python
Create a Python environment
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a data collection bot in Python using Selenium
[LINE Messaging API] Create a rich menu in Python
Create a plugin to run Python Doctest in Vim (1)
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create a fake Minecraft server in Python with Quarry
Take a screenshot in Python
Create a Wox plugin (Python)
Create gif video in Python
Make a bookmarklet in Python
Create a python numpy array
Draw a heart in Python
Create a directory with python
Create a local scope in Python without polluting the namespace
Create a list in Python with all followers on twitter
Loop through a generator that returns a date iterator in Python
Create a child account for connect with Stripe in Python
Let's create a script that registers with Ideone.com in Python.
Create code that outputs "A and pretending B" in python
Create a tool to check scraping rules (robots.txt) in Python
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
[python] Manage functions in a list
Hit a command in Python (Windows)
Create a CSV reader in Flask
Create a python GUI using tkinter
Create a Python environment on Mac (2017/4)
Draw a scatterplot matrix in python
ABC166 in Python A ~ C problem
Create a virtual environment with Python!
Write A * (A-star) algorithm in Python
Implement the Singleton pattern in Python
Create Gmail in Python without API
Write a pie chart in Python
Create Python project documentation in Sphinx
Create a Python general-purpose decorator framework
5 Ways to Create a Python Chatbot
Solve ABC037 A ~ C in Python
Run a simple algorithm in Python
Draw a CNN diagram in Python