Bambu Lab X1 Specific G-Code

I work on a code for a “filament drying” feature for the P1S. This code works well

G28 X ; re-home XY
M106 P3 S180 ; set chamber fan to 70%
M190 S90 ; wait for bed temp
;M400 U1
M106 P3 S104 ; set chamber fan to 40%
G4 P360000 ; wait 360.000 ms - 5 minutes
M106 P3 S0 ; set chamber fan to 0
M107 P3 ; set chamber fan off
M140 S0 ; set bed temp off

I wanted to use M400 U1, to notify the user to insert a spool, after bed and head are relyably homed and bed is heated. When I activate this, some strange things happen:

  1. The code execution seems to stop (pause message on LCD). OK
  2. From the moment the pause message appeares, the hotend starts to heat up to 90°C, which is not part of my gcode. Why?
  3. On user input the hot end stops heating up, regardless whether 90°C are reached, or not.
  4. Though user input restarted the print process, the next command (here: set fan speed) is executed about 120 seconds after user input.

Can anybody explain this behavior?

The “P” parameter is for milliseconds. It’s better to use the “S” parameter for seconds as it keeps the parameter number smaller.

Better yet you might instead try using
M400 S300 ; (pause for 5 minutes)

Regarding playing a sound it will be interesting to see if the P series printers ever gets the Sound/Midi function that the A series has.

4 Likes

The extension board for the P1P does support a buzzer.
https://wiki.bambulab.com/en/p1/manual/extension-board-gcode-reference

Interesting and good to know but it seem the extension board is vaporware?

4 Likes

Hi mowcius,
This is the Bambu Lab Wiki Team.
May we have your permission to share your post on our Wiki? We believe it would provide valuable information to our readers, and we will attach the link to this post in our Wiki with your attribution.
Once we receive your approval, we will provide you with the link we added.

Thank you for considering our request.

Best regards,
Bambu Lab Wiki Team

Now im confused,nothing happened back then?

The post was converted to a community wiki at that time ( Regular members can edit it) It sounds like Bambu is asking to use it in the formal Bambu Wiki.

3 Likes

Hey @BambuLabWikiTeam, while I’m flattered that you’d want to put this post on your official wiki, I was rather hoping that at some point someone from the Bambu Lab team would create a wiki page to make this obsolete.

The codes that myself and others have come up with have been from investigation and trial and error, and I have a whole spreadsheet full of guesses around what certain G-code does on these printers.

By all means copy and paste the bits from the top of this forum thread that are true and make sense, but please don’t just leave it at that.

We need an official resource that lists the codes Bambu uses, how they function, and how the might differ from the codes as people would expect from looking at the Marlin pages.

As an example, here’s Prusa’s page: Prusa firmware-specific G-code commands | Prusa Knowledge Base

8 Likes

Hi mowcius,
Thank you for permitting us.
Please check it here:Wiki Page Link
Also, we appreciate your feedback and information, we will forward your request to our appropriate personnel for future Wiki content update consideration.

Best regards,
Bambu Lab Wiki Team

But there is a “HELP”. at the top of the status bar

Hold on a second, aren’t the community doing this whole thread because we don’t have access to check the code to see which specific G-codes are enabled? Why don’t you just talk to the printer team and list literally every single G-code that is enabled and specific to the printer, and save us a whole bunch of time?

4 Likes

I and others reported this user as spam.

Hi asdfgasdfg1, thanks for this feedback. We will forward your request to our appropriate personnel for future Wiki content update consideration.

1 Like

Hey, whats actually turning on the light inside the printer?
Its not like in “stock” marlin Firmwares / M355 Case Light Control | Marlin Firmware
At least, i found a way to turn off the toolhead on the X1:

M960 S5 P0 ; turn off logo lamp

Thats an interesting comment in the “machine start G-Code”:

;========turn off light and wait extrude temperature =============
M1002 gcode_claim_action : 0
M973 S4 ; turn off scanner
M400 ; wait all motion done before implement the emprical L parameters
;M900 L500.0 ; Empirical parameters
M109 S[nozzle_temperature_initial_layer]
M960 S1 P0 ; turn off laser
M960 S2 P0 ; turn off laser
M106 S0 ; turn off fan
M106 P2 S0 ; turn off big fan
M106 P3 S0 ; turn off chamber fan
M975 S1 ; turn on mech mode supression
G90
M83
T1000
G1 E{-retraction_length[initial_no_support_extruder]} F1800
G1 X128.0 Y253.0 Z0.2 F24000.0;Move to start position
G1 E{retraction_length[initial_no_support_extruder]} F1800
M109 S{nozzle_temperature_initial_layer[initial_no_support_extruder]}
G0 X253 E6.4 F{outer_wall_volumetric_speed/(0.3*0.6) * 60}
G0 Y128 E6.4
G0 X252.5
G0 Y252.5 E6.4
G0 X128 E6.4
1 Like

XY Skew Compensation in Bambu Firmware

Y
 ^     B-------C
 |    /       /
 |   /       /
 |  A-------D
 +-------------->X
 XY SKEW FACTOR

