Bambu Lab P2S print starts after 1.5 minutes!

Just chiming in that I appreciate your efforts.

I’m a professional (metal) CNC machinist and read and write g-code from scratch.

The amount of arbitrary and undocumented 3DP g-code is bafflingly.

I worked through a P1S machine start for a few days and have it down to something pretty fast. But the P2S is on another planet of annoyance.

2 Likes

More minor but useful modifications :slight_smile: I noticed that during the first print after startup, the first layer was almost always unsatisfactory; however, when I preheated the bed, it improved. So, I added a delay before Z-axis homing to let thermal expansion do its thing. This extends the start slightly, but it is still shorter than the original factory G-code. Of course, this time can be modified if someone wants to experiment. Furthermore, my version does not consume kilometers of filament (purging old, loading new, etc.), using it only for the needs of the optional calibration.

I also made a list of the first 60 codes displayed by the P2S using the “M1002 gcode_claim_action : x” command (useful for those who like modifications and tinkering with G-code). If there is interest, I will publish it. The ones available online often have discrepancies.

;======== P2S quick start printing GCODE (V7.3) ==========
;
; Author of the modification: SylwekK
;
; G-code start sequence tested with a non-AMS printer
; Quick start: Printing begins around 2 minutes after selecting the model
; The printer does not purge filament unnecessarily as it does during a filament change.
; Features: Optional flow calibration and bed leveling active
; Verified and tested but use at your own responsibility
;

M140 S[bed_temperature_initial_layer_single] ; Heat heatbed first (Code 2)
M993 A0 B0 C0
M17
M620 M
G389

;===== Initial safety Z-axis drop =====
G91 ; Relative positioning
G1 Z10 F1200
G90 ; Absolute positioning

;===== Reset machine status =================
M204 S10000
M630 S0 P1
G90
M17 D
M220 S100
M1002 set_gcode_claim_speed_level: 5
G29.1 Z{+0.0}
M983.1 M1
M982.2 S1
M983.4 S0
;===== Reset machine status =================

;==== Heating to 140C and XY homing ====
M1002 gcode_claim_action : 13 ; Status: Homing (XYZ Homing)
M104 S140 A
G28 X T300 ; Home XY
G29.2 S0

;===== Filament sensor arming =====
M620 S[initial_no_support_extruder]A
T[initial_no_support_extruder]
M621 S[initial_no_support_extruder]A
G389

;===== Heatbed Thermal Stabilization (Soak) =====
M1002 gcode_claim_action : 58 ; Status: Temperature equalization for optimization

{if filament_type[initial_no_support_extruder] == “PLA”}
G4 S20 ; Wait 20s for PLA bed stability
{else}
G4 S45 ; Wait 45s for high-temp materials (PETG/ABS/ASA)
{endif}

;===== Nozzle cleaning at 140C =====
M1002 gcode_claim_action : 14 ; Status: Cleaning nozzle tip
G150.3
M109 S140 A
G150.1 F8000 ; Wipe
G150.1 F8000 ; Wipe repeat
M400

;===== Z homing =====
G1 X128 Y128 F30000 ; Move to bed center
M1002 gcode_claim_action : 13 ; Status: Homing (Z-axis Homing)
G28 Z P0 T400
M400

;===== Optional Auto Bed Leveling (ABL) =====
M1002 judge_flag g29_before_print_flag
M622 J1
M1002 gcode_claim_action : 1 ; Status: Auto Bed Leveling
M190 S[bed_temperature_initial_layer_single]
M109 S140 A
G29 A1 X{first_layer_print_min[0]} Y{first_layer_print_min[1]} I{first_layer_print_size[0]} J{first_layer_print_size[1]}
M400
M500 ; Save calibration data
G1 Z10 F1200
M623

;===== Mech mode resonance sweep =====
M1002 gcode_claim_action : 3 ; Status: Vibration Compensation
G90
G1 X128 Y128 F20000
G1 Z5 F1200
M400 P200
M970.3 Q1 A5 K0 O1
M970.2 Q1 K1 W74 Z0.01
M974 Q1 S2 P0
M970.3 Q0 A7 K0 O1
M970.2 Q0 K1 W74 Z0.01
M974 Q0 S2 P0
M400

;===== Optional Flow calibration =====
M975 S1
M1002 judge_flag extrude_cali_flag
M622 J1
M1002 gcode_claim_action : 8 ; Status: Extrusion Calibration
G150.3
M109 S[nozzle_temperature_initial_layer]
G4 S20 ; Nozzle pressure stabilization pause

M211 X0 Y0 Z0 ; Disable soft endstops
M975 S1 ; Enable Input Shaping
G29.2 S0

{if ((filament_type[initial_no_support_extruder] == “PLA”) || (filament_type[initial_no_support_extruder] == “PLA-CF”) || (filament_type[initial_no_support_extruder] == “PETG”)) && (nozzle_diameter[initial_no_support_extruder] == 0.2)}
M620.10 A0 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{else}
M620.10 A0 F{flush_volumetric_speeds[initial_no_support_extruder]/2.405360} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053
60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{endif}

M620.11 P0 L0 I[initial_no_support_extruder] E0
M620.11 K0 I[initial_no_support_extruder] R0
M620 S[initial_no_support_extruder]A
M1002 set_filament_type:UNKNOWN
M400
T[initial_no_support_extruder]
M400
M628 S0
M400
M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
M621 S[initial_no_support_extruder]A
G29.2 S1
G90
M83
M400
M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; Flow calibration pattern
M400
M106 P1 S255 ; Parts cooling fan for calibration
M400 S5
M106 P1 S0
G150.3
M623

