4-axis CNC Foam Cutter using Marlin 3d Printer Firmware


The 4-axis CNC foam cutter, until now, required a Windows computer to run the software to send G-codes to the controller. Several times, I have been asked if there is a way to run the foam cutter like a 3d printer by just inserting an SD card with the g-code.

Recently, I upgraded my 3d printer with some new hardware and decided to switch to version 2 of the Marlin firmware.  I spotted in the example configurations one for a foam cutter. Could this be used to run the foam cutter?

This post will describe how to compile the firmware, upload and configure it. Please use the ebook and other posts on the site for building the foam cutter itself

Can Marlin firmware be used with a 4-axis CNC foam cutter? 

Yes, it can, but it needed several changes before it was usable on 4-axis foam cutting. 

I’ve received a great deal of help from a GitHub member called DerAndere. I would have struggled without his help and would probably have given up.  Many thanks.

To make configuration changes, you need to be quite familiar with compiling firmware for 3d printers.  Some settings can be changed through the LCD.

If compiling firmware seems a bit daunting to you, then I would encourage you to use the Windows-based software with the pre-compiled firmware.

It isn’t difficult to compile the firmware, and there are many good tutorials online.  But if things go wrong, it can be very frustrating and time-consuming.

Pros and Cons of using Marlin Firmware for CNC Foam Cutting

I don’t use this firmware. It was developed primarily for users who don’t use Windows 10 or 11. My preferred options are grbl and grblHAL.

Pros

  • No PC is required. 
  • It may be possible to run on 32-bit control boards.

Cons

  • G93 feed mode is not supported. Good for more complex designs.
  • Aligning the wire to the foam before a cut takes a lot longer.
  • Must use axes XYUV

Hardware requirements

So far, I have tested this on the Arduino Mega 2560 with a RAMPS board. As yet, I haven’t tried the MKS Gen L board. However, it should work as the MKS Gen L is essentially the same, but combined into a single board. You will also need an LCD 12864 with an integrated card reader. Here’s the one I used from Banggood

You will also need 4 driver modules for your chosen board. I used the A4988, which worked fine on my foam cutter. The build of my foam cutter is here How to Build a $200 USB Hot Wire CNC Foam Cutter – Free eBook

A parts list is here, and you need to add an LCD as linked above.

Software required to compile and upload the firmware

The firmware uses Marlin 2.0.9.3 with several configuration changes to suit the foam cutter.

To compile the firmware, you will need Visual Studio Code with the Platform IO and Marlin extensions. Here is a good video showing how to install these. https://www.youtube.com/watch?v=eq_ygvHF29I&t=304s

I won’t cover installing software because there are already several good sources for this.

The software will run on Windows, Mac and Linux. I used Windows 10.

Compiling the firmware

Download the source code from https://github.com/rcKeith/Marlin and save it to a suitable location on your computer.

Extract the files from the zip file and then from the File menu in Visual Studio Code select Open Folder and select Marlin in the extracted files and your screen should look like the image below.

Make sure Visual Studio Code looks like the screenshot below with the PlatformIO and Marlin extension.

Visual Studio Code with PlatformIO and Marlin extensions

Building the firmware

First, we’ll build the firmware just to make sure we have no errors and upload it in a later step.

Click on the Marlin icon on the sidebar and then the hammer icon

Visual Studio Code build option

Click the Build button next to the mega2560

Visual Studio Code click the build button

If you get any errors, try building again; sometimes it needs to download additional libraries, which can cause an error. If you still get errors, then look at the first in the terminal window; most that follow are related to that error. Quite often, if you have altered the code, it may be just a simple typo or a missing semicolon.

Once you have a build with no errors, then plug in your control board and click Upload. This will detect the correct USB port and upload the hex file, and then read it back to verify it was a good upload.

The rest of the foam cutter build is the same as the Windows version, so please use the ebook, videos and posts on the website. There will be a video coming soon showing the steps in this post.

Microstepping Settings

The RAMPS and MKS Gen L boards’ microstepping is configured via the MS1, MS2 and MS3 jumpers

Put jumpers on MS1 and MS2 to set 1/8 microstepping.

RAMPS microstepping
Jumpers set for 1/8 microstepping

Drivers and Connections

The drivers need to go in sockets X, Y, E0 and E1. Don’t use Z. Make sure to align the enable pin on the driver with the enable on the RAMPS board. The driver will be destroyed if you don’t.

Use either the A4988 or DRV8825 drivers. Others will work, but you will need to change the firmware source code. I have only used the two mentioned and have no experience with any others.

RAMPS Wiring

You will need to set the VREF of the drivers to match your stepper motors. Watch my video showing how to do this. The driver location in the video is for the GRBL firmware; please ignore that. The setting of the VREF is exactly the same. Use the form below to get the correct VREF voltage

