Tag Archives: g-code

ShapeOko 2 tutorial – Dominion turntable – part 8

If you missed part 7, please find it here.

Milling the cutout of the quarter circle

At this point we’ve finished milling the surface of this quarter of our Dominion turntable and there are two things left to do, before we can continue working on the next quarter of the Dominion turntable:

  1. We need to mill the outline of this quarter – but just the curved part and the straight part along the y-axis. The straight line along the x-axis is not milled.
  2. We need to prepare and move the lumber to a position where the next quarter of the Dominion turntable is going to be milled.

This way we can mill half the turntable without having to glue two parts together.


We need to make a svg-file with the path for the cutout. For that purpose I use InkScape. If you’re not familiar with InkScape you’ll find several tutorials here. We need to draw an intersection of two quarter circles with the smallest having the same radius as our Dominion turntable, i.e. 274 mm. The larger circle has a radius of 279 mm leaving us with a 5 mm gap between them. Furthermore, we need a rectangle with dimensions 5×279 mm. Putting it all together in a combined path it looks like in the photo.

Cutout path made in InkScape

Cutout path made in InkScape

Last but not least we need to place the figure in the right position. That is: we need to place it so that the upper inner corner of the rectangle is placed at (0,0). Then save the figure as a svg-file.


I use MakerCam to create the g-code. Go to http://www.makercam.com to start MakerCam (there is a beginners tutorial here).

First we need to setup MakerCam so it fits the svg-file created by Inscape. In the upper right corner I select cm instead of inch. Then select Edit -> Edit preferences to open the preferences dialog shown in the photo.

MakerCam setup

MakerCam setup

Set the value of SVG Import Default Resolution (px/inch) to the value 90 and Machine Tolerance (in) to the value 0.001 and press Ok. Then select File -> Open SVG File, select your file and press Open.

Select the path (it will turn orange) and select CAM -> Pocket Operation and MakerCam will show the dialog below.

MakerCam - Pocket operation

MakerCam – Pocket operation dialog

Set the following values:

  • Name = pocket 1 (default value)
  • Tool diameter (mm) = 3.2 (in my case I use a 3,2 mm flat cutter)
  • Target depth = -26 (in my case the timber is 26 mm thick)
  • Safety height = 5 (default is 15 mm but I see no reason to have that much)
  • Stock surface = 0 (default value)
  • Step over (%) = 40 (default value)
  • Step down (mm) = 1 (default is 1,5 mm but I prefer to go a little less)
  • Roughing clearance (mm) = 0 (default value)
  • Feed rate (mm/minute) = 1000 (this value is depending on your CNC machine)
  • Plunge rate (mm/minute) = 500 (this value is depending on your CNC machine)
  • Direction = counter clockwise (default value)

Press Ok to close the dialog. Then select CAM -> Calculate all to get MakerCam to calculate the g-code for the pocket operation. When the calculation is done, select CAM – Export g-code to get the dialog shown here.

MakerCam - save g-code dialog

MakerCam – save g-code dialog

Press Export Selected Toolpaths and save the g-code in a file with the extension .nc

Again, I view my g-code in a g-code viewer just to check that the code looks fine.

GCodeViewer showing the generated cutout g-code

GCodeViewer showing the generated cutout g-code

Β Cutout

After a test run of the g-code, we’re ready to make some noise. πŸ™‚

Part 9.

ShapeOko 2 tutorial – Dominion turntable – part 7

If you missed part 6, please find it here.

The final cut

After working our way down into the material it’s time to do the two final runs: one in the x-direction and one in the y-direction. Running one file takes well over three hours! I made a small video of the process:

After the final cut in the x-direction there are still some jagged edges as seen in the photo below.

After the final cut in the x-direction

After the final cut in the x-direction

To get rid of these rough edges I finally run the original file in the y-direction to get the surface as smooth as possible (I hope you can see the difference in the photos).

After the final cut in the y-direction

After the final cut in the y-direction