;===== Final heating before printing ==========
G150.3
M1002 gcode_claim_action : 7 ; Status: Nozzle heating
M190 S[bed_temperature_initial_layer_single]
M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}
M400

;===== Double filament cut and nozzle wipe =====
M629
M400 P200
M629
M400 P200
G150.1 F8000
M211 S1 ; Enable soft endstops
G29.2 S1 ; Enable ABL compensation
M400

;===== Z-OFFSET correction (Bed type dependent) =====
{if curr_bed_type==“Textured PEI Plate”}
G29.1 Z{0.01}
{else}
G29.1 Z{0.03}
{endif}

;===== Purge line start =====
M975 S1
M1002 gcode_claim_action : 51 ; Status: Printing calibration lines
G90
M83
G0 X100 Y0 F24000
G130 O0 X100 Y-0.2 Z0.6 F{filament_max_volumetric_speed[initial_no_support_extruder]/2/2.4053} L40 E12 D4
G1 Z0.5
M400

;===== Activate all safety sensors =====
M1015.3 S1 H[nozzle_diameter]
M1015.4 S1 K1 H[nozzle_diameter]
M620.6 I[initial_no_support_extruder] W1

M1002 gcode_claim_action : 0 ; Status: Printing (Clear status)
G29.99

;— Load Cell Sensitivity & Monitoring —
M1010 Q0 B0.023 S0.01
M1010 Q1 B0.005 S0.01
M1010.1 S1

;======== END GCODE ==========

i have not been able to use your gcode yet. it always gives me an error.

Oh, I admit I haven’t checked with PLA material, but the compilation itself runs without any problems for me. No matter, just replace the fragment:

;===== Heatbed Thermal Stabilization (Soak) =====
M1002 gcode_claim_action : 58 ; Status: Temperature equalization for optimization

{if filament_type[initial_no_support_extruder] == “PLA”}
G4 S20 ; Wait 20s for PLA bed stability
{else}
G4 S45 ; Wait 45s for high-temp materials (PETG/ABS/ASA)
{endif}

with:

;===== Heatbed Thermal Stabilization (Soak) =====
M1002 gcode_claim_action : 58 ; Status: Temperature equalization for optimization

G4 S45 ; Wait 45s

Actually i currently don’t even print with PLA, mainly petg hf. It could be that there’s a pla filament in the project file, I don’t remember right now.

I open the printer settings, go to the machine code, swap the start code, save it and try to slice. That’s when the error pops up.

Ok, I think everything is clear now. The way the text is interpreted has an effect here. I copied my code from the forum and, after substituting it, the same error appeared, even though nothing in the code had changed. I will try to put it in tags; that should help.

;======== P2S quick start printing GCODE (V7.3) ==========
;
; Author of the modification: SylwekK
;
; G-code start sequence tested with a non-AMS printer
; Quick start: Printing begins around 2 minutes after selecting the model
; The printer does not purge filament unnecessarily as it does during a filament change.
; Features: Optional flow calibration and bed leveling active
; Verified and tested but use at your own responsibility
;

M140 S[bed_temperature_initial_layer_single] ; Heat heatbed first (Code 2)
M993 A0 B0 C0 
M17 
M620 M 
G389 

;===== Initial safety Z-axis drop =====
G91 ; Relative positioning
G1 Z10 F1200 
G90 ; Absolute positioning

;===== Reset machine status =================
M204 S10000
M630 S0 P1
G90
M17 D 
M220 S100 
M1002 set_gcode_claim_speed_level: 5
G29.1 Z{+0.0} 
M983.1 M1
M982.2 S1 
M983.4 S0
;===== Reset machine status =================

;==== Heating to 140C and XY homing ====
M1002 gcode_claim_action : 13 ; Status: Homing (XYZ Homing)
M104 S140 A 
G28 X T300 ; Home XY
G29.2 S0 

;===== Filament sensor arming =====
M620 S[initial_no_support_extruder]A 
T[initial_no_support_extruder]
M621 S[initial_no_support_extruder]A 
G389 

;===== Heatbed Thermal Stabilization (Soak) =====
M1002 gcode_claim_action : 58 ; Status: Temperature equalization for optimization

{if filament_type[initial_no_support_extruder] == "PLA"}
  G4 S20 ; Wait 20s for PLA bed stability
{else}
  G4 S45 ; Wait 45s for high-temp materials (PETG/ABS/ASA)
{endif}

;===== Nozzle cleaning at 140C =====
M1002 gcode_claim_action : 14 ; Status: Cleaning nozzle tip
G150.3 
M109 S140 A 
G150.1 F8000 ; Wipe
G150.1 F8000 ; Wipe repeat
M400

;===== Z homing =====
G1 X128 Y128 F30000 ; Move to bed center
M1002 gcode_claim_action : 13 ; Status: Homing (Z-axis Homing)
G28 Z P0 T400 
M400

