End GCode for Xtool d1 help

This is my first forum post so please stick with me. I’m still getting used to the Lightburn form so I’m open to any suggestions about the right etiquette and formatting for this form.
I need some help adding a small command to my ending GCode. I am nervous about writing it myself because Lightburn displays a message under machine settings>Gcode that says “it is up to the user to ensure the commands will not damage their machine”.

TLDR: I want to add a command at the end of a job to move the laser head very slowly one way a few millimeters and then very slowly back a few millimeters. I have my units in mm and am using the device settings downloaded from the Xtool library. I believe it is a GRBL controller but am not positive.

The long explanation is that I bought the XTool d1 10 watts and recently replaced my diode with their much heavier 20 watts diode. I have noticed that if I run a job above around 90 mm/s the laser loses its origin after the job completes. I believe this is because the xtool software turns off the motors after completing a job and the inertia of the new heavy module moves it an additional mm or two. I use my laser to batch out business cards and it is crucial that I can keep the origin between different jobs. I have been able to correct this error by running an additional layer at 3mm/s and 5% power at the end of the job so that the laser head doesn’t have enough inertia to lose the zero I set up.
I googled it and xtool says it is a GRBL controller. I asked chat GPT for some code but wanted a second opinion before I attempted it with my laser. I do not have limit switches so I want to make sure it does this from the relevant position and keeps the same zero from the last job. right now my end GCode is empty and my start GCode is M106 S0. Below I’m putting the end Gcode that was generated by chat GPT.
M107 ; Turn off the laser
G21 ; Set units to millimeters
G91 ; Use relative positioning
G1 X3 F180 ; Move 3mm to the right at a speed of 3mm/s (180 mm/min)
G1 X-3 F180 ; Move 3mm to the left (back to the initial position) at a speed of 3mm/s

Reduce homing speed. Defaults to 3000mm/m. I set mine to 1500 mm/m on my xtool d1 pro and it stopped slamming the machine on home. I also had it move to the 1,1 position instead of 0,0 and I was able to continue jobs with near laserlike (haha) accuracy. Something about the speed.combo with the variable throw of their limit switches is bad. (Edit; just read you have no limit switches…buy some!)
Also, using chatgpt to generate code is…brave.

Id change your units to mm/m since you have a diode. 90mm/s is quite fast for the xtool and may be above physical capability for any precision.

$1=255 GRBL parameter. The steppers will stay energized.

I’m having no problems while the machine is running at that speed or even up to 110mm/s the problems are just when it is stopping

Thank you Mikey, Is there a way to add a wait period and turn the motors off? I like how the Xtool turns off the steppers after a job so you can just move the diode out of the way. how does this sound
end GCode:
$1=255; keep motors on
G4(1 second); wait a second in the right syntax
$1=0; turn the motors back off

You may try adjusting the acceleration settings under machine settings to accomodate the new heavier 20w laser head as well. Youre sort of bandaiding the machine by doing this g code ammendment instead of getting at the root of the issue in my opinion. If you havent adjusted any of this after installing the heavier unit the inertia is definitely to play a part as you mention in your initial posting.

The correct description for $1 is step idle delay in milliseconds. Max delay would be 254ms, or about 1/4 second. Would that be enough? If not, I guess your code would be workable. Bear in mind that once you move the head physically, the machine has to be re-Homed. I just use Finish Position to get the laser out of the way, something like X280 and Y20.

1 Like

I misunderstood the $1 command. It’s finals week so i haven’t had time to test the code but I think that should work for me. I’ll test it ASAP and let you know how it goes.
John, I’ve run the new diode for a couple of months and haven’t noticed any problems with the engravings. It seems only to lose home when it completes a job.
The company claims a max speed of 400mm/s which is just wrong and has no acceleration numbers. I haven’t heard any noises or losing steps at 110mm/s so I’m just going to assume that’s the limit before I start slowing down its acceleration.

Note that xTool machines do not allow for custom GRBL configuration. You won’t be allowed to make changes.

Could I not just add $1=254 to the end Gcode section inside the device settings? My understanding was it added that command to the end of the job script. I only run this machine with Lightburn

No. Values would need to be stored for them to take affect. xTool will not allow either temporary or permanent changes.

is there anything that I can do to fix my problem?

My suggestion would be to definitely prove out root cause.

Test your hypothesis that it’s the additional mass that’s indeed causing the problem.

My assumption would be that you’re simply losing steps due to the mass and speed settings that you’re using.

Your machine is not likely to depower the stepper motors immediately and in fact has a short pause before doing so.

If your hypothesis indeed proves out to be correct then you could potentially do the end-gcode script approach but I wouldn’t arbitrarily move 3 mm as you have it set now since you don’t actually know if you’re already at the limits of your movement. It may be more straightforward to go to an arbitrary absolute position somewhere safe.

I feel ya on the machine. I have an xtool D1(pro) as well. I was never able to maintain a true zero at home for a whole year…i recently fixed it by changing the homing speed settings and having it go to 1,1 instead of hittinf the limit switches in top left corner. I agree it can go fast, but being capable of speed and accuracy are two diff things I guess. You may run a quick search for d1 pro 20w acceleration settings and compare them against what is in your machine. Sadly these things require tweaking more than they ought to.

How were you able to change this?

Its under machine settings. The default value is like 3500, so I took it down to 2000. After I changed that my machine didnt sound like it got hit by a truck upon homing. That, combined with returning to a 1,1 position fixed all end of job repeatabiloty issues for me.

Were you actually able to “write” the changes back to the controller? If you now read from the controller, does it reflect the 2000?

I ask because I didn’t think it was possible to write changes to xTool controllers.

I didnt feel the need to check because it was an instant and drastic change. It gave no errors when I sent the write command and was noticably more stable upon homing. Maybe they prevent only certain values from being written?

I’ve not seen any writes be possible but I’d love for this not to be the case.

Others have indicated the same. It just silently ignores any request from what I recall, either from Machine Settings or from Console commands.

Can I ask you to explicitly double check the current settings?