Bambu Lab X1 Specific G-Code

Right now there’s no documentation from Bambu around what standard and non-standard G-code commands can be used on the X1 series of printers.

As for the standard commands, this Marlin cross reference is great but please note that Bambu doesn’t implement all of it, and some things that are implemented behave a bit different than stated there.

This will be a constantly evolving thread to document these until Bambu publishes some official documentation. Some things are certain, some things may be guesses/assumptions, so use the commands below at your own risk.

If you know any codes, or have any assumptions, please discuss these below and I’ll add them to this first message.

Hardware Control

Code Description
M960 S0 P0 Calibration lasers, and calibration head white LEDs off
M960 S0 P1 Calibration lasers, and calibration head white LEDs on
M960 S1 P0 Calibration Y axis 808nm (IR, visible only thru a/the camera) laser (vertical) off
M960 S1 P1 Calibration Y axis 808nm (IR, visible only thru a/the camera) laser (vertical) on
M960 S2 P0 Calibration X axis 405nm (purple) laser (horizontal) off
M960 S2 P1 Calibration X axis 405nm (purple) laser (horizontal) on
M960 S3 P0/1 Appears to be nothing at all, or I haven’t found what it is
M960 S4 P0 Calibration unit white LEDs off
M960 S4 P1 Calibration unit white LEDs on
M960 S5 P0 Bambu Lab toolhead logo light off
M960 S5 P1 Bambu Lab toolhead logo light on
M17 X/Y/Z#.# Set X/Y/Z Stepper Motor Current**
M106 P1 S0-255 Part cooling fan off-full***
M106 P2 S0-255 Aux fan off-full***
M106 P3 S0-255 Chamber fan off-full***
M710 A1 S0-255 Motor Control (MC) Board fan off-full***
M220 S# Set feed rate to percent of normal (default 100). “M220 S166” is the same as Ludicrous Speed.
M221 Can be used 2 ways****
M971 Commands the built-in camera
M977 S1 P60 Described as “Register 1st layer scan”? No idea what this actually DOES, I’m thinking it sets a flag letting the printer know to perform a 1st layer scan once we’ve printed the 1st layer. That’s the only thing that makes any sense as this command is called in the gcode file WELL before any actual print commands have been sent (aside from the calibration stuff/purge lines)

**Be EXTREMELY careful using this command as it is VERY EASY to cause hardware damage with it should you set it too high!!!
**Example: M17 Z0.4 sets Z stepper current to 0.4

***Example: M106 P3 S180 sets the chamber fan on at 70%

**** If using S# (ie. M221 S75) sets the flowrate to # (Default 100)
**** If using X0/1 Y0/1 or Z0/1 disables or enables the software endstop for that axis (ie. M221 X0 Y1 Z1 would disable the X software endstop and enable them on Y and Z)

Other

Display Message Codes

These commands cause messages to be displayed on printer’s LCD screen, and trigger the corresponding messages to be displayed within the app/slicer.

Code LCD Message Displayed
M1002 gcode_claim_action : 0 (Clear screen of messages?)
M1002 gcode_claim_action : 1 Auto bed levelling
M1002 gcode_claim_action : 2 Heatbed preheating
M1002 gcode_claim_action : 3 Sweeping XY mech mode
M1002 gcode_claim_action : 4 Changing filament
M1002 gcode_claim_action : 5 M400 pause
M1002 gcode_claim_action : 6 Paused due to filament runout
M1002 gcode_claim_action : 7 Heating hotend
M1002 gcode_claim_action : 8 Calibrating extrusion
M1002 gcode_claim_action : 9 Scanning bed surface
M1002 gcode_claim_action : 10 Inspecting first layer
M1002 gcode_claim_action : 11 Identifying build plate type
M1002 gcode_claim_action : 12 Calibrating Micro Lidar
M1002 gcode_claim_action : 13 Homing toolhead
M1002 gcode_claim_action : 14 Cleaning nozzle tip
M1002 gcode_claim_action : 15 Checking extruder temperature
M1002 gcode_claim_action : 16 Paused by the user
M1002 gcode_claim_action : 17 Pause due to the falling off of the tool head’s front cover
M1002 gcode_claim_action : 18 Calibrating the micro lidar
M1002 gcode_claim_action : 19 Calibrating extruder flow
M1002 gcode_claim_action : 20 Paused due to nozzle temperature malfunction
M1002 gcode_claim_action : 21 Paused due to heat bed temperature malfunction

Software Control

