Question about Adding Auto-level GCODE to Print Start Script

Please Login to Comment

Running Skynet3D 2.3.2 (based on marlin) on a Anet A8 with RAMPS 1.4 and I have a question about adding the G29 command into the print start script. I understand the auto-level must be run after the last instance of G28; Home All Axes in order to save the data after leveling. But after the G29 command, the stock "prime nozzle" command seems to close to the bed surface. Shouldn't my Firmware know where 0 is after homing / the prob offset from the extruder since it is in the firmware? Or do i need to add a G92 Z(offset here) command after the G29 command and before the prime nozzle command runs? Just wondering where i need to tweak my offset so auto-leveling from the script brings my nozzle to the proper start height. Thanks!

Thanks for all the help guys. But weirdly enough i upgraded skynet3D to the latest build 2.4.5 based on Marlin 1.1.3 and now the Gcode acts as it should. 2 successful test prints and things are looking good!

OK so there's gotta me something i'm missing....

I tired sarf2k4's code, and it seemed to work ok but i wanted to change where the prime happened so ended up with this:

G28 ; home all axes
G29 ; level bed
G1 X0 Y0;
G92 E0
G1 Z1;
G1 X10.0 Y10.0 Z0.3 F2000 ; Go to Prime Position
G1 X100.0 E20.0 F1000.0 ; prime
G1 X 110 Y110 F2000 ; Go to print area
G92 E0

Annnnnd my z-axis thinks its at 0.2 height like way up at it's safe stow height of 13.02 ( 10mm raise after autolevel and 3.02 z offset in firmware)

tried jungle's code and the z axis also floated still....

i tried to move the Z axis in my code with G1 Z1 but that didn't work. What could i be missing that is making the z axis float above the bed still?? it's like sometimes it works but minor changes seems to reset the Z position to 0 or something. You think a M851 Z13.02 command after autobed level would help since that's the height it is at after autobed level?

Sorry, I went to sleep. You're getting there. I know this can be a pressure, I myself also can be stressed especially when printing with bed elevation can vary a bit then ruins the whole surface. I try not to be stressed and ruining it but sometimes it can't be helped but the surface already ruined a little.

Following is the start g-code for a custom 3d printer that I manage

M140 S[first_layer_bed_temperature]
M104 S120
G28 X Y
M190 S[first_layer_bed_temperature]
M104 S[first_layer_temperature]
G28 ; home all axes
G92 E0
G1 X130.0 Y190.0 Z0.3 F2000 ; Go to Prime Position
M109 S[first_layer_temperature] ; wait for nozzle
G1 X40.0 E20.0 F1000.0 ; prime
G1 Y180 F2000 ; Go to print area
G92 E0

almost like junglegumninja's start gcode. Like my previous post, I do priming outside of the print area, negative or way outside the printable area.

The z axis floating, is due to g29 procedure has done doing its job and it is on the safe position to store/retract the probe. Got to issue another move command.

On Prusa mk2, they use g80, at the end of g80 the head moves to the origin at -2,-2,0.3mm. Let's not get confused with prusa mk2 firmware shall we =)

The g92 e0 line is to reset the extruder to 0th position so it won't either retract or extrude whichever you found the problem. This is necessary since the extruder current position still being saved to the cache when you cancelled the print. On the next priming, it may either extrude or retract. I had this problem before and solved after adding the g92 e0

Awesome thanks for the advice and snippet of your start script. This makes a little more sense now. I will try something along these lines after work tonight when i'm finally home. Will update with findings as usual.

Here is my g-code, I wouldn't copy paste it but I recently created it with the help of some other users here yesterday, you might be able to find the post I created in the topic log.

I found it very useful to heat the bed fully to my set temperature, and also preheat my extruder to a temperature where it would get most of the thermal expansion for the most accurate G29 but without leaking plastic out of the hot end. as soon as the g29 ends I set the actual temperature based on whatever I set in my settings for the print and wait above xy 00 till it is at temperature, then it draws a purge line.

For 215C and 65C it takes 4 minutes from room temperature to begin the purge line. The syntax [bed0_temperature] and [extruder0_temperature] are extremely useful in simplify3d.

// Gcode start

M140 S[bed0_temperature] ; set bed temp

M104 S160; begin preheating extruder temperature

M190 S[bed0_temperature] ; wait for bed temp

G28 ; home all axes

G29 ; auto billinear leveling

