Adding a QR-Code (or alernatively an image) to a PCB, fully scripted/headless

The goal is, to encode some project specific information (like git commit and github URL) into a QR-Code, and put that code onto the board, as silk or copper. All of this should happen automatically on the build-bot (for example with GitHub actions), for every commit (just before generating the gerber files and 3D and 3D renders and so on, which I already have working).

I imagine this could happen either by:

  • using the QR-Plugin for KiCad
  • generating a PNG or SVG with the QR-Code externally (e.g. with qrencode), and then importing the image into the PCB.

The later would have the benefit of being able to auto-import arbitrary images.

… any hints on this one?

???
So, do you want the image on the PCB, or in the schematics?

But overall, it’s bad timing for a feature like this.
There is currently a lot of work being done in getting KiCad V6 ready (Now: nightly V5.99). The next KiCad version has a completely different file format for Eeschema. There also are some changes in the file format for PCB’s, but those are much smaller.

So you’ve already found the QR code wizard.
It seems logical to re-use that code if it fits your purpose, but it is designed to interact directly with the entry boxes in the footprint editor.

A bitmap format such as .PNG fits quite well with a QR code, but not with KiCad. In the KiCad Project Manager there is a program icon for converting bitmaps into symbols that can be used in KiCad (apparently both Eeschema and Pcbnew) It’s probably a good idea to have a look at that.

Description of the (old) file formats may also be useful:
https://kicad.org/help/file-formats/

After you Export from the BMP tool, using any Text editor, you can open the .mod file it created and change the Layer as desired (can do a Replace All…). Probably shouldn’t change layers for the Ref/label).

Image below shows example with Change to Back Copper Layer…

Remember that the git hash will not be known until the board is committed so the QRCode you subsequently produce will refer to the previous commit.

Oops, I missed that.
I have defaulted to simple date strings in ISO_8601 format.

Because:

  • Human readable, don’t need no tools to decipher them.
  • Inherent logical order when sorting.
  • Can be used as filenames for backups.
  • Gives instant feedback to how old a version (approximately) is.
  • Text strings can be used anywhere in documentation, on a PCB, Schematic, etc.
  • Don’t need conversion programs to even put the thing on a PCB.
  • You can simply copy and paste them almost anywhere (within limits of a PC).

And, oh, if it’s useful, you can also make a QR code out of it and stick it on a box or something.

my idea is, to have only a placeholder image in the PCB file that is checked into git. the actual qr-code will be generated on the build bot, when building the commit, and then we get a PCB with the actual qr-code.
meaning, the qr-code will never be check into the repo. I already do this with plain-text meta-data that I put onto the silk-screen with a simple script (using “${REVISION}” style placeholders).

That sounds like a good Idea.
The data in the QR code could be a data string such as I mentioned earlier.
(Or something else)

How do you make the link between the placeholder on the PCB and the actual QR code? You could put a script in your build system that makes a footprint with a QR code, but Pcbnew has copies of all footprints in it’s own file.

I also do not see git hashtags as a good identification mark. They are much too volatile. Generating a single UUID for a project is probably a better choice.
Or just an URL to your (publicly accessible?) git repository. Or a fancy project name for that matter, Just look at “ananasstepper” as an example. (Easy to remember too.

I use version control hashes as identifiers on boards - if you are using a version control system it is very easy to find a place in the history and restore to that point. The advantage that I see is that the commit messages give you information about the state of the board/schematic that a datestamp alone doesn’t provide.
I guess that @hoijui is tracking the commit reference and footprint in a programmatically generated unversioned file.

FYI… I did two things:

  1. Video 1
    • Used customized HTML BOM plugin to get data for QRcode
    • Made a QRcode PNG using a FireFox QRcode plugin

  2. Video 2
    • Used customized HTML BOM plugin to get data for QRcode (same data as above)
    • Made a QRcode PNG using custom plugin to run external QRcode App from PCBnew

• Used the PNG in Schematic
• Used the Footprint in PCB

• Quick and Simple - No problems (except the Mouse had too much BlackCoffee and got the Jitters :laughing: )
• Can use URL’s Text, etc… in the QRcodes thus, can have desired GIT info, Date/Time…etc

Lot’s of data (first image) ‘may’ make it difficult to produce good quality on Copper layer for CNC machining but, less data (last image) was ok and I was able to Read/Scan it

qrOut2.mov

qrOut3.mov

thanks a lot, that is great info! :slight_smile:
I’ll see if I get to hack on this some day.

So… if I use the QR-Code wizard (as a base) - assuming it will be ported to KiCad 6 - then I should have little problem with porting this tool as well.
…and yes, I meant the PCB of course, not the schematics (I am not an electronics person, but a software dev).
to me, the actual data in the QR-Code is very easy to change, and as said, I already have a script that runs on the build-bot (GitHub/GitLab CI system) whenever a commit is made, and inserts text into the ${VAR} style placeholders in the text parts of a *.kicad_pcb file, and then generates Gerber files and renders and such.
Really the only part missing for this, is the automatically insert a QR-Code (or generally an image) into a *.kicad_pcb file, replacing a placeholder of some kind.

I am also not sure what info would fit best on there, how much of it, and so on, but that is very easy to change and experiment with.
… come to think of it, should be tested also on real boards in the end. would make a great blog post.
maybe we will end up seeing art projects, where they try to make usable circuits out of a QR-Code describing the (meta-data of) the board its self. :wink:

had a look at the code in these two locations:

basically, it consists of two files:

  • qrcode.py - A python script that creates an in-memory QR-code (basically a 2D array of bool values), independent of KiCad (in fact, it uses no module at all)
  • qrcode_footprint_wizard.py - creates a QR-Code with the above script, and then draws it on the PCB, basically drawing one square polygon per pixel. IT also does the KiCad GUI plugin stuff.

I guess, it should be possible to change the GUI stuff and use a command-line interface instead.
As all the KiCad specific code treats the QR-code just like a black&white 2D pixel array, it should be easy to extend this to work with any black&white pixel-based image.

Main areas of work would be:

  • replace the KiCad-GUI-Plugin interface with a command-line based one
  • think of how to design the placeholder
  • how to replace it: optimally through the pcbnew API

As for the template (the thing to mark the position and size of the final QR-Code in the PCB):

From my perspective (having almost no clue of how stuff works in KiCads format), It would optimally be one rectangular/square polygon, with some special … name//field, that marks it as a (QR-Code) template, and with the data to encode as string in an other field (something like description, or can we use arbitrary fields?) of the polygon. optionally it could be the path to a file that would contain that info.

On the build-bot, we would then first replace the meta-data variables with the script I already have, in the *.kicad_pcb, so for example “rev: ${GIT_COMMIT_SHA}” gets replaced with “rev: af4e253” in the QR-Code data string.
Then our script would go through the list of all the polygons in the PCB, and check if they have the right “tag”, or their name corresponds to some pattern or something.
For each such polygon found, it takes the data from the QR-Code data string, and replaces the polygon with a lot of small polygons, making up the QR-Code.

Any suggestions/ideas if this makes sense, if it is possible, and if there are better ideas for the template?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.