M1005 X<AC> Y<BD>

(1) e.g. you print a 100mm square and measure AC as 141.53 and BD as 141.31

(2) using these values add this gcode to the end of the Machine start G-code:

M1005 X141.53 Y141.31
M500

(M500 will save the compensation factor to EEPROM)

(3) Print the square again and measure the diagonals.
(4) If ok delete the gcode from the Machine start G-code.
(5) Print another square to check the compensation factor has been saved.

After step (3) if there is still significant skew you can repeat steps (1)-(3) with the new measurements. A new factor will be applied to the compensation already saved in the firmware.
When satisfied with the result proceed to steps (4)&(5). (Remember to delete the gcode you added to the start G-code or it will continue to apply a new correction factor with each print!).

If you need to reset the compensation value:

M1005 I0
M500

See this post on Reddit for the source of this information which was originally provided by Bambu Lab tech support. The post includes instructions from Bambu Lab and a calibration stl file for printing the square:

Bambu’s M1005 applies a different format for skew correction than Marlin’s M852 but it may also incorporate XZ and YZ correction which could be determined by experimentation.

See also this post on this forum.

15 Likes

M1005 [In]

M1005 can also be used with the [In] parameter to apply a skew correction factor (in radians) for the XY axes.

See my recent post in this forum for details.

3 Likes

Some further information on the M1005 gcode:

M500 does not retain the skew compensation setting when the printer is powered off.

See this thread for a discussion of this problem and a solution using the M1005 [In] format of the command.

4 Likes

Does anyone know if these commands work on the A series?

I need to adjust z offset 29.1 but if put in like 29.1 Z9.9, it clearly is not going up 9mm.

any idea’s? gcode confirms the line is there

Just to make sure you put in
G29.1 Z9.9
But nothing happens, right?

I was working on a few G-code mods for my X1C and noticed that this wasn’t documented as far as I can tell. @mowcius - Feel free to add to the OP if you wish.

Referencing the Checkboxes (e.g. Calibrate, Timelapse, Bed Leveling)

This is information from testing, so may not be 100% accurate, but it does seem to work.

You can query the checkbox status at time of print by wrapping your commands in with M622/M623 callouts after an M1002, example:

; Purposes of this is 
; Check if Filament Calibration checkbox was set, if true, skip and use the new calibrated values.
M1002 judge_flag extrude_cali_flag
M622 J0 ; Meaning it's false, proceed in this block.

	{if enable_pressure_advance[current_extruder]}
   		; If PA is enabled in the Filament Settings, use that K-Value.
		; If not we proceed with whatever the printer has stored.
                                M400
                                M900 K{pressure_advance[current_extruder]} L1000 M10
	{endif}

M623 ; End of the extrude_cali_flag check.

The above sample code queries the “Run Flow Calibration” checkbox, and if it was FALSE (unchecked) when printing occurred the section of the code will run. If the box was TRUE (checked), the printer will skip over the section between M622 and M623.

Breakdown:

  • M1002 judge_flag extrude_cali_flag
    • This seems to query the “Run Flow Calibration” checkbox status at time of print.
  • M622 J0 ;
    • This creates a conditional, with the result needing to be FALSE to run the command.
  • M623 ;
    • This closes the conditional code block (think of it like an {endif})

If you wanted to run the code-block on a TRUE status, you’d switch M622 J0 to M622 J1.

I haven’t tested for the other queries, but these also exist:

  • M1002 judge_flag g29_before_print_flag (likely the bed-leveling checkbox)
  • M1002 judge_last_extrude_cali_success (based on the result of the calibration pass)

Other Examples:

This was just a sample script I used for debugging, allowing me to watch the camera. Placed in the Machine G-Code start after the initialization portion before all of the heatbed/heater stuff.

M1002 judge_flag extrude_cali_flag
M622 J0
   ; judge_flag with J0, false? Then turn the fans to a known value and blink the light.
   M960 S5 P0 ;	Bambu Lab toolhead logo light off
   G4 P5000
   M960 S5 P1 ;	Bambu Lab toolhead logo light on
   G4 P1000
   M960 S5 P0 ;	Bambu Lab toolhead logo light off
   G4 P1000
   M960 S5 P1 ;	Bambu Lab toolhead logo light on
   G4 P1000
   M960 S5 P0 ;	Bambu Lab toolhead logo light off
   G4 P1000
   M960 S5 P1 ;	Bambu Lab toolhead logo light on
M623

G4 P6000

M1002 judge_flag extrude_cali_flag
M622 J1
   ; judge_flag with J1, true? Then turn the fans to known values and turn the laser on.
   M106 S15 ; turn part-cooling fan to 15% for verification
   M106 P2 S44 ; turn aux fan to 44% for verification
   M106 P3 S67 ; turn chamber fan to 67% for verification
   M960 S1 P1 ; turn on laser
   M960 S2 P1 ; turn on laser
M623

If the Flow Calibration was checked, it does the latter part (with the laser), otherwise it does the first part (with the toolhead light).

5 Likes