;===== Optional Auto Bed Leveling (ABL) =====
M1002 judge_flag g29_before_print_flag
M622 J1
    M1002 gcode_claim_action : 1 ; Status: Auto Bed Leveling
    M190 S[bed_temperature_initial_layer_single] 
    M109 S140 A 
    G29 A1 X{first_layer_print_min[0]} Y{first_layer_print_min[1]} I{first_layer_print_size[0]} J{first_layer_print_size[1]}
    M400
    M500 ; Save calibration data
    G1 Z10 F1200 
M623

;===== Mech mode resonance sweep =====
M1002 gcode_claim_action : 3 ; Status: Vibration Compensation
G90 
G1 X128 Y128 F20000 
G1 Z5 F1200 
M400 P200 
M970.3 Q1 A5 K0 O1 
M970.2 Q1 K1 W74 Z0.01 
M974 Q1 S2 P0 
M970.3 Q0 A7 K0 O1 
M970.2 Q0 K1 W74 Z0.01 
M974 Q0 S2 P0 
M400 

;===== Optional Flow calibration =====
M975 S1
M1002 judge_flag extrude_cali_flag
M622 J1
  M1002 gcode_claim_action : 8 ; Status: Extrusion Calibration
  G150.3 
  M109 S[nozzle_temperature_initial_layer] 
  G4 S20 ; Nozzle pressure stabilization pause
  
  M211 X0 Y0 Z0 ; Disable soft endstops
  M975 S1 ; Enable Input Shaping
  G29.2 S0 
  
  {if ((filament_type[initial_no_support_extruder] == "PLA") || (filament_type[initial_no_support_extruder] == "PLA-CF") || (filament_type[initial_no_support_extruder] == "PETG")) && (nozzle_diameter[initial_no_support_extruder] == 0.2)}
    M620.10 A0 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
    M620.10 A1 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
  {else}
    M620.10 A0 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
    M620.10 A1 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
  {endif}
  
  M620.11 P0 L0 I[initial_no_support_extruder] E0
  M620.11 K0 I[initial_no_support_extruder] R0
  M620 S[initial_no_support_extruder]A 
  M1002 set_filament_type:UNKNOWN
  M400
  T[initial_no_support_extruder]
  M400
  M628 S0
  M400
  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M621 S[initial_no_support_extruder]A
  G29.2 S1
  G90
  M83
  M400 
  M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; Flow calibration pattern
  M400
  M106 P1 S255 ; Parts cooling fan for calibration
  M400 S5
  M106 P1 S0
  G150.3
M623

;===== Final heating before printing ==========
G150.3 
M1002 gcode_claim_action : 7 ; Status: Nozzle heating
M190 S[bed_temperature_initial_layer_single] 
M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]} 
M400

;===== Double filament cut and nozzle wipe =====
M629 
M400 P200
M629 
M400 P200
G150.1 F8000 
M211 S1 ; Enable soft endstops
G29.2 S1 ; Enable ABL compensation
M400

;===== Z-OFFSET correction (Bed type dependent) =====
{if curr_bed_type=="Textured PEI Plate"}
  G29.1 Z{0.01} 
{else}
  G29.1 Z{0.03} 
{endif}

;===== Purge line start =====
M975 S1 
M1002 gcode_claim_action : 51 ; Status: Printing calibration lines
G90
M83
G0 X100 Y0 F24000 
G130 O0 X100 Y-0.2 Z0.6 F{filament_max_volumetric_speed[initial_no_support_extruder]/2/2.4053} L40 E12 D4
G1 Z0.5
M400

;===== Activate all safety sensors =====
M1015.3 S1 H[nozzle_diameter] 
M1015.4 S1 K1 H[nozzle_diameter] 
M620.6 I[initial_no_support_extruder] W1 

M1002 gcode_claim_action : 0 ; Status: Printing (Clear status)
G29.99 

;--- Load Cell Sensitivity & Monitoring ---
M1010 Q0 B0.023 S0.01
M1010 Q1 B0.005 S0.01
M1010.1 S1

;======== END GCODE ==========

Edit:
I no longer get the error after copying the above, so the forum text formatting was changing something for the worse; it’s okay now :slight_smile:

Edit2:

I am still looking for a way to bypass this 45s wait when printing several items one after another. The bed is usually already warmed up then and does not need this delay. You can, of course, go into the G-code and change, for example, G4 S45 to G4 S1, but it would be cool to automate this :slight_smile:

this works good for me but i did encounter a problem. I was running a print it auto stopped (out of filament) when i reloaded the filament it would not stop purging after a long while i needed to kill the power to get it to stop. i was able to continue the print after powering back on with no problem. This has never happed before i used your start gcode. could be a fluke but wanted to let you know so you can test and update if needed.

1 Like

Fantastic. I came from creality and also felt my new p2s was taking forever to get started. New code should help a lot.

Thank you

1 Like

Thank you very much for the heads-up, this is exactly the kind of situation I mean. Some things I’m unable to test on the fly, and they only surface during normal use. I’ll take a closer look at it; I probably skipped some initialization command during the optimization.

There’s a new issue I’ve run into: after doing a manual pause, the printer won’t stop trying to purge when the print resumes. Once the extruder reheats and the print starts again, it begins purging and doesn’t stop.

Aside from the few problems I’ve encountered so far, it’s working great overall. I really like not having the “poop” purge at the start of a print. Since I don’t have an AMS, there’s no need to purge every time anyway. (sorry i used chatgpt to make it sound better)

