Our Advice When Setting Up Mach4 with ESS and J Tech Lasers
We have been getting requests to make a page on how to set up Mach4 for J Tech Lasers, as it is a bit confusing on the website on how to get the laser set up. So, we have answered the call and have set up Mach4 on our lab machine and want to share how to get it done for everyone. Let’s get started!
- Ethernet Smooth Stepper Control Board – This is the control board you need to run Mach4. Our instructions for the laser will only work with this board. You can get details for it here: https://warp9td.com/
- Breakout Board for the Smooth Stepper – There are a lot of options for this. We used the generic screw terminal board to get access to the signals. Here is the one we used: Breakout
- Ribbon Cable for the breakout is HERE
- Mach4 Software – Get it here: https://www.machsupport.com/software/mach4/
- J Tech Laser – If you have a mach4 machine, then try the Generic Bundle here: https://jtechphotonics.com/?product=generic-all-in-one-laser-and-mounting-kit-bundle
Electrical Hook Up:
We used Port 3 as our outputs from the breakout board to control the laser. We used Port 3, Pin 17 for the Laser PWM signal and Pin 26 for the Ground Signal. Optionally, you could use Pin 1 as it has slightly more current. Connect this to the laser driver input H4 or H2 port on the back of the driver.
The silkscreen on the breakout board will be incorrect. Pin 17 on the smoothstepper is labeled pin 8 on the breakout.
Note, your breakout board might be backwards to what the smoothstepper is expecting. Don’t use the silkscreen on the top of the board, but rather use this pin-out for the breakout board circled in green:
If you already have Mach4 set up for your router or milling machine, then you can copy a profile that is already working and then modify it for the laser. In our case, we had to set up a complete machine from scratch to get it to work. We went through the Warp9 instructions to get the basic machine up and running. We are assuming you either already have a machine profile set up, or you can follow the instructions on the Warp9 page to get this far.
Instructions for setting up your profile in Mach4:
Now that you have your machine configured, then you can start your profile and we will go through how to set up the laser portion of the machine. These instructions are taking from here and modified a bit for our specific machine:
We are going to be setting up two modes for the laser:
- Vector Mode – This will be for toolpaths with vectors in them that you create using a program like Vectric Aspire, V Carve, or Cut2D using a post processor.
- Rastor Mode – This will be for engraving images with Mach4.
Setting Up The Configuration:
1. To set up a Laser, go to Mach4 Menu -> Configure ->Control..>(was Mach4) -> Plugins.
Make sure that the Core, LUA, Regfile and ESS plugins are enabled.
2. Now, go to Mach4 Menu -> Configure ->Plugins… -> ESS ### -> Pins Config Tab:
In the Pins Config tab, we are going to assign a name to two pins for our Gate and PWM signals. I used Port 3 because I have nothing else on it and it is easy to expand out.
- Determine which output pin will be your Laser PWM output pin (I picked Port 3- Pin 17).
- Determine which output pin will be your Laser Gate output pin (I picked Port 3-Pin 1). If your Laser does not use a Gate signal, YOU WILL STILL NEED TO ASSIGN ONE, but you may pick any unused output on the ESS, since you will not need to (or be able to) wire it up.
3. In the Output Signals Tab:
- Set the “Laser PWM” signal to the Laser PWM output pin selected in the last step.
- Scroll down to the Output Numbers area, and select an unused one. I picked Output #20, and assigned it to the Laser Gate output pin selected in the last step.
4. In the Laser Tab:
For the Rastor Mode settings, you might need to change these when doing pictures. Mostly, it would be the flipping of the image. Keep these not selected unless you run into a situation where you might need them.
- Depending on the starting corner of your image, you may need to check “Flip Image Horizontally” to get the orientation and lettering to appear correct. This will flip or mirror your image left to right.
- Depending on the starting corner of your image, you may need to check “Flip Image Vertically”to get the orientation and lettering to appear correct. This will flip or mirror your image top to bottom.
- In an image, pure white (or the pixel value of 255) will burn with full intensity, and pure black (or the pixel value of 0) will not burn at all. To switch this, check “Invert Image Intensities”.
- “Compensate for X Acceleration Distance” means that the plugin will calculate the distance it takes to get up to the commanded velocity, which is where the pixels will be burned. The plugin will automatically move in the opposite direction before it starts to burn the first line of the image, so that the first image pixel will occur at the starting point of the Laser Raster. If you are using the “_Laser_Raster_Velocities.txt” file to manually adjust the Pre-Comp offset, that will be in addition to this automatically calculated value.
- If “Skip the Laser Raster Start Window” is unchecked, you will be prompted with a confirmation window before the Laser Raster Starts. Check this, if you do not want to see the confirmation window.
- “Laser Raster Even Rows Only” may be checked, and then only the Even Numbered rows (all in the same direction) will be burned. This is useful if you wish to check the overlap distance of your laser beam, or if you are having alignment issues with your Odd Numbered rows (i.e. a single vertical line is being rastered as two vertical lines – in this case, you would need to adjust your Motor Delay Distance).
6. Download these lua macros, unzip them, and place them in your “C:\Mach4Hobb\Profiles\YOUR_PROFILE_NAME\Macros\” folder. These macros will be discussed in the next section.
7. Close down Mach4 and Restart to let the settings take effect.
Running J Tech Lasers with Mach4
Now you have the setup all done, let’s go through a project really quickly.
We are going to do this in Vectric Using the J Tech Mach4 post processor. You can get it here:
We have it right here as well to download:
MACH 4 – Vector No Z
Once you download the post processor, install it in Vectric by either putting it in the PostP folder or by using the install post processor function under the toolpath menu.
Create your text in Vectric and then select the quick engrave toolpath.
Select your tool. We used a 7W with a high res lens. Your spindle speed will be your Laser Power in Percentage form. It will be from 0% to 97%.
*NOTE* There is a glitch that only allows 0 to 97% power. If you put over 97%, then the laser won’t fire at all. Choose between 0 and 97 for laser power.
Choose your vectors and calculate the toolpath.
Choose your “J Tech Laser Mach4 Vector – No Z (inch)” post processor from the list. Press “Save Toolpath” and save it to your computer.
Open up Mach4 and press the “load G Code” button. Choose your file.
Press the “Enable” button to enable the machine. Then press the “Cycle Start” button to start the engraving. Make sure you are at your zero point.
It should now run and engrave your text. You can do more advanced engravings by using fills and the other features of the Vectric products.
Picture engraving in Mach4 is not a simple process. I recommend that you try the demo before you jump into purchasing a Mach4 machine license to see if you can hack doing pictures. There are a lot of settings you need to get correct, including your image file and your configuration. If you have any of them wrong, it will not work.
Enough for the disclaimer, let’s try this out!
- You will need to have a directory with your pictures you want to engrave as well as a G Code file you edit to start your engraving. Let’s start by making a folder for your pictures.
We made a folder on the C:\ drive labeled “pictures”.
In order to start a laser image process, you need to create a small G Code file. It will have the parameters in it for the image to be processed. Once you get all of the settings correct, you can then just change the name of the image in the file to run.
Here are the lua script commands used to set up the Laser Raster:
1. m2000 (C:\Pictures\image.bmp) This command will look for the image.bmp picture in your C drive. You can point to any folder location you wish, and use any image name that you wish. The requirement is that the image be a 256 color (8 bit) gray scale bitmap or a 24 bit RGB bitmap without an alpha channel.
2. m2001 (Comment)
- m2001 (UNITS=IN) This will tell the software that all your commanded values will be in Inches. This must be the same as the default units for your profile in Mach4’s General Tab for Machine Setup Units. If your default units are metric, you must call m2001 (UNITS=MM) for the software to run.
- m2001 (FEEDRATE=900.9) you may specify your desired feedrate. However for Build 221, it will be ignored and the appropriate, calculated, feedrate will be used.
- m2001 (IMAGE_STARTING_CORNER=#) The Laser Raster will start from the commanded corner and work to the opposite corner. Replace the # with 1, 2, 3 or 4. 1 means start from the Lower Left corner of the image. 2 means start from the Lower Right corner of the image. 3 means start from the Upper Right corner of the image. 4 means start from the Upper Left corner of the image.
- m2001 (IMAGE_COLOR_CHANNEL= #) If you are using a 256 color gray scale image, this command is not important. If you are using an 24 bit RGB image, this command allows you to select which color channel the image data will be taken from. 1 means the Red color channel.2 means the Green color channel. 3 means the Blue color channel. 4 means the average of all three color channels.
- m2001 (IMAGE_INVERT_INTENSITIES=0) 0 Means that pure white (or the pixel value of 255) will burn with full intensity, and pure black (or the pixel value of 0) will not burn at all. 1 means that pure black (or the pixel value of 0) will burn with full intensity, and pure white (or the pixel value of 255) will not burn at all. This will override the default setting in the Laser tab for “Invert Image Intensities”.
- m2001 (IMAGE_FLIP_X=0) Depending on the starting corner of your image, you may need to set this to 1 to get the orientation and lettering to appear correct, by flipping or mirroring your image left to right. This will override the default setting in the Laser tab for “Flip Image Horizontally”.
- m2001 (IMAGE_FLIP_Y=0) Depending on the starting corner of your image, you may need to set this to 1 to get the orientation and lettering to appear correct, by flipping or mirroring your image top to bottom. This will override the default setting in the Laser tab for “Flip Image Vertically”.
- m2001 (PWM_MAX=100) This will set the Maximum PWM Duty Cycle corresponding to a pixel intensity value of 255 (full burn value). Depending on the speed of the raster, a 100% value may be too high.
- m2001 (PWM_MIN=15) This will set the Minimum PWM Duty Cycle corresponding to a pixel intensity value of 0 (no burn value). Depending on the speed of the raster, a 0% value may be too low. This is ideally set just low enough that it does not burn the surface of the material, but a pixel value of 1 will.
- m2001 (SHOW_WINDOW_TO_START=1) When set to 1, you will be prompted with a confirmation window before the Laser Raster Starts. Set this to 0 if you do not want to see the confirmation window. This will override the default setting in the Laser tab for “Skip the Laser Raster Start Window”.
3. m2002 (This starts the Laser Raster) This will tell the software to start the laser raster process.
When the laser raster process starts, a log file is created and updated at “C:\Mach4Hobby\Plugins\_PROCESSING LASER COMMANDS LOG.txt“. This file will explain what is happening and what, if anything, went wrong. This is very useful to see if your settings are incorrect.
For an example, warp9 has a test file and program you can run. Here are the files to run this:
Here is the G Code file explained:
G00 X1.0500 Y1.9465
M2001(UNITS = in)
M2001(FEEDRATE = 10.000000)
M2001(IMAGE_STARTING_CORNER = 1)
M2001(IMAGE_COLOR_CHANNEL = 1)
M2001(IMAGE_INVERT_INTENSITIES = 0)
M2001(IMAGE_FLIP_X = 0)
M2001(IMAGE_FLIP_Y = 0)
M2001(MOTOR_DELAY_DISTANCE_X = 0.0)
M2001(PWM_MAX = 90)
M2001(PWM_Min = 5)
M2001(PWM_ZERO = 0)
M2001(SHOW_WINDOW_TO_START = 1)
M2001(SHOW_IMAGE_CORNER_POSITIONS = 0)
M2002(This starts the Laser Raster)
G4P1 (Wait here while the Raster happens)
G00 X1.0010 Y1.9990
G01 X1.9990 F90
G00 X0 Y0
Note, you can change the initial offset, the feedrate, and the corner where you start. Try messing around with this in the file and see how you like to engrave your pictures. Once you have it set, then load into Mach4 and press Cycle Start. You will get a pop up telling you the speed at which it will engrave. Press Yes to continue.
The picture should start engraving after this.
Running New Picture Files
Now that you have the example from the shield image, you can run new pictures by just changing the name of the image in the file. Here is how to make your new image and format it correctly to work.
We recommenced using the photo editing software that Warp9 recomends as well. It is called GIMP and it is free and open source. Here is the download link:
Load your color image into the program. You can use the “Scale Image” to make it a size you want. Adjust the resolution and the size to match what you want to engrave. Then press the “export as” to save the image.
Click on the “select by file type”
Then select the Windows BMP format and press Export.
Make sure you check the “do not write color space information” in the compatibility options. Check the “R8 G8 B8” in the advanced options. Then Export the image by clicking Export.
We put the image into the pictures folder and changed the path name to the name of the image we just exported. This line would be this for the image:
Now try your own pictures and start to play!
If you run into issues, Warp9 discusses how to do line alignment if your axis are off in the rastor. Here is from their website:
Laser Raster Line Alignment
For Laser Rastering, each row starts by accelerating up to the commanded velocity (feed rate) at which point the SmoothStepper will start issuing the PWM values for each pixel. Once all of the pixel data for the row has been used (over the distance commanded for the row in the image), the X axis motion then decelerates to a stop so the Y line distance can be moved before the next row is rastered in the opposite direction. If you motors or axes have lag (this could even be just a little backlash pullout) you will have a horizontal offset in your rastered image. You can easily see if this is the issue by selecting the option in the Laser tab for “Laser Raster Even Rows Only”, and the alignment issue will be gone on your next image. Please make sure you uncheck this option after you have verified that this is the issue.
To fix this issue, you will need to adjust your “Motor Delay Distance” in C:\Mach4Hobby\Plugins\_Laser_Raster_Velocities.txt
Your delay distance will need to be essentially 50% of the distance you are off by in your original alignment at that velocity or feed rate. The faster your feed rate, the larger your Motor Delay distance will need to be. It is best to enter specific distance values for all of your common feed rates, but the software will interpolate the distance based off of higher and lower values. Once these changes have been made your image should be in perfect alignment. More information regarding the setup is inside the “_Laser_Raster_Velocities.txt” file itself. Please make sure to include one or two distance lines for feed rates faster than you expect to use so you are covered on the high end if you forget.
First try with Laser Raster Line Alignment Issues
Second and Third tries with Laser Raster Line Alignment Issues, and success on the Fourth attempt.
The image above shows that the alignment was corrected with the proper motor delay distance. However, the quality of the image still suffers a little bit due to insufficient resolution; increasing the DPI would help to improve the quality of the image.