SVG to a custom penplotter, a complete walkthrough.

Hi, I am part of the Acrylicode Team and I want to show you my workflow for plotting any SVG file.
In order to follow you need a basic understanding of what a Terminal is and what bash scripts and command-line interfaces (CLI) are. This is going to work on Mac and Linux (it may work also on windows, but I haven’t tried it there).

I have custom Penplotter, made with an Arduino Uno and some Nema 17 motors. In this tutorial, I am not going to go deep in the Hardware construction but rather on the Firmware and Software part. If you would like a tutorial on the construction, let me know in one of my Youtube Videos or contact me via DM in Instagram.

The firmware running in my pen plotter is GRBL 1.1 , but it should also work with the GRBL Servo (0.9). GRBL is a firmware that can be installed on the Arduino and it accepts gcode and it can move motors according to the gcode. More info about GRBL here and about gcode here.

Now we know we need gcode in order to plot something (this works also for 2D and 2.5D CNC cutting as well as Laser cutting and engraving, it its the same software and firmware, just different hardware). So this tutorial is going to show you how to convert any SVG to optimized gcode for pen plotting. A brief overview to follow this tutorial:

Software requirements:

  • VPYPE
  • JUICY-GCODE
  • UNIVERSAL GCODE SENDER

VPYPE Installation

pip install vpype

Juicy-gcode installation (Check it here)

Universal gcode sender installation. (Check it here)

The following steps are matching with the diagram above.

Start

We need an svg file so we can start with. For simplicity, I am going to generate one with the free online tool provided in the previous tutorial. You can find the link of the tool here. I am going to call the file „shape.svg“.

Preprocessing

For this step we need to have vpype installed. So make sure you followed the installation steps. If your vpype installation was successful, you can type "vpype" on your terminal and some usage information should be displayed. You can check out the whole vpype CLI documentation here

Here is a very brief explanation how vpype commands work (taken from their github repo)

The command I use for most of my plots in A3 size :

vpype read shape.svg scaleto 19cm 27.7cm linemerge -t 1mm linesort write --page-size a3 --center output.svg

You can change the scaleto to the values you want and the page-size for a4 if thats more suitable for you. If you want to read more how those commands work : scaleto , linemerge , linesort , write . Just because I only use those commands, doesnt mean you cant use others, check out the documentation and use the commands that fit your needs.

After executing that command (in the same directory where the “shape.svg” is), we will see that the “output.svg” was created, this is an optimized svg in the size we want. Keep reading until the end, because I will show you in the bonus part how to automatize it.

Conversion

Now we have an optimized svg file called “output.svg” and we want to convert this file to a gcode file. First we need a configuration file for Juicy-gcode. It is a text file, (its called juicy-flavor) and in my case its called “juicy-flavor.txt” and it looks like this: (DO NOT COPY PASTE WITHOUT KNOWING, THIS DEPENDS ON YOUR MACHINE)

gcode
{
   begin = "G17\nG92 X0 Y0 Z0"
   end = "G0 Z0\nG0 X0 Y0"
   toolon =  "G0 Z-8"
   tooloff = "G0 Z0"
}

Well, this configuration is very important and for you it may be different, depending on the machine you have. How this works is that the “begin” is a command or series of gcode commands separated by a “\n” that are executed once in the very beginning of the plot. And the “end” commands are executed when the plot is finished. Note that in the “end” there is first a G0 Z0 command and then the G0 X0 Y0, the reason is that if you type G0 X0 Y0 Z0 all axis will move at the same time and its very possible that the pen draws undesirably on the finished plot on the way back.
And the “toolon” is the command for “pen up” and “tooloff” for “pen down”. My Z axis is backwards so thats why the G0 Z-8. If you have a Servo Motor on the Penholder, probably you should use commands like “M3 S90” and “M5” for Pen up and pen down respectively. If you built a custom pen plotter feel free to contact me for personalized advice on this. Here is the reference for the commands used: G17, G92 , G0 .