Sorry new issue the printer auto stopped for extruder pressure problem i clicked problem fixed the purge started again i chose the cancel print the print did cancel but the purge was still going i needed to power the printer off to get the purge to stop.

I spent several hours on analysis and testing, changing the order of various commands, and still nothing. I decided to modify the whole thing again from scratch. You won’t believe it… the issue with the filament oozing when refilling after a roll runs out was the lack of the startup melody code(!), which I don’t play because it’s annoying and I disabled it immediately in the printer menu. Currently, the code works correctly and no longer oozes filament after refilling when it runs out during a print. Additionally, the code structure will likely work even with AMS, provided that in the END G-code section, we comment out the code (about 10 lines of the program): “T65535” => “;T65535” (without quotes, of course). This line is likely responsible for retracting the filament; alternatively, you could do the same with the next one, which is “G150.2” => “;G150.2”. Unfortunately, I have no way to test and confirm this. It should work as long as the same AMS slot is used for the next print.

As a side note: The print starts after about 1:35 min if no calibrations are active, whereas with flow calibration enabled (recommended at least for the first print), the time increases to 2:20 min.

;======== P2S quick start printing GCODE (V7.4) ==========
;
; Author of the modification: SylwekK
; Verified and tested but use at your own responsibility
;

M140 S[bed_temperature_initial_layer_single] ; Heat heatbed first (Code 2)
M993 A0 B0 C0 
M17 


;=====printer start sound ===================
M17
M400 S1
M1006 S1
M1006 A53 B9 L50 C53 D9 M50 E53 F9 N50 
M1006 A56 B9 L50 C56 D9 M50 E56 F9 N50 
M1006 A61 B9 L50 C61 D9 M50 E61 F9 N50 
M1006 A53 B9 L50 C53 D9 M50 E53 F9 N50 
M1006 A56 B9 L50 C56 D9 M50 E56 F9 N50 
M1006 A61 B18 L50 C61 D18 M50 E61 F18 N50 
M1006 W
;=====printer start sound ===================


M620 M ;enable remap
G389 

;===== avoid end stop =================
  G91
  G380 S2 Z10 F1200
  G380 S2 Z-5 F1200
  G90

;===== reset machine status =================
M204 S10000
M630 S0 P1
G90
M17 D ; reset motor current to default
M960 S5 P1 ; turn on logo lamp
G90
M220 S100 ; Reset Feedrate
M1002 set_gcode_claim_speed_level: 5
M221 S100 ;Reset Flowrate
M73.2   R1.0 ;Reset left time magnitude
G29.1 Z{+0.0} ; clear z-trim value first
M983.1 M1
M982.2 S1 ; turn on cog noise reduction
M983.4 S0

;==== set airduct mode ==== 
;==== if Chamber Cooling is necessary ====
{if (overall_chamber_temperature >= 40)}
M145 P1 ; set airduct mode to heating mode for heating
M106 P2 S255 ; turn on filter fan
{else}
{if (min_vitrification_temperature <= 50)}
M145 P0 ; set airduct mode to cooling mode for cooling
M106 P2 S255 ; turn on auxiliary fan for cooling
M106 P3 S127 ; turn on chamber fan for cooling
M1002 gcode_claim_action : 29
M191 S0 ; wait for chamber temp
M106 P2 S102 ; turn on chamber cooling fan
M106 P10 S0 ; turn off left aux fan
M142 P6 R30 S40 U0.3 V0.8 ; set PETG exhaust chamber autocooling
{else}
M145 P1 ; set airduct mode to heating mode for heating
M106 P2 S127 ; turn on 50% filter fan
M142 P6 R30 S40 U0.3 V0.8 ; set PLA/TPU exhaust chamber autocooling
{endif}
{endif}

;==== heating to 140C and XY homing ====
M1002 gcode_claim_action : 13
M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
M104 S140 A 
G29.2 S0 ; avoid invalid abl data
G28 X T300 ; homing XY
G150.3

;===== Filament sensor arming =====
M620 S[initial_no_support_extruder]A 
T[initial_no_support_extruder]
M621 S[initial_no_support_extruder]A 
G389 ; collision detection

;===== Nozzle cleaning at 140C =====
M1002 gcode_claim_action : 14 ; Status: Cleaning nozzle tip
G150.3 
M109 S140 A ; wait for 140C target to soften residue
G150.1 F8000 ; Wipe
G150.1 F8000 ; Wipe repeat
M400

;===== Z homing =====
M1002 gcode_claim_action : 13 ; Status: Homing (Z-axis Homing)
;  G150.3
  M972 S24 P0
  M972 S26 P0 C0
  M972 S42 P0 T5000
;  G150.1 F8000 ; wipe mouth to avoid filament stick to heatbed
  G90
  G1 X128 Y128 F20000
  G28 Z P0 T400
  M400

;===== Mech mode resonance sweep check =======
  M1002 gcode_claim_action : 3 ; Status: Vibration Compensation
  G90 
;  G1 X128 Y128 F20000 
  G1 Z5 F1200 
  M400 P200 
  M970.3 Q1 A5 K0 O1 
  M970.2 Q1 K1 W74 Z0.01 
  M974 Q1 S2 P0 
  M970.3 Q0 A7 K0 O1 
  M970.2 Q0 K1 W74 Z0.01 
  M974 Q0 S2 P0 
  M400

  M150.3