Code Description
G29.2 S0 Disable bed leveling compensation (ABL)
G29.2 S1 Enable bed leveling compensation
M205 X#.## Y#.## Z#.## E#.## Sets the jerk limits to #.## mm/sec
G29.1 Z#.## Set Z-trim value to # (0 to clear). Example: “G29.1 Z-0.04” is used for Textured PEI
M900 K#.## Set Pressure Advance, also known as K-value. Eg. “M900 K0.023”
M400 Pause - Can be used 3 ways*

Pause Method 1 Example/Description:

Including S# with the M400 command pauses for # seconds

M400 S30
G1 Z100
G1 X100 Y100

Explanation: Pause for 30 seconds, then start moving towards Z100, and move to X100 Y100 (regardless of whether we’ve arrived at Z100 yet or not)

Pause Method 2 Example/Description:

Use M400 by itself to pause until the previous command completes

G1 Z100
M400
G1 X100 Y100

Explanation: Pause until we arrive at Z100, then move to X100 Y100

Pause Method 3 Example/Description:

M400 U1 ; pause for user intervention

Using U1 with M400 behaves just like when printer is paused from touch screen (or app): The toolhead is parked at the waste chute and printer waits indefinitely for manual resume.

Skew Correction

( Reference post )

Print and measure the Square Calibration STL

M1005 X##.#Y##.# ; input values from printed calibration stl
M500 ; save the values

Add the above Gcode to the last line of the “Machine start Gcode” and only run it once otherwise the compensation will compound each time it is run. Remove the Gcode and reprint the Square Calibration STL and verify the measurements. Iterate as required.

The compensation value can be reset by using the below Gcode.

M1005 I0 ; reset the compensation value
M500 ; save the value
48 Likes

@BrotherC, could you enable the option for regular users to post as wiki? That way (1) the community can contribute together on these guides and (2) if the original author should ever leave, other community members can still edit the post since it is a wiki. Refer to below:

In the meantime, could you convert @Mowcius’s post (if he’s okay with that) to a wiki?

3 Likes

The post has been converted.
We will consider the possibility of users creating Wiki posts, and apply the change if it’s decided.
Thanks for the suggestion.

5 Likes

@BrotherC contribution is already mentioned in the Wiki itself Home | Bambu Lab Wiki

1 Like

I apologize if I wasn’t clear. I wasn’t referring to the Bambu Lab wiki. I was referring to converting the post type of this thread to a wiki. It’s a feature that the forum software allows that I was pointing out to Ciprian.

Is there a wiki for this?

How long does the claim action message remain on the printer’s screen?
Is there a way to pause at that point with some gcode command?

2 Likes

Any clues on how I could send this command to the printer via a script (or as an HTTP call or MQTT message?). Right now, I find myself wanting to adjust the fan (for example), and needing several clicks in Bambu Slicer to do so.

2 Likes

you can add this into the filament start code - example here

Right, but if I want to do this interactively during a print… I guess Bambu Slicer already does send commands somehow, and was hoping to be able to do the same thing, for example, have a button to quick set the chamber fan to 60% during a print, without having to open the slicer. Start code is only going to work when I send the print initially.

It looks to me like the MQTT piece is only publishing current status rather than receiving commands, and since the only connection otherwise is on the network, I was trying to understand how those commands are being sent.

The X1 offers this manipulation here, if that is want you intend to do ?

I’ve now got this working in a manner that is independent of Bambu Studio! :partying_face:

Publish to topic: device/[device-id]/request
Message:
{ "print": { "command": "gcode_line", "param": "M106 P3 S150 \n", "sequence_id": "0" } }

That sets the fan to ~50%, which is usually what I want - now I can automate that via a button or voice command to a simple script.

5 Likes

FYI: for those of you that want to communicate with the printer, the network log file for Orca Slicer actually shows the MQTT commands being sent to the printer.

3 Likes

Forgive me for asking but, where do I find said logs?

click on help/open config directory and there is a log subdirectory.

