I’d like to include a QR code on a PCB. I have created one and it is about 1x1cm with fairly high resolution. Does anyone have experience with the result after PCB fab?
Should my code be normal or invert black<->white?
Thanks for any help.
Look to your board house for minimum line widths and see if they can even print the resolution you need. I’d look at the text requirements and see if that helps.
Best option is to clear with the manufacturer. They should be able to give you their thoughts based on the gerbers. It is hard to say from here without seeing the silkscreen pattern .
My rule of thumb for silkscreen is smallest feature of 1mm or so which eaves you a 10x10 qr code “pixel” grid which is not much.
However, typically, I have usually seen a sticker used for this instead. If you ask, the PCB often will be able to print and apply the sticker for you.
A few things to note that may make a sticker more appropriate
- The contrast between soldermask and silkscreen may not be sufficient for code reading, remember you can only apply single color printing (typically white) and the negative is whatever your soldermask color is.
- Even with good minimum width spec, the resolution may not be perfect for a larger pattern
- Silkscreen will be interrupted by vias and skewed by any copper planes.
- The QC on silkscreen is a secondary consideration, so you may not have a perfect image every time.
Ah, the good old days, when parts were scattered wide enough to include QR codes. The code below is ~4.5x4.5mm and reads just fine with ‘barcode scanner’ for Android. PCB by OSH Park (in case the purple/gold didn’t give it away).
I don’t remember the exact details of the PCB (it was made about 5 years ago), but out of the three I have here two look like this one, one is unreadable. I’m guessing this was very much on the limit of what OSH Park could do back then.
Thanks for all the comments.
Stefan - yes that is what I want to do. I see your QR was in Cu, not silkscreen.
Things I’ve learned.
-
JLCPCB via email support says the smallest feature size on silkscreen is 0.15mm. If I chose 0.25mm as my minimum and the QR is about 30 “elements” per X,Y then the QR will be 7.5 x 7.5mm. Further increasing the size to 10x10mm, the element would be 0.33mm which is 2x larger than the mfgr minimum.
-
Have to avoid vias and other potentially visually confusing features.
-
I’ve considered stickers but don’t want to use paper, so I’d have to buy lots of little printed dots to get vinyl and decent glue. Uncharted waters.
-
There is something going on in the KiCad CONVERT tool which results in much loss of resolution. I need to play with that more.
The QR Code footprint generator included with Kicad seems to produce a fairly reliable QR code both on silk screen and on copper using a number of cheap Chinese fabs. The default size It is a 33 x 33 matrix of 0.5mm blocks however - so it is quite a lot larger at 16.5mm square than you are proposing; the minimum pitch supported seems to be 0.4mm (13.2mm overall). I am not sure if this size is based on any actual real-world test. The 0.5mm pitch version seems to scan easily enough on a phone based scanner - presumably might be rather better with a proper scanner.
The 33x33 matrix supports up to 90 characters at the preset medium error correction level. If you only need a serial number/revision you could get away with a much smaller sized code - 21 x 21 for instance which still gives you 20 characters to play with but you would have to generate this outside of Kicad (or hack the python code for the QR generator).
Learned a bit more.
The process is:
-
Create a QR code. This web site worked best: https://www.qr-code-generator.com/ More on that in a bit. Save the original file, don’t edit it with photoshop or anything. PNG worked for me.
-
Open the KiCad convert tool and load the QR PNG file.
Adjust the DPI to generate a file with the desired outside dimensions. Export the file. I wanted about 10x10mm
IMPORTANT!!!
The referenced website created a file with better initial resolution that other free sites I tried. This was NOT obvious, but after conversion (using 750 DPI for 10x10mm), the sharpness was still good. Using other sites QR image files showed signs of loss due to compression or poor sampling or ?
I’ve no affiliation to the web site, it just worked better for me. I did NOT register although having an SVG file would likely have been better.
I would also like to try the KiCad QR code but haven’t located it. Possibly it’s a plugin?
The QR code generator is a plug-in but I think it comes as part of the standard Kicad install along with the barcode generator and a variety of other scripted footprints. As it is a python script you presumably need a Kicad version with scripting enabled.
In the footprint editor chose new footprint from wizard, refresh the list and hopefully this should show up (I am away from my computer at the moment so can’t check the exact wording).
It is written in python - it looked fairly ameanable to a bit of editing to alter the code size.
John - the Python QR code is extremely sharp. Substantially better than the either of the other images using the Converter. The smallest I was able to go was 0.4 which results in a image about 13x13mm
With a minor edit to the python, I reduced the min size to 0.3 and the resulting code is about 10x10mm.
Thanks for the tip as I was completely unaware of this plugin! and thanks to all who commented.
i did not try to get a qr on a pcb yet - will have to try the build in generator…
Just some remarks that came through my mind and i thought i share theme…
- web qr-code generator that does not communicate with a server (your data stays in your browser - its written in js)
- web qr-code generator from the zxing project - has all the options available in the GUI…
- inkscape (the open source vector-graphic program) has a extension to generate QR-Codes as SVG / Vector files - it also can also export as dxf.
You find the plugin inExtension
→Render
→Barcode
→QR Code
in the manual it is not mentioned yet - (as it is new as of 0.92)
- there is a alternative plugin for inkscape i found (did not try) -
it uses segno (Python QR Code and Micro QR Code encoder)
eventually this brings more options?
the current script uses kazuhikoarase/qrcode-generator - from this it seems if you change (Line56ff)
# Build Qrcode
self.qr = qrcode.QRCode()
self.qr.setTypeNumber(4)
# ErrorCorrectLevel: L = 7%, M = 15% Q = 25% H = 30%
self.qr.setErrorCorrectLevel(qrcode.ErrorCorrectLevel.M)
self.qr.addData(str(self.Barcode))
self.qr.make()
to
# Build Qrcode
# ErrorCorrectLevel: L = 7%, M = 15% Q = 25% H = 30%
self.qr = qrcode.QRCode.getMinimumQRCode(
str(self.Barcode),
qrcode.ErrorCorrectLevel.L)
it creates the minimal size. (i also changed error correction level to the minimum)
i have attached the modified script file.
qrcode_footprint_wizard_mod.py (6.7 KB)
on ubuntu i placed it at /home/stefan/.config/kicadnightly/scripting/plugins/
(make sure there is a empty __init__.py
file in this directory - otherwise it will be ignored)
i also tried and made a variant with the segno library -
install library with $ pip3 install segno
then add this extended script to your user script collection:
qrcode_footprint_wizard_segno.py (8.2 KB)
micro QR
normal QR
have fun
sunny greetings
stefan
I wonder if you would get better contrast in the QR code if you allowed solder mask everywhere there isn’t copper. Granted, this entirely depends on the color of solder mask used. White wouldn’t give much contrast, but many colors are dark enough.
Your next trick will be to design a QR code that is also a functional circuit. Then the code can be as large as your PCB.
This is not a direct answer to your question, but a bit of related information. I’ve recently been working a lot with QR codes, optimizing their generation for future PartsBox.io features. It seems few people know that there are many ways to encode a string into a QR code.
You can get a significantly shorter code if you use an encoder that optimizes the segments, and an even shorter one if you are willing to make some compromises on the content. As an example, if you can put parts of your content in upper case, that will result in a shorter code.
In general, you want your code as short as possible, so that you can use the lowest possible QR “version” (size). The fewer pixels your QR code has, the smaller you can make it on your PCB, and the more readable it will be.
For optimizing QR codes, I highly recommend Nayuki’s https://www.nayuki.io/page/optimal-text-segmentation-for-qr-codes page — it lets you play around with settings and content and see the results immediately. I found her QR generators to be excellent, too.
I’m very satisfied with the QR wizard in KiCad. It results in a much sharper image than using photoshop to manipulate pixels. I just wanted to encode the URL of my web page so I don’t have a lot of part numbers or data to encode.
On PCB I get from JLCPCB, on the feed rails, there is a VERY small laser etched QR that is 4x4mm. Pretty amazing that it is low contrast and small. The surface texture is either hard shiny or rough green and it can be read by my phone. With a fixed camera on a production line, it would be easily read. So I wouldn’t worry about too much about getting higher contrast than white/green.
Just for fun I had a bit of a play with the QR generator and have added in a DataMatrix library from https://github.com/hudora/huBarcode. I think DataMatrix might be considered more robust but it has a smaller data capacity - probably not an issue if you just want a serial number. I think they will be OK smaller than QR codes but I would like to try some real examples.
I have managed to produce some smaller Data Matrix footprints. These are about 6mm square (0.3mm feature size).
I have not tried these out yet but I will pop some of different sizes on my next board to see how they look. I have put the code on Github if anyone is interested. https://github.com/Gasman2014/kicad-DataMatrix
I created a QR that is 10x10mm using the KiCad tool. The minimum feature size of 0.5mm was too large so I set it to 0.3mm to get a total size of 10x10. The boards just came back from JLCPCB and my Android phone reads them just fine.
Thanks John Pateman and all the others who provided advice.
I have an interesting problem that the QR doesn’t appear when I do a Print preview. Looking at the feature in the footprint editor now to see what might be wrong.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.