;===== detection start =====
  M1002 gcode_claim_action : 11
  M104 S{nozzle_temperature_initial_layer[initial_no_support_extruder]-80} A ; rise temp in advance
  M972 S19 P0 T5000 ;plate type detection

;=====
  M211 X0 Y0 Z0 ;turn off soft endstop
  M975 S1 ; turn on input shaping
  
  G29.2 S0 ; avoid invalid abl data

;===== Optional Auto Bed Leveling (ABL) =====
M1002 judge_flag g29_before_print_flag
M622 J1
    M1002 gcode_claim_action : 1 ; Status: Auto Bed Leveling
    M190 S[bed_temperature_initial_layer_single] 
    M109 S140 A
    M106 S0 ; turn off fan , too noisy
    {if hold_chamber_temp_for_flat_print}
      G29 H
    {else}
      G29 A1 X{first_layer_print_min[0]} Y{first_layer_print_min[1]} I{first_layer_print_size[0]} J{first_layer_print_size[1]}
    {endif}
    M400
    M500 ; save cali data
    G90
    G1 X128 Y128 F20000
    G29.2 S1 ; Enable ABL compensation
    G28 Z P0 T400
    G1 Z10 F1200 
M623

M622 J2
    M1002 gcode_claim_action : 1 ; Status: Auto Bed Leveling
    M190 S[bed_temperature_initial_layer_single] 
    M109 S140 A
    M106 S0 ; turn off fan , too noisy
    {if hold_chamber_temp_for_flat_print}
      G29 H
    {else}
      G29 A1 X{first_layer_print_min[0]} Y{first_layer_print_min[1]} I{first_layer_print_size[0]} J{first_layer_print_size[1]}
    {endif}
    M400
    M500 ; save cali data
    G90
    G1 X128 Y128 F20000
    G29.2 S1 ; Enable ABL compensation
    G28 Z P0 T400
    G1 Z10 F1200 
M623

;===== Optional Flow calibration =====
M1002 judge_flag extrude_cali_flag
M622 J0
  M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; cali dynamic extrusion compensation
M623

M622 J1
  M1002 gcode_claim_action : 8 ; Status: Extrusion Calibration
  
{if ((filament_type[initial_no_support_extruder] == "PLA") || (filament_type[initial_no_support_extruder] == "PLA-CF") || (filament_type[initial_no_support_extruder] == "PETG")) && (nozzle_diameter[initial_no_support_extruder] == 0.2)}
M620.10 A0 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{else}
M620.10 A0 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{endif}
  
  M620.11 P0 L0 I[initial_no_support_extruder] E0
  M620.11 K0 I[initial_no_support_extruder] R0

  M620 S[initial_no_support_extruder]A ; switch material if AMS exist
  M1002 gcode_claim_action : 4
  M1002 set_filament_type:UNKNOWN
  M400
  T[initial_no_support_extruder]
  M400
  M628 S0
  M629
  M400
  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M621 S[initial_no_support_extruder]A
  M104 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}
  M400
  M106 P1 S0
  M400
  G29.2 S1

  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M109 S{nozzle_temperature[initial_no_support_extruder]}
  G90
  M83
  M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; Flow calibration pattern
  M400
  M106 P1 S255
  M400 S5
  M106 P1 S0
  G150.3
M623

M622 J2
  M1002 gcode_claim_action : 8 ; Status: Extrusion Calibration
  
{if ((filament_type[initial_no_support_extruder] == "PLA") || (filament_type[initial_no_support_extruder] == "PLA-CF") || (filament_type[initial_no_support_extruder] == "PETG")) && (nozzle_diameter[initial_no_support_extruder] == 0.2)}
M620.10 A0 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{else}
M620.10 A0 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{endif}
  
  M620.11 P0 L0 I[initial_no_support_extruder] E0
  M620.11 K0 I[initial_no_support_extruder] R0

  M620 S[initial_no_support_extruder]A ; switch material if AMS exist
  M1002 gcode_claim_action : 4
  M1002 set_filament_type:UNKNOWN
  M400
  T[initial_no_support_extruder]
  M400
  M628 S0
  M629
  M400
  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M621 S[initial_no_support_extruder]A
  M104 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}
  M400
  M106 P1 S0
  M400
  G29.2 S1

  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M109 S{nozzle_temperature[initial_no_support_extruder]}
  G90
  M83
  M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; Flow calibration pattern
  M400
  M106 P1 S255
  M400 S5
  M106 P1 S0
  G150.3
  M400
M623

;=====
  {if hold_chamber_temp_for_flat_print}
    M1002 gcode_claim_action : 58
    M104 S{first_layer_temperature[initial_no_support_extruder]}
    {if bed_temperature_initial_layer_single > 89}
        M1030 S1800      
    {else}
        M1030 S300
    {endif}
    M1030 C
  {endif}

  {if filament_type[current_extruder] == "TPU" || filament_type[current_extruder] == "PVA"}
  {else}
    M83
    G1 E-3 F1800
    M400 P500
  {endif}

  G150.2
  G150.1 F8000

  G91
  G1 Y-16 F12000 ; move away from the trash bin
  G90
  M400

;=====
  M985.1 U0 E2
  M985.1 U1 E2

;========turn off light and fans =============
  M960 S1 P0 ; turn off laser
  M960 S2 P0 ; turn off laser
  M106 S0 ; turn off cooling fan