Of course I can’t make all these cuts in one day so I have do it over several days. The trick is to avoid changing the zero position so you can continue the next day without resetting the zero. When I decide to stop working, I do the following:

  • Stop the spindle and the vacuum cleaner
  • Shut down Grbl Controller
  • Shut down the computer
  • Finally, cut the power to the g-shield and the stepper motors

This way the stepper motors will hold the position until the last minute. Then the only problem is to avoid touching the machine until the next time. When I want to continue it’s only a matter of the reverse procedure:

  • Power up the g-shield and the stepper motors
  • Turn on the computer
  • Start Grbl Controller
  • Connect to the g-shield in Grbl Controller

When power is turned on and everything is running, the Grbl Controller will set the current position as the zero position and all I have to do is to adjust the z-axis and continue. πŸ™‚

Part 8.

ShapeOko 2 tutorial – Dominion turntable – part 5

If you missed part 4, please find it here.

Getting ready to start milling

Now we’re ready to start milling! We’ve generated the g-code we need for the Dominion turntable but before we start milling I’ll write a little about my setup and show you the process I use to get ready.

My setup

I’m using an old computer running Windows XP and Grbl Controller to control the machine and to send the g-code to the Arduino and the g-shield. Here are some advise I learned the hard way:

1) It’s important that the power management for the USB ports is turned of in Windows. Otherwise, the operating system might loose communication with the Arduino.

2) Run the spindle and the vacuum cleaner from one power outlet and the computer and the stepper motors from another outlet. Having everything running from the same power outlet seems to disturb the Arduino and/or the g-shield.

3) Put a ferrite ring on the USB cable to stabilize the signal between the computer and the Arduino. This seems to help preventing the stepper motors from skipping steps when milling.

Ferrite ring on the USB cable

Ferrite ring on the USB cable

Starting position

In this case we’re going to use almost the full movement of the ShapeOko 2, so it’s important that we find the right starting position that allows us to mill the Dominion turntable without hitting the out most positions of the ShapeOko 2.

Here we need 274×274 mm plus 10 mm in each direction for the final cutout, so all together we need about 284×284 mm of workspace. The ShapeOko 2 has just short of 300×300 mm of usable workspace so we need to set the starting position very close to the out most positions.

Without power on the Arduino and the g-shield I move the spindle to about 10 mm from the out most positions in both the x- and the y-direction (I don’t care about the z-position just yet). Then power up everything so the stepper motors will hold that position.

Starting point on the x-axis

Starting position on the x-axis

Starting position in the y-direction

Starting position on the y-axis


Β Sanity check

With the starting point set I do a sanity check with some g-code that defines the maximum movement that the CNC machine is going to do in order to get the job done. In this case I use the following g-code:

(Generated by PartKam Version 0.05)

G21 G90 G40

(profile 1)
G0 Z15
T0 M6
G0 X-277.4 Y-277.4
G1 Z15 F1000
G1 X3.401015228426396 Y-277.4010152284264 F1000
G1 X3.401015228426396 Y3.401015228426396
G1 X-277.4010152284264 Y3.401015228426396
G1 X-277.4010152284264 Y-277.4010152284264
G0 Z15

This g-code will move the spindle to the corner furthest away from the starting point and then do a full square of the working area we’re going to use. It looks like this:

With the sanity check done I move the spindle back to the starting point by pressing the “Go home” button i Grbl Controller.

Test run

With the sanity check done I usually do a test run with one of the files that we are going to use when milling the Dominion turntable for real. I the case below I used the Limit=-17.00 file in the x-direction. If I made a mistake when generating the g-code it will reveal itself here by trying to move the spindle out of bounds (or do something weird). Be sure to have enough free space beneath the cutter to make the test run without actually ever touching the surface. Here is my test run:

With the test run done I again move the spindle back to the starting point by pressing the “Go home” button i Grbl Controller.

Setting zero on the z-axis

With the sanity check and the test run done we’re ready to set the zero on the z-axis. I use a piece of paper to do this. I put it underneath the cutter and then move the spindle down one millimeter at the time until I get close to the surface – then move on downwards 0,1 mm at the time until I can no longer move the paper. I then move the spindle upwards 0,1 mm and press the “Zero position” button in Grbl Controller. The process looks like this:

We’re now ready to start making some noise… πŸ™‚

Part 6.

ShapeOko 2 tutorial – Dominion turntable – part 4

If you missed part 3, please find it here.

Splitting g-code

So far we have created a drawing in OpenSCAD and generated 4 g-code files in FreeMILL: two files with a flat tool and a step distance of 2,8 mm (one in each direction) and two files with a ball nose tool and a step distance of 0,4 mm (one in each direction).

The two files created for at ball nose tool and a step distance of 0,4 mm are going to be used for the last two runs to finish the surface and to make it nice and smooth. The other two files are going to the split into several smaller files that will allow the CNC machine to work its way down into the material one millimeter at a time.

For that purpose I created a small program (with some valuable input from my friend Mads) which will do just that. It’s called G-Code Utility and can be downloaded here. Use it at your own risk! It comes with no warranty so please test the generated g-code before using it – for your own safety! G-Code Utility is built for this purpose only: Splitting g-code generated in FreeMILL as described in my earlier post! Remember: Carefulness is essential when working with high powered, fast spinning sharp tools like a CNC machine. I cannot stress that enough…

G-Code Utility

Since the g-code generated by FreeMILL describes the surface of our Dominion turntable and the ShapeOko 2 isn’t capable of milling the deepest holes (the deepest hole is 18 mm deep compared to the surface of the stock) in one run, we have to do something.

What G-Code Utility does is this: Finds the deepest place on the surface (here it is -18 mm), adds one millimeter (can be changed) and generates a file with the g-code that will cut anything below that limit (in this case -17 mm). Adds another millimeter to the limit and generates a new file with the g-code that will cut anything below this new limit (in this case -16mm) and so on.

Furthermore, it adds the current limit to the z-values in the file so we can run all of them from the same zero and it will try to choose the next path to be the one closest to the current machine position. This may sometimes generate an odd choice for the next path since it’s a mathematical calculated value – and not the logical choice for a human!

Β Splitting the g-code in the x-direction

When you start G-Code Utility it looks like this:

The G-Code Utility interface

The G-Code Utility interface

Go to File -> Input file and select the g-code file generated by FreeMILL and press “Open”. Remember, we are using the file we generated for a flat tool 3,2 mm i diameter and with a step distance of 2,8 mm. In my case it’s called “mads5c_3.2_flat_2.8_step_x.nc” as seen in the screen dump.

Input file selection

Input file selection

Now, got to File -> Output file and type in the name that you want to prefix your output files and press “Save”. In my case I choose “mads5c_3.2_flat_2.8_step_x_mod.nc” (“mod” for “modified”).

Output file

Output file selection

G-Code Utility will then generate files with file names on the form “mads5c_3.2_flat_2.8_step_x_mod(limit -X.XX).nc” where X.XX is the limit used in that particular file.

Go to Setup -> Options to display the options:



The default options displayed above are the option I use for my ShapeOko 2. They should be quite easy to understand but here’s the explanation anyway:

Decimals -> Reduce decimals

Check to reduce decimals in the code. There is no reason to use more than 4 decimals when sending coordinates to the g-shield.

String length -> Reduce length

Check to reduce string length. The g-shield can only take strings of length 50 characters. You can change it if you use another shield.

Step size -> Step size in mm.

Change to change the difference in depth used in the files generated by G-Code Utility. Never use a value larger than half the diameter of the tool you’re going to use.

Step size -> Split output into several files

If unchecked G-Code Utility will only generate one output file with the g-code for each step collected in section so the CNC machine will first run g-code for maximum depth plus limit, then code for maximum depth plus 2 time the limit, and so on.

Path optimization -> Optimize path

If unchecked G-Code Utility will not try to take the closest path as the next one. Instead it will simply take the next path in the original file.

Speed -> Movement speed

The movement speed (when not cutting) in mm per minute.

Speed -> Cutting speed

The speed in mm per minute when cutting.

Speed -> Engagement speed