; change filament without AMS g-code {if toolchange_count > 1} M204 S9000 ; set starting acceleration G17 ; set CNC workspace plane G2 Z{max_layer_z + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift G1 Z{max_layer_z + 3.0} F1200 ; vertical lift

; move to poop chute G1 X70 F21000 G1 Y245 G1 Y265 F3000 M400

; turn off fans P1 and P2 M106 P1 S0 M106 P2 S0

; wipe? G1 X90 F3000 G1 Y255 F4000 G1 X100 F5000 G1 X120 F15000

; move to position to prep for cutting filament G1 X20 Y50 F21000 G1 Y-3 ; always use highest temperature to flush M400 M109 S[nozzle_temperature_range_high]

; cut filament G1 X5 F300 G1 X20 F12000

; move to poop chute G1 X70 F12000 G1 Y245 G1 Y265 F3000

; push a little filament out and then retract out G1 E10 F200 G1 E-10 F200 G1 E-20 F500

; pause for user to load and press resume M400 U1

; don’t know when next_extruder is >=255, so this may always activate? {if next_extruder < 255} M400

G92 E0 {if flush_length_1 > 1} ; FLUSH_START {if flush_length_1 > 23.7} G1 E23.7 F{old_filament_e_feedrate} ; do not need pulsatile flushing for start part G1 E{(flush_length_1 - 23.7) * 0.02} F50 G1 E{(flush_length_1 - 23.7) * 0.23} F{old_filament_e_feedrate} G1 E{(flush_length_1 - 23.7) * 0.02} F50 G1 E{(flush_length_1 - 23.7) * 0.23} F{new_filament_e_feedrate} G1 E{(flush_length_1 - 23.7) * 0.02} F50 G1 E{(flush_length_1 - 23.7) * 0.23} F{new_filament_e_feedrate} G1 E{(flush_length_1 - 23.7) * 0.02} F50 G1 E{(flush_length_1 - 23.7) * 0.23} F{new_filament_e_feedrate} {else} G1 E{flush_length_1} F{old_filament_e_feedrate} {endif} ; FLUSH_END G1 E-[old_retract_length_toolchange] F1800 G1 E[old_retract_length_toolchange] F300 {endif}

{if flush_length_2 > 1} ; FLUSH_START G1 E{flush_length_2 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_2 * 0.02} F50 G1 E{flush_length_2 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_2 * 0.02} F50 G1 E{flush_length_2 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_2 * 0.02} F50 G1 E{flush_length_2 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_2 * 0.02} F50 G1 E{flush_length_2 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_2 * 0.02} F50 ; FLUSH_END G1 E-[new_retract_length_toolchange] F1800 G1 E[new_retract_length_toolchange] F300 {endif}

{if flush_length_3 > 1} ; FLUSH_START G1 E{flush_length_3 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_3 * 0.02} F50 G1 E{flush_length_3 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_3 * 0.02} F50 G1 E{flush_length_3 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_3 * 0.02} F50 G1 E{flush_length_3 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_3 * 0.02} F50 G1 E{flush_length_3 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_3 * 0.02} F50 ; FLUSH_END G1 E-[new_retract_length_toolchange] F1800 G1 E[new_retract_length_toolchange] F300 {endif}

{if flush_length_4 > 1} ; FLUSH_START G1 E{flush_length_4 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_4 * 0.02} F50 G1 E{flush_length_4 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_4 * 0.02} F50 G1 E{flush_length_4 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_4 * 0.02} F50 G1 E{flush_length_4 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_4 * 0.02} F50 G1 E{flush_length_4 * 0.18} F{new_filament_e_feedrate} G1 E{flush_length_4 * 0.02} F50 ; FLUSH_END {endif} ; FLUSH_START M400 M109 S[new_filament_temp] G1 E2 F{new_filament_e_feedrate} ;Compensate for filament spillage during waiting temperature ; FLUSH_END M400 G92 E0 G1 E-[new_retract_length_toolchange] F1800 M106 P1 S255 M400 G1 X80 F15000 G1 X60 F15000 G1 X80 F15000 G1 X60 F15000; shake to put down garbage

G1 X70 F5000 G1 X90 F3000 G1 Y255 F4000 G1 X100 F5000 G1 Y265 F5000 G1 X70 F10000 G1 X100 F5000 G1 X70 F10000 G1 X100 F5000 G1 X165 F15000; wipe and shake G1 Y256 ; move Y to aside, prevent collision M400 G1 Z[z_after_toolchange] F3000 {if layer_z <= (initial_layer_print_height + 0.001)} M204 S[initial_layer_acceleration] {else} M204 S[default_acceleration] {endif} {else} G1 X[x_after_toolchange] Y[y_after_toolchange] Z[z_after_toolchange] F12000 {endif}

{endif}

; as there is no AMS, these next three lines only serve to hide T[next_extruder] ; if this was not included, the T[next_extruder] command is input after this ; code and will cause the system to hang as the toolchange command searches ; for the AMS M620 S[next_extruder]A T[next_extruder] M621 S[next_extruder]A

1 Like

Did some cleaning up/editing and added a bunch of commands, hope everyone enjoys!

2 Likes

I’m on Mac, as such I do not have this “Help” you speak of to click on. Anyone else care to take a try?

Does this area look familiar on a mac? Im not apple user but i found this picture.

1 Like

Library > Application Support > Bambu Studio > Log or
[User Home] Library > Application Support > Bambu Studio > Log

that’s the path on the Mac here’s a shot from my machine
Screenshot 2023-07-27 at 9.08.26 AM

1 Like