;===== Final heating before printing ==========
M1002 gcode_claim_action : 7 ; Status: Nozzle heating
M104 S[nozzle_temperature_initial_layer] A
G150.3 
M190 S[bed_temperature_initial_layer_single] 
M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]} 
M400

;===== wait temperature reaching the reference value =======

  M1002 gcode_claim_action : 255
  M400
  M975 S1 ; turn on mech mode supression

;============switch again==================
  M211 X0 Y0 Z0 ;turn off soft endstop
  G91
  G1 Z6 F1200
  G90
  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M620 S[initial_no_support_extruder]A
  M400
  T[initial_no_support_extruder]
  M400
  M628 S0
  M629
  M400

  M621 S[initial_no_support_extruder]A

;===== Z-OFFSET correction (Bed type dependent) =====
{if curr_bed_type=="Textured PEI Plate"}
  G29.1 Z{0.01} ; for Textured PEI Plate 
{else}
  G29.1 Z{0.03} 
{endif}

;===== nozzle load line ===============================
M1002 gcode_claim_action : 51 ; Status: Printing calibration lines
  G29.2 S1 ; ensure z comp turn on
  G90
  M83
  M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}

  G150.1 F8000 
  M400

  G0 X100 Y0 F24000
  M400
  ;G130 O0 X100 Y-0.4 Z0.8 F{filament_max_volumetric_speed[initial_no_support_extruder]/2/2.4053} L40 E20 D5
  G130 O0 X100 Y-0.2 Z0.6 F{filament_max_volumetric_speed[initial_no_support_extruder]/2/2.4053} L40 E12 D4
  G90
  M83
  G1 Z0.5
  M400

;===== Activate all safety sensors =====
M1002 gcode_claim_action : 0
  G29.99

{if (filament_type[initial_no_support_extruder] == "TPU") || 
(filament_type[initial_no_support_extruder] == "PLA") ||  (filament_type[initial_no_support_extruder] == "PETG")}
M1015.3 S1 H[nozzle_diameter];enable tpu, pla and petg clog detect
{else}
M1015.3 S0;disable clog detect
{endif}

{if (filament_type[initial_no_support_extruder] == "PLA") ||  (filament_type[initial_no_support_extruder] == "PETG")
 ||  (filament_type[initial_no_support_extruder] == "PLA-CF")  ||  (filament_type[initial_no_support_extruder] == "PETG-CF")}
M1015.4 S1 K1 H[nozzle_diameter] ;enable E air printing detect
{else}
M1015.4 S0 K0 H[nozzle_diameter] ;disable E air printing detect
{endif}

M620.6 I[initial_no_support_extruder] W1 ;enable ams air printing detect

M1010 Q0 B0.023 S0.01
M1010 Q1 B0.005 S0.01
M1010.1 S1


;======== END GCODE ==========
2 Likes

Thank you for your work with this code, it is much appreciated.

I have made a few simple changes in to adapt my AMS2 Pro setup so that I can select a colour from the four available in the AMS during the process to send the file to the printer, then the AMS acts normally in unloading/loading that colour. I have not tried a multi-colour print, this code is for fast repeats of simple PLA one colour projects. More complex projects I will just run the default full code.

I have set the bed at 55, the nozzle warm up at 140 and the nozzle print at 210 in the gcode. It also does one quick extrusion of 30mm to clear the nozzle before printing. Total time about 80 seconds. Switching between filament colours I could just use a profile with gcode setting a longer purge length before returning the next print to the 30mm purge setting. Simple.

2 Likes

Привет!! Я заценил твой код, красавчик. Можно в него внести протирку сопла об металическую пластину на столе перед колибровкой? Как на стандартном коде. У меня без этой протирки на сопле остается висеть пластик, и он потом мешает калибровке стола. Я печатаю педжем. В целом твой код понравился. Он уже расходится по сети как чума )) спасибо тебе.

I added nozzle tip cleaning for cases where bed leveling is active, although frankly, I haven’t noticed any significant difference myself when printing with PETG.

;======== P2S quick start printing GCODE (V7.5.1) ==========
;
; Author of the modification: SylwekK
; Verified and tested but use at your own responsibility
;

M140 S[bed_temperature_initial_layer_single] ; Heat heatbed first (Code 2)
M993 A0 B0 C0 
M17 


;=====printer start sound ===================
M17
M400 S1
M1006 S1
M1006 A53 B9 L50 C53 D9 M50 E53 F9 N50 
M1006 A56 B9 L50 C56 D9 M50 E56 F9 N50 
M1006 A61 B9 L50 C61 D9 M50 E61 F9 N50 
M1006 A53 B9 L50 C53 D9 M50 E53 F9 N50 
M1006 A56 B9 L50 C56 D9 M50 E56 F9 N50 
M1006 A61 B18 L50 C61 D18 M50 E61 F18 N50 
M1006 W
;=====printer start sound ===================

M620 M ;enable remap
G389 

;===== avoid end stop =================
  G91
  G380 S2 Z10 F1200
  G380 S2 Z-5 F1200
  G90

;===== reset machine status =================
M204 S10000
M630 S0 P1
G90
M17 D ; reset motor current to default
M960 S5 P1 ; turn on logo lamp
G90
M220 S100 ; Reset Feedrate
M1002 set_gcode_claim_speed_level: 5
M221 S100 ;Reset Flowrate
M73.2   R1.0 ;Reset left time magnitude
G29.1 Z{+0.0} ; clear z-trim value first
M983.1 M1
M982.2 S1 ; turn on cog noise reduction
M983.4 S0

