CNC Machining QR Codes for Stencils

Needed to stencil some QR codes to do a street art project. Found it was really difficult to get QR codes in vector format to create a machinable design so I wrote a breif octave script to do it for me.

The script takes a target URL or payload and uses a free API to return a QR bitmap.

Using the site: http://goqr.me/api/ and making a call to the API will return a QR code. EG:

https://api.qrserver.com/v1/create-qr-code/?size=27×27&data=https://bit.ly/2NDh5Sn returns:

download (4).png

Octave reads in the script and gives a preview of the API to make sure the QR code has rendered properly. Typically I was setting the resolution to the minimum ie 27×27 to keep the machining complexity as low as possible but also make the pixels as large as possible for spraypainting.

Our installation was to be a dance tutorial. The user is invited to open the link in the QR code which plays a music track. The rest of the installation is a series of dance steps that the user is invited to dance to.

The input QR looks something like this. But we want the squares to be inscribed circles so that the hole think can remain together after being machined.

frame.png

The script loops through each of the pixels and creates a script file that can be opened in AutoCAD to create a DXF of the QR code.

QR cad.PNG

The code can then be machined.

IMG_1541.jpg

And installed.

IMG_1552.jpg

the script can be found at: https://github.com/cstewart000/HME_Mach3/blob/master/QRCodeToSCR.m

#{
QRCordeToSCR.m

Authour: cstewart000@gmail.com
14/07/2019

Script to take a URL and convert to a AutoCAD interpretable script for creating
QR codes. Script runs a few dialog prompts for inputs and creats a ".scr" file
which can be run in AutoCAD to create a .dxf for CNC machining.

http://goqr.me/
#}

#Packages
pkg load image;

# Prompted variables
file_out_name = inputdlg ("output name for AutoCAD script"){1}
qr_size = inputdlg ("Size (in minimum pixels) of QR code - may need to run a couple of times to confirm QR is well formed"){1}
rad_drill = inputdlg ("Enter a value for the radius of the pixel ~0.5"){1}
target_url = inputdlg ("Target URL of the QR code"){1}

#Fixed/global variables
api_url = "https://api.qrserver.com/v1/create-qr-code/?"
complete_url ="";
fileOut = "";

# build the URL
complete_url = strcat(api_url, "size=", qr_size, "x", qr_size, "&data=", target_url)

#Get QR code online
onlineImg = imread (complete_url);
figure();
imshow(onlineImg);

btn = questdlg ("Is the QR code well formed", "QR Code formed", "Yes", "No", "No");
if (strcmp (btn, "Yes"))
#TODO re-run size prompt url build and request
endif

onlineImg = imcomplement(onlineImg);
onlineImg = im2bw(onlineImg);

#Nested loop through each of the pixels
for i = 1:SIZE
for j = 1:SIZE

#If the pixel is false (ie black) add a circle at that point
if (!onlineImg(i,j))

#add the circle command at the coordinate
fileOut = strcat(fileOut, "Circle ", "\r\n", num2str(i),",",num2str(j)," ",num2str(rad_drill), "\r\n");
endif

endfor
endfor

#Write the output to file
fid = fopen (fileOutName, "w");
fdisp(fid,fileOut);
fclose(fid);
clear('fileOut');

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s