The speed in mm per minute used when moving the cutter into the stock (downwards). Should in my experience never be more than 1000 mm/minute. Values higher than 1000 can cause the z-axis stepper motor to skip some steps.

Speed -> Retraction speed

The speed in mm per minute used when moving the cutter out of the stock (upwards). Should in my experience never be more than 1000 mm/minute. Values higher than 1000 can cause the z-axis stepper motor to skip some steps.

Safety height -> Safety height in mm

Determines the distance above the stock where the CNC machine can safely move without cutting. Should never be less than 1.


When you’re satisfied with your choices, press “Start processing” in the main window. It will process the file in the background and tell you the result in a dialog. The three progress bars will tell you how your job is progressing.

Thats it! We’ve now split the original file into several files with limits from -17 mm to -1 mm. Now we just need to repeat the process with the file for the y-direction.

Output files

Output files

Control the g-code files generated by G-Code Utility

I always check the generated g-code files with a g-code viewer (there are several versions available – even on-line versions) just to see if it looks reasonable to me. In this case I’ve shown the file “mads5c_3.2_flat_2.8_step_x_mod(limit -7.00).nc” viewed in Universal Gcode Sender in file mode.

The file with limit -7.00 viewed in Universal Gcode Sender

The file with limit -7.00 viewed in Universal Gcode Sender

When you feel comfortable with the g-code you’ve generated it’s time to go to the workshop! πŸ™‚

PS! Bug reports and suggestions for G-code Utility are very welcome.

Part 5.

ShapeOko 2 tutorial – Dominion turntable


This is the first part of my tutorial on using the ShapeOko 2 for building a Dominion turntable looking a little like this one.

First of all you’ll need a CNC machine. I got mine from Inventables and upgraded it with a Kress 800 FME spindle (the ShapeOko forum has some nice posts on the bigger Kress 1050 spindle). I posted some posts about building my ShapeOko 2 (here’s another one). I’m very pleased with the performance of my new spindle. The stock spindle (the Dremel clone) wasn’t strong enough for continuous work in my opinion.

Then there is software: there is a lot of free and open source software out there for the purpose of drawing, generate g-code and sending the g-code to the ShapeOko 2. I find the following combination of software useful:

OpenSCAD: An open source CAD program. It doesn’t have a lot of fancy drag and drop features but it is solid and gets the job done. There is a lot of documentation and tutorials on the homepage for the beginner so don’t be scared by the programmatic approach (which suits a mathematician and programmer like me very well πŸ™‚ ).

Inkscape: Another open source program for drawing SVG files which sometimes are handy when creating simple tasks for the ShapeOko 2. Again the homepage contains a lot of useful information for the beginner: tutorials, videos, blogs and a strong community.

MakerCAM: An on-line g-code generator. It’s simple to use and I use it for simple tasks. A good tutorial on how to use Makercam can be seen here and some more useful information can be found here.

FreeMILL: A free program from MecSoft (thank you for making this excellent program free πŸ™‚ ). If you get fascinated by making things on a CNC machine (like me) then you should consider some of their non-free products (no, I don’t get paid for writing this!).

Grbl Controller: A open source g-code sender for communicating with the CNC machine. There is also a tutorial on how to run Grbl Controller on a Raspberry Pi. A list of g-code senders can be seen here.

Last but not least: I needed a small utility for breaking down the g-code generated by FreeMILL so I made one (I will make it available for download later on). The thing is that FreeMILL generates g-code describing the surface of a solid (imported as STL) which often isn’t possible for the ShapeOko 2 to run directly because the cuts are simply too deep for the machine to handle in one run. Therefore, I created a small tool to break down the file from FreeMILL so it can be milled a few millimeters at a time. I’ll write more about it, when we reach that part. πŸ™‚

At the end of this tutorial we’ll have created something like this:

Dominion turntable

I’ll take you through the process step by step and tell you about my experiences with the ShapeOko 2 along the road (Murphy has been a very frequent but uninvited guest in my workshop since I got my ShapeOko 2!). πŸ™‚

Part 2.