Power Loss Resume Function in Klipper
Overview
- The power loss resume function in Klipper refers to the ability to automatically restore the printing state of Klipper after it has been powered off and then powered on again.
- This function requires the use of a safety shutdown module.
- It is not applicable for machines where the Z-axis will move when the power is cut.
Configuration
plr.cfg Configuration File
-
In the printer configuration page, click "New Configuration File" to create a
plr.cfg
file. -
The content of the configuration file is as follows:
[mcu host]
serial: /tmp/klipper_host_mcu
[power_loss_resume]
# power_pin: PA0 # Shutdown pin of the safety shutdown module connected to PA0 of the lower-level MCU
power_pin: host:gpiochip1/gpio21 # Shutdown pin of the safety shutdown module connected to PA21 of the upper-level MCU
is_shutdown: True # Whether to execute the shutdown operation, default is enabled
paused_recover_z: -2.0 # If the machine stops during a pause print, the Z movement distance during recovery, default is no movement
start_gcode:
# G-code to be executed before resuming printing
# All parameters saved before power failure can be accessed via {PLR}
# Use M118 {PLR} to output all available parameters
M118 Resuming Print: {PLR.print_stats.filename}
M118 Interrupt Position: X:[{PLR.POS_X}] Y:[{PLR.POS_Y}] Z:[{PLR.POS_Z}] E:[{PLR.POS_E}]
M140 S{PLR.bed.target} ; Set bed temperature
M104 S{PLR.extruder.target-10} ; Set extruder temperature
M109 S{PLR.extruder.target-10} ; Wait for the extruder to heat up to the set temperature
G91 ; Relative coordinates
G1 Z2 F100 ; Lift Z, prepare for X,Y reset
G90 ; Absolute coordinates
G28 X Y ; Reset XY
M140 S{PLR.bed.target} ; Set bed temperature
M104 S{PLR.extruder.target} ; Set extruder temperature
M190 S{PLR.bed.target} ; Wait for the bed to heat up to the set temperature
M109 S{PLR.extruder.target} ; Wait for the extruder to heat up to the set temperature
M83 ; Relative extrusion
# G1 E0.5 F400 ; Extrude a bit
layer_count: 2 # Number of layers to resume before executing layer_change_gcode
layer_change_gcode:
# G-code to be executed after resuming {layer_count} layers
M118 Resuming Print Speed
M106 S{PLR.fan_speed} ; Turn on the part cooling fan
M220 S{PLR.move_speed_percent} ; Set requested speed percentage
M221 S{PLR.extrude_speed_percent} ; Set requested extrude speed percentage
shutdown_gcode:
# G-code to be executed before shutdown
M118 Low Voltage, Shutting Down
# M112 ; Emergency stopNote- The
start_gcode
macro in the above configuration file may need to be modified based on the actual machine conditions.
- The
-
After saving the configuration file, open the
printer.cfg
file and add the following content at the beginning of the file:
[include plr.cfg] -
Click the "Save" button at the top right and restart the system.
-
The power loss resume function in Klipper has now been configured.
Testing
- Start printing any file and click the "Emergency Stop" button during printing to simulate a power failure.
- Click "Firmware Restart" again, wait for Klipper to connect normally.
- If a pop-up prompt appears on the web interface or KlipperScreen, it indicates that the power loss resume function is working properly.
- You can then proceed to test the real power outage scenario.