Adjust 3D Printer GCODE for a Custom CNC Machine

In my last post I showed y’all my new CNC machine that I converted from a laser engraver.  On this post I’ll share how I’m converting the GCODE from S3D to be usable for the CNC machine.  Firstly, I mentioned in the prior post that I further customized the firmware for the controller and the controller itself.  I inverted the Z axis movement direction by simply reorienting the stepper motor cable going into the controller 180°.  I could have done this in the firmware but this was easy and my cable connectors aren’t keyed right now for a specific orientation.  This means something very important though.  When the firmware thinks its moving up to print another layer it’s actually moving down, and when it thinks that the extruder is printing it’s actually ripping wood out of the area the extruder ought to be.  Something that is very important about this though is the toolhead movement between extrusion needs to be moved physically up so it doesn’t cut through a place where it’s not supposed to.  This also means that the firmware has to accommodate moving “lower” (physically higher) than the build plate.  In order to allow this I had to define minimum software endstops as false.

#define min_software_endstops false

To make the router bit move up before moving to the next cutting spot, I run a VBA script using Microsoft Word to insert a movement before every instance.  In S3D I make the X/Y Movement speed something unique to all of the different speeds.

Every time the find function finds “F800” it turns on reference mode (G91), moves vertically a predefined amount of space that is taller than the maximum cut depth, turns on absolute mode (G90) moves to the next spot and then does the same thing in reverse.

Here’s a screenshot of the actual code:

Here is the actual text in case you’d like to replicate what I’m doing:


 

Sub AdjustGCodeforCN()

Dim OnMove As String

Dim OnCount As Integer

OnMove = “F800”

If OnMove > “” Then

‘ Set the counter to zero for each loop

OnCount = 0

Application.ScreenUpdating = False

With Selection

.HomeKey Unit:=wdStory

With .Find

.ClearFormatting

.Text = OnMove

‘ Loop until Word can no longer

‘ find the search string and

‘ count each instance

Do While .Execute

OnCount = OnCount + 1

Selection.HomeKey Unit:=wdLine ‘ home button,

Selection.TypeText Text:=”G91″

Selection.TypeParagraph

Selection.TypeText Text:=”G1 Z-4.5″

Selection.TypeParagraph

Selection.TypeText Text:=”G90″

Selection.TypeParagraph

Selection.MoveDown Unit:=wdLine, Count:=1

Selection.TypeText Text:=”G91″

Selection.TypeParagraph

Selection.TypeText Text:=”G1 Z4.5″

Selection.TypeParagraph

Selection.TypeText Text:=”G90″

Selection.TypeParagraph

Selection.MoveRight

Loop

End With

End With

Application.ScreenUpdating = True

End If

Application.ScreenUpdating = True

MsgBox OnMove + ” appears ” & OnCount & “”

End Sub


After saving the newly adjusted GCODE, if you preview the code you can see the movement.  It is a little confusing though because it’s easier to see if you turn off the view of the build plate.

I have the CNC machine set up in the garage for obvious reasons, so I’ve been using OctoPrint to run the controller outside.  I’m still turning the spindle on manually but I’ll be adjusting that soon.

I made a super short video to show you what the code does for a little reference.  

I’d be super interested if anybody used something different or replicated my plan.  Hope this helps!!

Leave a Reply