Now we have our “flavor.txt” and our “output.svg” in the same directory, we can use the juicy-gcode command to convert it. I use :

juicy-gcode output.svg -f flavor.txt -o output.gcode

This will create a “output.gcode” file from the “output.svg” based on the “flavor.txt”. For more information on that here.

Sending it

Now we have our gcode, we just need to plug the Arduino to the computer, plug the motors, connect the Arduino to our computer and send the gcode. Open the Universal Gcode sender and select the Arduino port. It should be cu.usbmodem in Mac, in linux it may vary. If you dont see it , make sure the Arduino is connected and click the refresh button next to the dropdown.

Once the port is selected, click on the “Connect” Icon.

Once successfully connected you should see something like this

On the right part, we see the GRBL settings. You can change them with a “$” then the number of the setting and then an “=” and the value you want to set. Example :

$110=1000

The settings are important for calibration, speed, acceleration and more things. More on that here.

Now click on the Folder Icon, select the gcode file we created and then hit the Play button. Your machine should be moving and plotting the gcode, congratulations ! .

Bonus: Automatization (MAC & Linux)

Well if you read the article until here, you deserve a juicy bonus. I am going to show you how to automatize a big part of the process.

First lets create a folder in the home directory, mine is called “globalData” . Here we will store some bash scripts for the automatization and also save the plotted svg, aswell as the plotted gcode. Put your “juicy-flavor.txt” on that folder (this is the configuration file for juicy-gcode). Inside this folder create also another 2 folders: “svgs” and “gcodes” . Now lets create a bash script that contains following code.

This is for a3 size , so I call it “a3.sh” :

vpype read $1 scaleto 19cm 27.7cm linemerge -t 1mm linesimplify linesort write --page-size a3 --center ~/globalData/svgs/$1 && juicy-gcode ~/globalData/svgs/$1 -f ~/globalData/juicy-flavor.txt -o ~/globalData/gcodes/$1.gcode

If you have been following the tutorial, this may seem familiar to you. First we execute vpype and we store the output in ~/globalData/svgs/ , then we execute juicy-gcode with the exact svg we just saved. (The && in bash allows us to chain commands). The $1 is the first argument of the bash command, that means we pass the script the svg we want to convert. Before an example we need to make this file an executable file we do it by :

chmod +x a3.sh

This now should be an executable that you can execute by:

./a3.sh someDrawing.svg

But this would only work if the terminal is open on the globalData directory, so we are missing the main secret.

And the main secret is here: we are going to add the globalData folder to the paths , so every time , wherever we open the terminal we can use our “a3.sh” script. So type this: (this may vary among linux distros, so just google add folder to path)

sudo nano /etc/paths

Then go to the end of the file with the arrows and add the absolute path from the “globalData” folder something like this: “/Users/yourusername/globalData” and type Ctr+O and then Ctr+X (Save and exit on the nano editor).

Now you will have all the scripts stored in the globalData folder, everywhere ! . This is amazing because you can have multiple scripts with different settings for your most common use cases, lets size a3 and a4 or some variations of the a3 with different scaleto parameters (vpype scaleto). Now if you for example download some svg from the internet and save it in the downloads folder, you can open the terminal, cd to the Downloads and then just type

a3.sh downloadedFromInternet.svg

And after executing this command you will have the gcode already on the ~/globalData/gcodes folder and the optimized svg on ~/globalData/svgs . This will save you a lot of time and give you amazing control over your plots.

I hope you enjoyed this tutorial. You can always contact us via DM Instagram (@acrylicode.berlin) , we appreciate any feedback, if it was too simple or too complex, or what would you like to see in a tutorial, we are open for suggestions.

Support us:

– subscribing to our Youtube channel https://www.youtube.com/channel/UC6kz8lb80gitsmjx0gnZC8Q

– sharing this content and following us in social media @acrylicode.berlin

-check out our shop https://www.acrylicode.com/shop/