;==== set airduct mode ==== 
;==== if Chamber Cooling is necessary ====
{if (overall_chamber_temperature >= 40)}
M145 P1 ; set airduct mode to heating mode for heating
M106 P2 S255 ; turn on filter fan
{else}
{if (min_vitrification_temperature <= 50)}
M145 P0 ; set airduct mode to cooling mode for cooling
M106 P2 S255 ; turn on auxiliary fan for cooling
M106 P3 S127 ; turn on chamber fan for cooling
M1002 gcode_claim_action : 29
M191 S0 ; wait for chamber temp
M106 P2 S102 ; turn on chamber cooling fan
M106 P10 S0 ; turn off left aux fan
M142 P6 R30 S40 U0.3 V0.8 ; set PETG exhaust chamber autocooling
{else}
M145 P1 ; set airduct mode to heating mode for heating
M106 P2 S127 ; turn on 50% filter fan
M142 P6 R30 S40 U0.3 V0.8 ; set PLA/TPU exhaust chamber autocooling
{endif}
{endif}

;==== heating to 140C and XY homing ====
M1002 gcode_claim_action : 2
M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
M104 S140 A 
G29.2 S0 ; avoid invalid abl data
G28 X T300 ; homing XY
G150.3

;===== Filament sensor arming =====
M620 S[initial_no_support_extruder]A 
T[initial_no_support_extruder]
M621 S[initial_no_support_extruder]A 
G389 ; collision detection

;===== Nozzle cleaning at 140C =====
M1002 gcode_claim_action : 14 ; Status: Cleaning nozzle tip
G150.3 
M109 S140 A ; wait for 140C target to soften residue
G150.1 F8000 ; Wipe
G150.1 F8000 ; Wipe repeat
M400

;===== Z homing =====
M1002 gcode_claim_action : 13 ; Status: Homing (Z-axis Homing)
  G90
  G1 X128 Y128 F20000
  G28 Z P0 T400
  M400

;===== Mech mode resonance sweep check =======
  M1002 gcode_claim_action : 3 ; Status: Vibration Compensation
  G90 
;  G1 X128 Y128 F20000 
  G1 Z5 F1200 
  M400 P200 
  M970.3 Q1 A5 K0 O1 
  M970.2 Q1 K1 W74 Z0.01 
  M974 Q1 S2 P0 
  M970.3 Q0 A7 K0 O1 
  M970.2 Q0 K1 W74 Z0.01 
  M974 Q0 S2 P0 
  M400

;===== detection start =====
  M1002 gcode_claim_action : 11
  M104 S{nozzle_temperature_initial_layer[initial_no_support_extruder]-80} A ; rise temp in advance
  M972 S19 P0 T5000 ;plate type detection

;=====
  M211 X0 Y0 Z0 ;turn off soft endstop
  M975 S1 ; turn on input shaping
  
  G29.2 S0 ; avoid invalid abl data

;===== Optional Auto Bed Leveling (ABL) =====
M1002 judge_flag g29_before_print_flag
M622 J1

;   == wipe right nozzle start =====
G150.3
M400
  M1002 gcode_claim_action : 14
  G150 T{nozzle_temperature_initial_layer[initial_no_support_extruder]}
  M400
 
{if filament_type[current_extruder] == "PC"}
  M109 S170 A
{else}
  M109 S140 A
{endif}
  G91
  G1 Z5 F1200
  G90
  M400
  G150.1
;   === wipe left nozzle end =====

G150.3
M400
    M1002 gcode_claim_action : 1 ; Status: Auto Bed Leveling
    M190 S[bed_temperature_initial_layer_single] 
    M109 S140 A
    M106 S0 ; turn off fan , too noisy
    {if hold_chamber_temp_for_flat_print}
      G29 H
    {else}
      G29 A1 X{first_layer_print_min[0]} Y{first_layer_print_min[1]} I{first_layer_print_size[0]} J{first_layer_print_size[1]}
    {endif}
    M400
    M500 ; save cali data
    G90
    G1 X128 Y128 F20000
    G29.2 S1 ; Enable ABL compensation
    G28 Z P0 T400
    G1 Z10 F1200 
M623

;===== Optional Flow calibration =====
G150.3
M1002 judge_flag extrude_cali_flag
M622 J0
  M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; cali dynamic extrusion compensation
M623

M622 J1
  M1002 gcode_claim_action : 8 ; Status: Extrusion Calibration
  
{if ((filament_type[initial_no_support_extruder] == "PLA") || (filament_type[initial_no_support_extruder] == "PLA-CF") || (filament_type[initial_no_support_extruder] == "PETG")) && (nozzle_diameter[initial_no_support_extruder] == 0.2)}
M620.10 A0 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F74.8347 H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{else}
M620.10 A0 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
M620.10 A1 F{flush_volumetric_speeds[initial_no_support_extruder]/2.4053*60} H{nozzle_diameter[initial_no_support_extruder]} T{flush_temperatures[initial_no_support_extruder]} P{nozzle_temperature_initial_layer[initial_no_support_extruder]} S1
{endif}
  
  M620.11 P0 L0 I[initial_no_support_extruder] E0
  M620.11 K0 I[initial_no_support_extruder] R0

  M620 S[initial_no_support_extruder]A ; switch material if AMS exist
  M1002 gcode_claim_action : 4
  M1002 set_filament_type:UNKNOWN
  M400
  T[initial_no_support_extruder]
  M400
  M628 S0
  M629
  M400
  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M621 S[initial_no_support_extruder]A
  M104 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}
  M400
  M106 P1 S0
  M400
  G29.2 S1

  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M109 S{nozzle_temperature[initial_no_support_extruder]}
  G90
  M83
  M983.3 F{filament_max_volumetric_speed[initial_no_support_extruder]/2.4} A0.4 ; Flow calibration pattern
  M400
  M106 P1 S255
  M400 S5
  M106 P1 S0
  G150.3