G4 P200; wait 0.2 seconds

G1 X0.0 Y0.0 F2000 ; return to front left corner
G1 Z20.0; Raise to 20 to wait

G4 P200; wait 0.2 seconds

M109 S[extruder0_temperature] T0 ; wait for extruder to heat before creating purge line

G1 Z0.3 F300 ; lower Z to prep for purge line
G1 X60.0 E9 F800.0 ; START PURGE LINE
G1 X100.0 E12.5 F800.0 ; FINISH PURGE LINE
// end g-code

Thanks! You and sarf2k4 definitely showed me what i probably need to tackle! The manual moving of Z from it's safe stow distance needs to be tinkered with! Will update with findings!

Proper g29 doesn't have any parameters except UBL type. I highly advice to do g28 then g29 right before laying down plastic on to the surface or moving the head close to the bed; where the gap is about lesser than 2mm between nozzle and bed surface.

The priming procedure differs to each printer and to each person's printer setup and preferences. I myself would do priming outside of the printable area and it is another set of gcodes. These priming gcodes are after g29 procedures

Ok so without changing anything but the Z offset via my LCD menu in firmware, it runs the following script:

G28 ; home all axes
G29; autolevel
G1 X0 Y0
G1 Y20 Z0.2 F3000 ; get ready to prime
G92 E0 ; reset extrusion distance
G1 X200 E20 F600 ; prime nozzle

But the Z axis is floating in air way above the bed. although i home with G28, then run G29, then move X and Y to 0, then start priming, the axis never goes down?? What could be the issue?? I know it isn't a connection issue because homing and autolevel run fine and the Z axis moves up and down. Do i need to add in a M851command with the z offset? I notice after leveling the Z carriage moves up 5mm. Do i take this into account with me M851 command and my found z offset? So Z offset in firmware + Z axis raise of 5mm = my M851 command?

I had the same issue when I first setup marlin 1.1.2. it would float away or crash depending on where it was. I ended up disabling the option where the extruder and fan disable while g29 in progress. I just noticed in my temp graphs that as soon as g29 is done temps get reset along with my movement commands back to 0,0 for a prime. once I get back to my computer I can show you my start code. It is very similar.

I also have the safe stow distsnce enabled at 5mm and that doesn't seem to be the issue.

when the probe moves up with 5mm the display should show the z height as whatever your offset is plus that 5mm.

so if your offset is -3mm, and your stow distance is 5mm, you should see 8mm z height immediately after a g28. when the print starts it will start at 0mm + whatever your first layer height is.

So yes i am running a G28 then a G29 after heating of both bed and nozzle, and before priming and start of printing. I am wondering if i need to adjust my z-offset in software, or in the script with M565 Z(offset here) after G29 as my nozzle is not starting at the proper height when it goes to start the priming function. I just learned that the G29 needs to run after the last instance of G28 so I've actually been not utilizing my auto-leveling by running it from the LCD menu and then starting a print. It seems now when I've added in the G29 the z-offset/the nozzle doesn't start where it is suppose to.

Does it mean that you nozzle is far from the bed? M565 is smoothie firmware command, not for marlin. Marlin is M851 http://reprap.org/wiki/G-code#M565:_Set_Z_probe_offset.

First I would highly advice to check whether or not your board has eeprom enabled by connecting to the board with pronterface, issure m500 to display loaded settings, try change something that isn't critical followed by m501, then m500 to see if anything changed. I assumed that the printer has come with the probe when you build it and that, the eeprom should've been enabled.

Further more unknown which marlin version your printer rus on, I can only assume it run based on 1.0.2.

Straight to the point, to adjust your z-offset, you can check them under Control>motion>z-offset. I highly suggest to adjust this after doing babystepping z during printing at tune>babystepping z. Then take the values of the babystepping z, add into the z-offset. After changing the z-offset, don't forget to save setting or store setting or store memory under Control section

I also doubt that baystepping z also enabled.

Thanks sarf2k4

No, my nozzle is too close to the bed after i run G29; through the print script. Good thing I haven't tried the M565, good to know its M851 in Marlin. I believe EEPROM should be enabled as I've never had any troubles saving things to it in the past through console commands. And i am not using a stock Z-probe, but a Mini IR height sensor on E3D Titan Aero.

I am not sure what Marlin Skynet3D 2.3.2 is based on. I can look into that.