Configuration

The firmware has been configured to use the same settings used in the GRBL Mega 5X as much as possible. During my testing, they worked very well on my machine. If you use the same design, then the firmware should not need any changes.

Checking Axis direction

From the menu, select Motion and select each axis. Select the 1mm option and move the dial in the positive direction from 0.00 to +1.00 mm. X and U should move forward, and Y and V should go up.

If you find that an axis goes the wrong way, the simplest option is to reverse the stepper motor cable on the RAMPS or MKS board. This will change the direction. If this isn’t possible, then you will need to change the code as shown below.

It’s possible to change the direction in the firmware, but you will need to edit the Configuration. h around line 1404 and re-compile and upload. Internally, the U axis is referred to as I and the V axis as J

Changing the axis direction
Toggle true or false to change direction.

Homing

The firmware is configured to use 4 end-stops with the pinout shown below. Please note pin D42 is a signal pin, the pin next to it is D43 and is not a ground pin. Use a spare ground pin where the other end stop pins are.

marlin  2 cnc foam cutter ramps pinout

This is the only configuration I have tested and it works without any issues on my machine. If you have issues, then you will need to change the code as below.

marlin homing invert direction
Change -1 to 1 to reverse the direction of homing

Checking Calibration

Once your axes are moving correctly, the next thing to do is check the calibration. We need to make sure that when a g-code is received for an axis to move a specific distance, it does. To check this, place a rule and make a pointer. I just used a paper clip attached to a nut on the carriage as shown below.

Calibrating the Hot Wire CNC Foam cutter steps per mm
Checking calibration

The bigger the distance you can check, the more accurate the results will be. Set the pointer on say 300 mm and then in the Move menu select 10 mm and rotate the knob to 100 mm. There is a 100 mm option, but if you turn it too quickly, you may move beyond your machine’s limits. Check how far the pointer has moved. If it has moved to the 200 mm mark on the steel rule, then that’s correct. If not, we need to adjust the steps/mm.

The steps/mm can be adjusted from the LCD menu under Configuration ->Advanced Settings

steps per millimeter
Default steps per millimetre

If for example, it only moved 98 mm, then we need to calculate a new value for the steps per millimetre. Use the form below to calculate the new value.

So in our example, where it only moved 98 mm, the new value would be 1088. Select the axis in the menu on the LCD screen and adjust the value with the rotary knob. Then run the calibration check again and rerun the check again if necessary. If it’s now correct, we need to store the settings on the board. From the Configuration Menu, select Store Settings.

The steps per millimetre should be the same for all axes. It may be worth checking them all just to be sure.

Testing the Hot Wire

I use a Nichrome wire of 0.4 mm in diameter. This works very well for me on both the RAMPS board at 12 Volts and the MKS at 24 volts. If you are going to place the carriages more than 1000 mm apart, then the 12-volt RAMPS will not provide enough power. Use an MKS Gen L board with a 24 Volt power supply.

You will need to experiment with the ideal settings. Type of foam, wire and carriage distance all have an impact on the percentage used in the menu for Hot Wire Pwr:

Marlin Hot wire  power settings
Hot Wire Menu

Test with some scrap foam just by holding it against the wire. It should melt easily but not leave a large kerf(the amount melted away). It’s a bit of trial and error, but worth running some tests.

Dry Run

Use the g-code below to run the machine without any foam, and the hot wire the turned off. Load the file onto an SD card and insert it into the LCD slot. From the main menu, select Cut from Media and confirm. You may find it runs too fast and misses steps or is too slow. You can adjust the acceleration and velocity in the Advanced menu.

Icon

Clark-Y test file for Marlin Firmware XYUV axes 42.18 KB 1057 downloads

Use this file to test the foam cutter using Marlin firmware from https://github.com/rcKeith/Marlin …

First Cut

If your dry run is good, then now it’s time to test with some foam. Set your hot wire on from the menu and run the file again. Make sure the wire isn’t dragging on the foam, which usually indicates too fast a feed rate or that the wire isn’t hot enough. If all is well, yours should look like the image below.

clarky test cut use the Marlin firware
Nice Clark-Y airfoil test
YouTube player

Generating G-code

Now that your machine is running well, you will need to generate some g-code for your projects. I have a post on the website showing the various options available. G-code generation software to make foam wings and fuselages with a CNC foam cutter, so I’ll refer you to that. Please remember to use the XYUV axes in your chosen software.

Conclusion

This was quite a challenge to use the Marlin firmware, and I had some good help, as mentioned earlier. Please use with caution and run lots of tests.

Happy foam cutting

Similar Posts