INTRODUCTION TO HOW TO CUSTOMIZE CNC CONTROL SOFTWARE NAMED MACH3 TO CONTROL 3D PRINTER WHICH HAS LINEAR EXTRUDING MOTION

written by Junghoon LEE

South Korea

written in March 2019

I. Introduction

Generally 3D printer on the shelf is controlled by embedded software supplied by the manufacturer. But when a maker is trying to set up a 3D printer by herself, it is definitely not an easy task to develop or write a software and firmware to control the printer, though assembling parts of the printer could be rather easy.

I first was planning to make a 3D printer by myself from top to bottom, which requires designing and assembling motor drivers, logic board, firmware, software and hardware. But under the time constraint, I had to find a other way around. I adopted different approach to overcome my limitations on the project, by utilizing pre-built systems such as a machine with 2 axis of linear motion implementing a belt driven system, microcontroller(arduino MEGA2560) with an add-on interface(ramps 1.4), all-in-one controller(stm32f103 based CNC controller), stepper motor driver(based on a TB6600 IC), ect. Hereunder, I summarized a short essay about how I could utilize pre-existing tools for completing controller of a multi-axis machine.

II. Setting Up a 3D Printer

After assembling mechanical parts of the multi-axis machine, such as moving axis, stepper motors, setting the right amount of tension to the belts, aligning the aluminium profiles, now I was ready to wire the motor and drivers with the corresponding connections. At first, I tried an arduino mega 2560 with TB6600 motor drivers, in order to control the printer. However, the ramps board did not show the direction, step, enable pins populated on the board. By having a look at the schematic of the ramps PCB and some searching of the code that is for the marlin firmware, I matched all the needed connections and soldered wire to the corresponding pins.

There are several advantages in using the external stepper motor driver(with a big heat sink) instead of small integrated drivers that plugs on to the controller board. The external motor driver is powerful enough to run all motors of a 3D printer, unlike a small integrated stepper that over heats which causing shortening the overall lifespan of the driver. Furthermore, current setting and micro stepping of a motor can be easily performed via hardware switch that is also helpful for troubleshooting.

The software that I used was Marlin firmware for the arduino and Pronterface software for PC to control the printer. For the mechanical part, I used a XY axis platform, which requires one motor for the x-axis and two motor for the y-axis. For the z-axis, that is an extruder, I used a lead screw driven by sliding axis that is c-shaped aluminum profile.

III. Testing

I programmed the arduino with the Marlin firmware and downloaded the Pronterface software on my PC. I connected my arduino board with the Pronterface software via USB. After selecting the proper baud rate to make the arduino and Pronterface software for the PC to communicate to each other, I was able to connect the arduino to my PC.

Next, I tried to test the printer by moving all the axis by entering commanding order in my PC, in order to make sure all the axis were moving to direction ordered. In order for the test being performed properly, it was required that the printer must have the same measurement as Pronterface software of PC does. Accordingly I made some modifications of the measurement to the Marrlin firmware of the arduino and stepper drivers, after calculating such measurement.

To make sure that the printer run as coordinated by a command, I did some G-code work. After making a test image and converting into G-code, I loaded the code to the PC to check that it work properly. However, it did not work as what I intended. After frantic search for a solution to the problem, I could find out the cause of the problem. It was a part of the code(c++) for safety feature of the Marlin firmware that makes the printer in a locked state which locks the motor when the extruder is in a cold state. In order to relieve the safety feature, I made the required modifications to the firmware, including axis homing, motor acceleration, temperature sensor value, and more. After all the troubleshooting, I finally made the printer work as I commanded.

IV. In Big Trouble

The last part of the printer test was the z-axis, the extruder. An image is a two dimensional drawing, which can be described in x and y coordinates. The printer however needs a extra z-axis because it’s a three dimensional machine. I could move the z-axis via the PC, but it was difficult and inefficient. On top of that, writing the G-code for the z-axis is possible. But it would literally take a few centuries to code manually all the commands required for the z-axis. At this point I needed to find another way to solve this stalemate.

V. The Breakthrough

During Internet search, I came across a program called ‘Mach3’. At first glance, I had gut feeling that this program might be a cure-all to my problems.

Mach3 is a program for controlling CNC machines. There is a lot more CNC based programs other than Mach3. But Mach was best suited for my purpose because it was very helpful in troubleshooting CNC based machines. After a bit of learning from YouTube tutorials, reading some introductory materials, I bought a Mach3 compatible board called ‘RnRmotion’, which was a CNC board that runs on a stm32f103 (ARM cortex-M3) processor.