Now one thing to note is my Z-offset is fine within firmware, somewhere around 3.04 mm above the nozzle when the probe is triggered. I have yet to try to control my printer from Simplify3D itself so i will take your advice on setting the z-offset in software from the control interface.

I am wondering if i just need to adjust my first layer height/ percentage from 100% to something like 101-105%. I am using a .4mm nozzle and printing at .2 mm layers. At the start of prints the nozzle is too close to the print so the filament isn't pushed out, but just leaves a line/scratch in my PEI bed surface. Could it be that easy? I haven't poked around too much since i just dove into this last night.

I would strongly recommend you to check your Z probe accuracy and if doing several G28 it gives you always the same results, which I doubt using an ir sensor, the temperature play a big difference in the reading, G29 command should never give you troubles, as it just memorize the delta on the bed grid, the zero level has always the priority and if is accurate should always work.

If the nozzle barely lay down the filament or scratches the surface, you really need to adjust your z-offset higher or lower depending on your marlin version. on v1.1.1, more negative will bring the nozzle lower to the bed meaning push it further down, while v1.0.2 is the opposite.

If you change the first layer height percentage, it will have problem on other printer since their initial offset differs. Please check your z-offset again. I'm pretty sure that it is off.

I advice you to print a single 0.2mm thick square with only 1 layer then measure them with vernier/digital caliper and check the thickness.

I also going to do the same shortly on my just upgraded mk2 to mk2s printer. I haven't put up the proper z-offset yet from last night's job.

Once you got the correct thickness. Do note that the printed material can stick on to the PEI sheet too well until it can rip the sheet itself. Here you need to try increase by about 25 microns or 0.025mm or lesser that works for you. You will know the ratio between easy and hard time scraping the printed thickness calibration plate of 0.2mm.

After printed one in the center, do a 9 point thickness calibration as well to check whether or not the sensor accurately probe the bed elevation. If some of the plate gives off plus/minus about 25-50 micron difference, it is still okay, but not about 100-150 microns.

A single layer test print is a great idea, which i will try tonight. My number for z-offset in firmware currently is not negative at least as far as i can see.

I did notice prior to adding auto-leveling into the script, 99-100% layer height was the best bet for being able to remove the prints. 97-98 was way too low and i had a hell of a time releasing the print. (I've learned the hard way and forcing prints off the PEI, i took a chunk out of my first PEI sheet that way a month ago, now I'm much more careful). Although I only have 1 printer so changing layer height could be a quick fix in my case, but I'll venture down the road you described.

And by a 9 point thickness calibration, you mean print test prints at 9 points across the bed? Or auto-level? I usually do a mesh bed level with 9 points across the bed. I do need to tweak each point though as it only hit 85% of my bed and such. But for what I'm printing now it's been fine.

So to recap i should:
-Adjust the z-offset (in firmware or simplify3d?)
-Do a test print of a single layer cube at .2mm thickness
-Measure and adjust z-offset from test print
-Print a 9-point test and repeat z-offset adjust

I do sarf2k4 does. Before I had an autolevel probe I did the z-offset in simplify because it would change too often depending on how tightly I leveled using feeler gauges so I'd have to adjust increments as small as 0.05mm at times. Now that I am using a bltouch probe I do it through firmware because I don't have to go through my multiple filament profiles and remember to update the z-offsets, I just leave them at 0mm and adjust my firmware settings if something ever goes wrong.

Using the 0.2mm single layer I found 0.19-0.25mm with calipers on a single most outer perimeter measurement gave me great "squish" and filled layer where the layers adhered to each other. This may differ slightly on material/temp but you will see what is best for you when you do the tes.


Go to page 5. It isn't specific to your probe but should work just the same. I have done offset firmware side so it applies to all my prints as well as well as in simplify3d under the G-code advanced settings.

Thanks junglegymninja

I have done something similar to this with my mini IR sensor when calibrating for the offset within my firmware. Would it be just as easy to add my firmware's offset value ~3.04mm to the G-code advanced settings? Or should i run this again via the PDF you sent me in the Simplify3D console to get the value, then add it into the G-code advanced settings?

I wouldn't recommend doing it in G-code advanced settings as the primary way since you have an autolevel probe. If you have to do it for one print sure, but the problem is you'd have a growing list of things to remember to change anytime you switch profiles and... what if you update your firmware for correct setting on one profile with a simplify3d advanced setting of 0mm then go back to a profile where you have -1mm offset? bye bye PEI sheet.