M623

;=====
  {if hold_chamber_temp_for_flat_print}
    M1002 gcode_claim_action : 58
    M104 S{first_layer_temperature[initial_no_support_extruder]}
    {if bed_temperature_initial_layer_single > 89}
        M1030 S1800      
    {else}
        M1030 S300
    {endif}
    M1030 C
  {endif}

  {if filament_type[current_extruder] == "TPU" || filament_type[current_extruder] == "PVA"}
  {else}
    M83
    G1 E-3 F1800
    M400 P500
  {endif}

  G150.2
  G150.1 F8000

  G91
  G1 Y-16 F12000 ; move away from the trash bin
  G90
  M400

;=====
  M985.1 U0 E2
  M985.1 U1 E2

;========turn off light and fans =============
  M960 S1 P0 ; turn off laser
  M960 S2 P0 ; turn off laser
  M106 S0 ; turn off cooling fan

;===== Final heating before printing ==========
M1002 gcode_claim_action : 7 ; Status: Nozzle heating
M104 S[nozzle_temperature_initial_layer] A
G150.3 
M190 S[bed_temperature_initial_layer_single] 
M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]} 
M400

;===== wait temperature reaching the reference value =======

  M1002 gcode_claim_action : 255
  M400
  M975 S1 ; turn on mech mode supression

;============switch again==================
  M211 X0 Y0 Z0 ;turn off soft endstop
  G91
  G1 Z6 F1200
  G90
  M1002 set_filament_type:{filament_type[initial_no_support_extruder]}
  M620 S[initial_no_support_extruder]A
  M400
  T[initial_no_support_extruder]
  M400
  M628 S0
  M629
  M400

  M621 S[initial_no_support_extruder]A

;===== Z-OFFSET correction (Bed type dependent) =====
{if curr_bed_type=="Textured PEI Plate"}
  G29.1 Z{0.01} ; for Textured PEI Plate (0.01 oryginal)
{else}
  G29.1 Z{0.03} 
{endif}

;===== nozzle load line ===============================

M1002 gcode_claim_action : 51 ; Status: Printing calibration lines
  G29.2 S1 ; ensure z comp turn on
  G90
  M83
  M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}

  G150.1 F8000 
  M400

  G0 X100 Y0 F24000
  M400
  ;G130 O0 X100 Y-0.4 Z0.8 F{filament_max_volumetric_speed[initial_no_support_extruder]/2/2.4053} L40 E20 D5
  G130 O0 X100 Y-0.2 Z0.6 F{filament_max_volumetric_speed[initial_no_support_extruder]/2/2.4053} L40 E12 D4
  G90
  M83
  G1 Z0.5
  M400

;===== Activate all safety sensors =====
M1002 gcode_claim_action : 0
  G29.99

{if (filament_type[initial_no_support_extruder] == "TPU") || 
(filament_type[initial_no_support_extruder] == "PLA") ||  (filament_type[initial_no_support_extruder] == "PETG")}
M1015.3 S1 H[nozzle_diameter];enable tpu, pla and petg clog detect
{else}
M1015.3 S0;disable clog detect
{endif}

{if (filament_type[initial_no_support_extruder] == "PLA") ||  (filament_type[initial_no_support_extruder] == "PETG")
 ||  (filament_type[initial_no_support_extruder] == "PLA-CF")  ||  (filament_type[initial_no_support_extruder] == "PETG-CF")}
M1015.4 S1 K1 H[nozzle_diameter] ;enable E air printing detect
{else}
M1015.4 S0 K0 H[nozzle_diameter] ;disable E air printing detect
{endif}

M620.6 I[initial_no_support_extruder] W1 ;enable ams air printing detect

M1010 Q0 B0.023 S0.01
M1010 Q1 B0.005 S0.01
M1010.1 S1


;======== END GCODE ==========
2 Likes

dzięki, działa neźle.

Thanks, works good, but if you have preloaded wrong material its not enought to clean it

you could probably use the part fan to cool the nozzle quicker when doing nozzle cleaning

Hello @SylwekK, does your preset support multi color printing? I just tried and the first attempt was the wrong filament, but it is difficult for me to say whether the ams fed the correct one, the second attempt was the correct filament, but the previous one that remained in the hotend was not reset. Maybe something wrong with my settings? Any tips on what to check?

Thx!

Thank you for this I will give this one a go, as the current one i am trying has mad no difference to the horrible Z motor barking that driving me mad :grin:

As I mentioned before, I don’t have an AMS and have no way to check and test various options, so something might not work as expected. Perhaps we should ask the creators of Bambu Lab for some minimalist AMS code that would skip some of the operations that are unnecessary from the perspective of a reasonably correct print.

1 Like