3D Printing on CNC using Mach3

by kai Dec 20, 2010
Download All Files

Please Login to Comment

Hey Kai, i know this is an old post - sorry for bringing it back from the dead... but i am looking at adding a 3d print head to my diy cnc machine running mach3. i have a 4 axis board for controlling the stepper - but i'm wanting to use a device (https://makerstorage.com/index.php?id_product=27&controller=product) which is best suited for wifi based communication for controlling temp and fans, and giving temp feedback. I've seen modbus looks to be the industry standard but no idea on where to go from there (at least inside mach3, including the commands etc) and was wondering if you had any advice, steps or resources about what i should be doing? i will need to write the firmware for the device myself anyway (the github for it indicates it wouldn't work without doing something) - but just not sure on what i can get from mach3 - or what i can write within it to get the functionality i'd need. I'm a programmer so not scared of needing to DIY the com stuff, just not sure where to start.

Thanks for at least looking at the comment even if you are unable to help.


A few years ago I wrote a mach3 vbscript that will send and receive serial commands to a 1980s controller board, this would work with your system here running Mach3, just send a serial read-control command in gcode..

I ended up writing a vbscript file, you load it into Mach3 gcode by calling it's M-code name, this one M995, initiates the opto22 422 link, sets up modules, and writes (0) position bit on.

I can use it like this, but.. the commands are so close to Modbus transactions of data that mach3 uses there has to be a way>?>
command string = ">" start of transmission, "FF" Hex address 255, A-Z command register, between 4 bytes and sixteen 4 byte transactions of data per unit.

Anyways.. here is a script that opens up the serial and is working right now.. I have 32 commands related to a 16 I/O board thou.. gets confusing.. and typos kill a gcode program faster than a bullet.

I commented the "other modules commands and do one command per Mcode"

'**** vbscript code
Mach 3 serial opto22 write ***
Authored Cofer 12-26-2013 NORF Gawgia
' Utilizing 16 bit opto22 Pb16hc card & B1 422 serial card. usb-422 adapter on com port 3
Private Declare Function timeGetTime Lib "WINMM.dll" () As Long
Dim M_flag As Boolean
Dim TimeToEnd As Boolean
Dim m_value As Double
Dim i, t As Integer
Dim not_complete As Boolean
Dim Add$, Cmd$, Pl$, Modi$, RetData$, Opto22Err$
Dim modules As Integer
Dim Byte_pick$
Dim pausetime As Long
Dim control_word$(25) 'array for all control g,M,n codes
Dim control_flag(25) As Boolean

Sub MyFunction()
Dim pwrup As Integer
Set MSComm1=CreateObject("MSCOMMLib.MSComm")
Dim t
MSComm1.Settings = "19200,n,8,1"
MSComm1.CommPort = 3
MSComm1.InBufferCount = 0
MSComm1.PortOpen = True
If Err Then
MsgBox "COM" & MSComm1.CommPort & ": not opened, Sorry!"
Exit Sub
End If

MSComm1.output=">FFACD" & Chr(13)  'opto22 power up clear at address FF
Call delay_MS_time(10)
'MsgBox " reply was " & MScomm1.input

MSComm1.output=">FFI000FAB" & Chr(13)  'configure the first four as outputs 
Call delay_MS_time(10)
'MsgBox " reply was " & MScomm1.input

MSComm1.output=">FFK000198" & Chr(13)  'TURN on bit one, opto22 address FF 
Call delay_MS_time(10)
'MsgBox " reply was " & MScomm1.input

' MSComm1.output=">FFK000299" & Chr(13) 'TURN on bit two, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input

' MSComm1.output=">FFK00049B" & Chr(13) 'TURN on bit three, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input
' MSComm1.output=">FFK00089F" & Chr(13) 'TURN on bit four, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input
' MSComm1.output=">FFL000199" & Chr(13) 'TURN OFF bit one, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input
' MSComm1.output=">FFL00029A" & Chr(13) 'TURN off bit two, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input

' MSComm1.output=">FFL00049C" & Chr(13) 'TURN off bit three, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input
' MSComm1.output=">FFL0008A0" & Chr(13) 'TURN off bit four, opto22 address FF
' Call delay_MS_time(10)
' 'MsgBox " reply was " & MScomm1.input

MSComm1.PortOpen = False
Set MSComm1 = Nothing

End Sub

Private Sub delay_MS_time(MsDelay)
Dim time_out As Double
time_out = MsDelay + timeGetTime()
Do Until time_out <= timeGetTime()
' the delay for the steppers accel/decell
End Sub

So this is for a DC-motor with encoder and PWM?

How do I use a Nema-17 stepper motor as the extruder motor and use Arduino to regulate temperature?

I was looking at this: http://www.buildlog.net/blog/2011/02/modbus-arduino-mach3-and-brains-oh-my/http://www.buildlog.net/blog/2...

Do I just add an axis in Mach-3 config and use ModBus to connect Arduino for temp control?

Any help greatly appreciated.

are you only using the stepper for the extruder?

Hi Kai, i have a question for you. i have a 4 axis mach 3 breakout board and a plastruder MK7 from makerbot with the controller board, how do i connect the extruder controller to the mach 3 board in order to control the temperture before printing. i have also order a heated and a temperature controller how do i connect that to my mach 3 board in order to regulate the temperature before printing. thank you

The easiest way to control temperature is using external PID controller. However, it usually can only set manually. If you want to set temp through Mach3, you will need some temp controller that able take TTL serial packet from Mach3. In my case, I just modify the code of extruder controller to do this. 

Hi, not sure if you are still pursuing this. I'm very interested in trying it. I have a plastruder mk5, makerbot extruder v3.6 with an ATMega328 on it with their v3.1 firmware. I've not been able to install your firmware - do I need to make any modifications to make it work with my setup?

hi, so far i am not work on it yet. I have made other 4 3D printer already. However, I can still willing to help people who what to do this.

My firmware is written on old extruder v2.2. That's probably the reason not working on your v3.6. However, it shouldn't be too bad to modify the code compatible to v3.6 if you know how to write Arduino code.

Great job! I have a PCNC 770, and I've had this in the back of my mind. Thanks for forging the trail!

why u not used stepper motor? why dc motor, can be possible to run stepper motor instead dc motor

i like stepper.. ;)