The CNC board(RnRmotion controller board) was well suited for being used with external motor drivers. I used TB6600 stepper motor drivers. I connected all the connections that were needed. But at my first attempt, I had some trouble first getting it to run, later I got it to work properly. The reason why was in trouble in the first place was simply because there was not enough information available about this CNC board. Even there’s no proper documentation about the CNC board. Inevitably I had to figure it out by myself. A bit of reverse engineering of the board was also performed.

After confirming the CNC board communicate with the Mach3, I went into the Mach3 configuration tab and made changes. As the same case of arduino controller, I had to calculate the machine measurements and imported it into the Mach3. I also calculated the acceleration and deceleration of the motors. I used a program that converts an image into G-code, which is made to work with Marlin firmware. So I had to make some modifications of the G-code to make it work with the CNC board.

While I came across a program used to print high viscosity materials such as HVM. It was perfect to suite to my needs. I used those programs to make a G-code. After loading the G-code to the Mach3, I did a test run and confirmed that x and y axis was moving without any problems.

VI. The Final Troubleshooting

Finally I had to work on the Z axis, in other words, the material side. At the beginning, I couldn't get the Z-axis to work. Even after a long troubleshooting, I could not make the Z-axis work with the Mach3 compatible board. I needed to find a other way to use the Z axis.

Hopping to solve the problem, I decided to use the extra pins that were on the board which is responsible for the cooling and controlling different things on the CNC machine. Unfortunately, while I was connecting the pins to the CNC board, I shorted one of the power leads to a pin on the board. It fried one of the IC that was connected to the output pins that which I was going to use.

After studying the data sheet of the part I blew, I could understand an uln2003 darlington IC. I removed the burnt chip from the PCB by using a rework station. Since there were no schematic, circuit and even no proper documentation, I had do some more reverse engineering of the PCB. After utilizing all of my test equipment to find all the PCB traces that I needed, I made necessary connections by soldering directly to the PCB traces. After that, I needed a relay to turn on and off the Z-axis. I decided to use an arduino compatible relay or a SSR. But the stm32f103 pins could not provide current needed and voltage to be used with the relays.

By bypassing the uln2003 transistor, I was getting a 3.3v (80mA max) signal from the stm32. However to trigger a SSR(solid state relay), the logic voltage needs to be around 4~5v, for a latching relay the required current would be to high, exciting the 80mA current limit of the stm32. So I used a 2N2222A transistor to amplify the 3.3v signal coming from the stm32. It would not be ideal to be near or at the maximum current, which was 80mA. So I calculated the resistor value needed for the circuit. I was worrying about the offset voltage of the stm32 I/O pins. By differing the voltage offset of the signal with a function generator, I was able to obtain a threshold voltage of the 2N2222A. To my surprise, offset of the voltage was low enough, thus, higher than the minimum threshold value. After some testing, I wired the relay and the transistor circuit to the wire that I soldered directly to one of the solder pads that is connected to the I/O pins of the stm32. By entering the F7, F9 command on the Mach3 program while the motion board was connected, I was able to turn on and off the relay.

VII. Selecting Printing Materials

With regard to Mach3 software, I could turn on and off the Z-axis by sending a M7, M9 commands. Now I finished all the tasks for the electrical and mechanical side of the 3D printer. It was the time for me to decide what material I'm going to use.

I’ve done some research about what High-viscosity materials I could print with the machine. Before I started this project, I was planning on using a syringe type extruder. My method was to push the syringe which would be filled with the HVM(high-viscosity material), with linear actuators which would advance the HVM through the nozzle. This was a conventional approach on gravity assisted extruder, which is commonly used in FFF(Fused filament fabrication) or otherwise known as FDM(Fused deposition modeling).

The syringe based HVM consists of a food safe 150mm stroke syringe with different sized nozzle and 250mm stroke lead screw actuated linear axis with a 40mm Nema17 stepper motor. I did some rough estimations about the theory behind the HVM. Estimations are not acceptable in machines or any devices that require coordinated, reliable and repeatable movements.

But due to the lack of time, specific instruments that can measure with precision, are the few reasons why made brief calculations. To calculate the HVM extrusion forces, it could be obtained by use of the Hagen-Poiseuille equation.

VIII. Conclusion

Unfortunately due to school and other work, I had to stop the project. I could not finish the project that I was working on. But all the time and effort that was gone into this project, I think it was well worth to try. I had a lot of problems during my project. However, by slowly thinking back what I have learned in the past, I was able to figure out the problem that I have faced.