Git Product home page Git Product logo

kicad-image-injector's Introduction

KiCad image/QR-Code injector

License: GPL-3.0-or-later REUSE status

In cooperation with FabCity Hamburg In cooperation with Open Source Ecology Germany

status: beta

What is this

A stand-alone (python) tool to replace rectangular template areas drawn onto a KiCad PCB with B&W images or QR-Codes.

This was written with the intention to include QR-Codes containing git-commit specific information onto a PCB and later the generated Gerber & Drill files in a CI job.

What it does

pseudo code (python):

pcb = parseKicadPcb("some_board.kicad_pcb")
placeholders = scanForPlaceholderRectangles(pcb)
replacements = cli_args.getAsList("replacements")
if len(placeholders) != len(replacements):
    print("Bad!")
    exit(1)
for i in range(0, len(placeholders)):
    p_holder = placeholders[i]
    repl = replacements[i]
    if isSkip(repl):
        continue
    elif isImage(repl):
       pixels = loadImagePixels(p_holder.imagePath)
    elif isQrData(repl):
       pixels = generateQrCode(p_holder.data)
    pcb.replace(p_holder, pixels)
pcb.writeKicadPcb("some_board-REPLACED.kicad_pcb")

Usage

  1. Design your PCB in KiCad and include rectangular polygons on any silk or copper layer. See below for more detailed instructions.

  2. Make sure the images you want to inject are available (e.g. generate them).

  3. Run this tool with the appropriate number of arguments (Identifiers can be (1) image paths, (2) qr-code data strings or (3) skip instructions).

    # simplest example
    python3 placeholder2image.py --input foo.kicad_pcb qr_to_inject.png
    
    # In the case of three placeholder rectangles in Kicad, use three identifier arguments:
    python3 placeholder2image.py --input ~/some/path/board.kicad_pcb qr.png skip 'qr:My Data'

    NOTE: Take care of using the correct order of the supplied replacements.

  4. Done! Do what you want with the generated PCB: ~/some/path/board-REPLACED.kicad_pcb

Run python3 placeholder2image.py --help for more info.

Placeholders

As the KiCad PCB file format does not allow for much meta-data to be added to elements, we treat all axis-aligned, rectangular polygons as viable placeholders. If you do not want to replace some of those, you have to explicitly tell this tool to skip them.

Creating Placeholders

  1. Open your PCB in KiCad (pcbnew),
  2. select the menu item Place -> Polygon,
  3. draw an axis-aligned rectangle (don't worry if it is not perfect, you can adjust it after creation),
  4. right-click on it,
  5. select Properties...,
  6. select the layer you want (any of: F.Cu, B.Cu, F.SilkS, B.SilkS).

NOTE
If a polygon does not have exactly 4 points, and is not perfectly axis aligned, it will not be recognized!

Take note of how many rectangles you created!

Order of Placeholders

The order of the repalcement pixels sources supplied on the command-line is important, and has to correspond exactly to the order of the placeholders in the PCB.

The order of the placeholders on the PCB is defined as follows (higher up in this list is more important):

  1. copper before silk
  2. front before back
  3. top-left corner up before down
  4. top-left corner left before right
  5. bottom-right corner up before down
  6. bottom-right corner left before right
  7. polygon before zone

Example Usage

input:

input QR-Code (generated with: qrencode -s 1 -m 1 -o qr.png "My Data")

input PCB

output:

output PCB

Misc

Please also see the KiCad text injector.

Funding

This project was funded by the European Regional Development Fund (ERDF) in the context of the INTERFACER Project, from July 2021 until March 2023.

Logo of the EU ERDF program

kicad-image-injector's People

Contributors

hoijui avatar jcmariscal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kicad-image-injector's Issues

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.