hi,can u make wires diagarm,,and ready to burn firmwares,, i don't have arduino only isp programmer,

whats the rating of your dc motor?

any video how do you do it all the setting for mach 3 =-X

Hello Kai,

Any new developments on the CNC and plastruder? How do i get the firmware?

Have you updated it to steppstruder yet?



Hi Kai.

I install ReplicatorG and Python. but I don't have a board that connect to ReplicatorG.

is it possible to get a G-code from ReplicatorG without a board?

(when I click on the "Generate Gcode" key, it shows "toolpath generating complete" but Gcode file doesn't make)

please help me!



Yes, we don't have board either. You will still able to produce g-code from ReplicatorG without a board.

is it possible to show me what can I do to get a Gcode (from a stl model)

I upload a video that shows my replicatorG.



replicatorG can open any type of stl (ascii
amp; binary) but can not produce g-code of binary type!

my model was binary, that was the problem.

thanks kai very mach.


Hi Kai. It appears that Mach 3 pauses when it encounters the M8 and M9 macros. This causes blobs of plastic to form. Do you see this behavior?

Yes, I do have this problem and still working on it. One approach is minimize M8/M9 code when change z height. For example, M8 -
gt; Move Z up -
gt; M9 becomes just Move Z up without stop/start feeder. This will help in some cases, but there still many chance you will need to stop feeder and travel to some where. So, I think the real solution is using 4-axis and stepper motor for the feeder. In this way, everything is controlled by G-code instead of M-code.

Hi Kai, disregard previous question. I have a new question. I notice you have the RS-485 connected. Now that the extruder controller is reprogrammed and you are communicating with it directly why is the RS-485 still connected to the motherboard. I would assume that the motherboard is no longer needed.

And yes, you don't need motherboard.

hi Scott,

RS485 here only provides power to the extruder controller and hot end, no data communication through this cable. The way I program the extruder controller board is through same USB-TTL cable with Arduino software(remember put RTS green pin back for programming).

Kai, thanks very much for providing the details of getting the extruder working with a CNC machine. How did you get the pde file on the extruder?

Hello Kai, I want to try Mach3 on the machine I''m building. I contacted Mach support and they told me it would not work. Are you willing to help?

Why it would not work? I am running it all the time. It seems complicate to make Mach3 as 3D printer because there are not much information out there. That's why I made this tutorial to help people utilize their CNC machine.

kai, I am working in my second home cnc, once I complete it in two more months I would like to also be able to print in 3D. Can you support me with your knowledge to make the conversion?

Thanks in advance for your help

Sure, let me know if you have any problems. Now I am working on stepper motor version of extruder, that's say "5D" version of g-code. It will take me a while to finish it. However, DC gearhead motor version already running pretty smoothly now.

I'm wanting to do something similar. I'd trying to avoide temp control, and simply put a PID or some other device to just keep the temp constant. I'm no programmer, but thought that a nice introduction to plastruders would be accomplished with as little delving into the electronics as possible. A plastruder with stepper and driver, and a stand alone temp control that just needs power to function would be an idea addition/mod to an existing CNC machine.

beyond incredible. I have a 15 foot by 6 foot shopbot. Man, could I print some stuff!


I'd love to see more of this great work done with EMC2/Axis (Casainho and two or three ppl did some time ago w/reprap). IMHO, the way to go, and unlike Mach3, it is FOSS.