Revive your Prusa Mk3s with Klipper 2/5 – Compile and flash Klipper

Chapter 2/5

Installing Mainsail, Compiling Klipper, Flashing Einsy Board with Klipper, and Creating Printer.cfg File for Prusa Mk3s

 

This is a series of 5 chapters:

By the end of this chapter your Prusa Mk3s will be running Klipper software and you will be able to:

  • Use the Raspberry Pi MCU for all calculations, thereby enhancing printer quality. The Einsy board will be solely controlling the stepper motors.
  • Print via Wi-Fi.
  • Increase speed and accelerations.
  • Enjoy unlimited software definitions and tuning.

First of all you will need:

Our setup is going to look super clean, no adaptors, no converters, no nothing. We are going to connect a rpi zero 2w to the back of the einsy board and use the board to power the rpi and transmit data via uart serial connection. Just like the image below.

What is Mainsail?

Mainsail is the web interface where you can control and manage your 3d printer that runs klipper.

Check their github https://github.com/mainsail-crew/mainsail and consider making a donation https://ko-fi.com/mainsail

 

How to install Mainsail:

    1. Download Raspberry Pi imager from here https://www.raspberrypi.com/software/
    2. Click on “Choose OS” > “Other specific-purpose OS” > “3D Printing” > “Mainsail OS” > “Mainsail OS 32-bit.”
    3. Next click on the bottom right corner for more definitions:

            • set hostname: prusa
            • enable SSH
            • set username: pi
            • set password: raspberry
            • configure wlan (check if you wifi SSID and password are there)
            • set locat settings
            • hit save button
    4. Click on write button
    5. Remove the microsd card from your computer and place it on the rpi zero 2w
    6. Power the RPI zero 2w by connecting with a micro usb cable to a charger.
    7. Find the new IP address of your RPi Zero 2W. Access your router’s online dashboard and look for new devices connected to the network or access the RPi via a browser by typing the following in the address bar: prusa.local
    8. Turn off the RPi. On the Mainsail web interface, look for the power icon on the top bar on the right side. Click on the power icon and select shutdown. This step is mandatory every single time you want to turn off the printer, or you might face a corrupted SD card very soon.

 

Flash Einsy Board with Klipper

Now that the raspberry is running Mainsail were are ready to proceed.

  1. Power the RPI zero 2w using a micro usb charger, connect a micro usb OTG cable to the available micro usb connector and connect the usb type B cable to the OTG and to the top of the einsy board. Like the picture below.

  2. We are going to SSH to the rpi using putty https://www.putty.org/
    • place the ip address of the rpi. select SSH. click in open.
    • user name is pi
    • password is raspberry
  3. Execute the following commands:
cd klipper
make clean
make menuconfig

We now have to decide if we are going to use a raspberry connected via USB or Serial UART

By USB:


Just like the picure

By Serial UART (to the back of the einsy board):

Just Like the picture.

    1. Now hit esc / yes . We are going to compile the firmware by executing
      make
    1. We are going to turn on the printer and check if we can dected the einsy board by executing the command
      ls /dev/serial/by-id/*
    2.  We should detect “usb-Prusa_Research__prusa3d.com__Original_Prusa_i3_MK3-if00”
    3.  Lets proceed and send the compiled firmware to the einsy board by executing the following command
      sudo service klipper stop
      
      make flash FLASH_DEVICE=usb-Prusa_Research__prusa3d.com__Original_Prusa_i3_MK3-if00
    4.  If everything goes ok, you should see a screen display success message like this:

    5.  you should see a message on the printer display saying updating. Ignore it. start klipper again
      sudo service klipper start
    6. turn off the rpi and the printer. RPI can be shutdown by shh command sudo shutdown -r now or access mainsail and on the right top bar of Mainsail web interface, click on the power icon and shutdown. This has to be mandatory every single time you want to turn off the printer or you might face a corrupted sd card very soon.

 

 

How to connect the RPI Zero to the back of the Einsy Board by Serial UART?

    1. First we need to enable Serial UART on the raspberry pi.
      Power the rpi. Access via SSH and execute:

      run sudo raspi-config

      Select 3. Interfacing Options
      Select Serial Port
      Then No when it asks if you want a login shell to be accessible over serial.
      Then Yes when it asks if you want the hardware enabled.
      Shutdown the RPI and remove all the cables attached to it

    2. Following the exaclty steps from the prusa blog, quoting: “Make sure the printer is turned off and carefully cut all the indicated plastic parts and remove the cut-out part. During the cutting process, MAKE SURE YOU DON’T CUT the Einsy board!!!”
      That small orange printed part is a frame to keep the rpi 2w at a safe distance from the einsy board. You can download it here https://www.printables.com/model/86489-raspberry-pi-zero-2-w-frame-for-einsy-rambo 

    3. Slot the RPi Zero, with its frame, into the connector holes indicated below (green square). Then fit the cover to protect the RPi Zero W (purple arrows).

    4. download a cover to close the einsy back at  https://www.printables.com/model/36118-raspberry-pi-zero-frame-for-einsy-rambo

    5. turn on the printer
    6. find the new IP address of your rpi zero 2w. Acess your router online dashboard and look for new devices connect to the network or access the rpi via browser by writting on the address bar: prusa.local. Now you have access your mainsail installation.
    7. Mainsail is going to display some erros because there is no printer.cfg file. This file is where you define all the settings of your board and printer.
      Mainsail requires a minimum configuration to function properly and will display a warning at startup if the required parts are not found in your configuration file(s). Let’s proceed with this on the next topic.

 

 

Create Printer.cfg file for Prusa Mk3s

On the left side of the display click on Machine and create new file

On the dialog box write printer.cfg and click create
Copy paste the following code.

###################################################################################
###################################################################################
################ Prusa MK3s Klipper Config by Lab4450.com ###################
###################################################################################
###################################################################################

# This file contains pin mappings and reasonable defaults for Prusa i3 MK3S
# printers. It will work with MK3s.
# References to common community mods are included as well.
#
# Note: The Einsy boards sold by Prusa have defective firmware on the
# usb-to-serial chip that makes the boards unusable with Klipper through USB.
# While flashing Klipper firmware must be done over USB, the board can be used
# via serial with no additional modification.
# To use this config, the firmware should be compiled for the AVR atmega2560.
#
# SERIAL CONNECTION
# If you want to connect the Rpi to the back of the Einsy Board as https://help.prusa3d.com/article/prusaprint-rpi-zero-and-octoprint_2180
# run sudo raspi-config which will start the utility and then select:
# To use via serial, in "make menuconfig" select "Enable extra low-level configuration options"
# and select serial1 (the RasPi serial)
# on the raspbery pi make sure serial is enabled. run sudo raspi-config
# 3. Interfacing Options
# select Serial Port
# Then No when it asks if you want a login shell to be accessible over serial.
# Then Yes when it asks if you want the hardware enabled.
# At this point you might want to double check that the ssh server is running:
# From the raspi-config utility:
# 3. Interfacing Options
# select SSH
# Answer Yes when asked if you would like the SSH server to be enabled.
#
# USB CONNECTION
# If you want to use the USB connection dont select "Enable extra low-level configuration options".
#

### UI
[include mainsail.cfg]

### BOARD
[mcu]
serial: /dev/serial0 # If you are using internal RPI serial port
# serial: /dev/serial/by-id/usb-Prusa_Research__prusa3d.com__Original_Prusa_i3_MK3-if00 # If you are using RPI via USB connection to printer
restart_method: command

[temperature_sensor einsy_board]
sensor_pin: PF6
sensor_type: TDK NTCG104LH104JT1
min_temp: 0
max_temp: 70

### RPI
[temperature_sensor raspberry_pi]
sensor_type: temperature_host
min_temp: 0
max_temp: 80

### PRINTER DEFINITIONS
[printer]
kinematics: cartesian
max_accel: 4000
max_accel_to_decel: 2500
max_velocity: 300
max_z_velocity: 40
max_z_accel: 200
square_corner_velocity: 8.0

### BED
[heater_bed]
heater_pin: PG5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF2
control: pid
min_temp: 0
max_temp: 120
pid_Kp:55.864
pid_Ki:0.876
pid_Kd:890.334

### FANS
[heater_fan hotend_fan]
pin: PH5
heater: extruder
heater_temp: 50.0
fan_speed: 1.0

[fan] # Part Cooling Fan
pin: PH3

### DISPLAY
[display]
lcd_type: hd44780
rs_pin: PD5
e_pin: PF7
d4_pin: PF5
d5_pin: PG4
d6_pin: PH7
d7_pin: PG3
encoder_pins: ^PJ1,^PJ2
click_pin: ^!PH6

[output_pin LCD_backlight_pin]
pin: PE3
pwm: True
hardware_pwm: True
value: 0.25 # 30% backlight
shutdown_value: 1 # Back to full backlight (without PWM) on restart
cycle_time: 0.001 # Default 0.1s cycle time flickers as hell

[static_digital_output debug_led] # Keeps Debug LED off / not floating
pins: !PB7

[output_pin BEEPER_pin]
pin: PH2
pwm: True
value: 0
shutdown_value:0
cycle_time: 0.001
scale: 1000

### MOTORS
[motor_constants prusa-xye]
# install https://github.com/andrewmcgr/klipper_tmc_autotune/tree/main
# this is a custom motor for xye
resistance: 6.5
inductance: 0.013
holding_torque: 0.49
max_current: 1
steps_per_revolution: 200

[motor_constants prusa-z]
# install https://github.com/andrewmcgr/klipper_tmc_autotune/tree/main
# this is a custom motor for z
resistance: 8
inductance: 0.095
holding_torque: 0.32
max_current: 1
steps_per_revolution: 200

[autotune_tmc stepper_x]
motor: prusa-xye

[stepper_x]
step_pin: PC0
dir_pin: !PL0
enable_pin: !PA7
microsteps: 16
rotation_distance: 32
endstop_pin: tmc2130_stepper_x:virtual_endstop
position_endstop: 0
position_max: 255
homing_speed: 50
homing_retract_dist: 0

[tmc2130 stepper_x]
cs_pin: PG0
interpolate: True
stealthchop_threshold: 0
run_current: .281738
hold_current: .281738
sense_resistor: 0.220
diag1_pin: !PK2
driver_IHOLDDELAY: 8
driver_TPOWERDOWN: 0
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 1
driver_HSTRT: 5
driver_PWM_FREQ: 2
driver_PWM_GRAD: 2
driver_PWM_AMPL: 230
driver_PWM_AUTOSCALE: True
driver_SGT: 3

[autotune_tmc stepper_y]
motor: prusa-xye

[stepper_y]
step_pin: PC1
dir_pin: PL1
enable_pin: !PA6
microsteps: 16
rotation_distance: 32
endstop_pin: tmc2130_stepper_y:virtual_endstop
position_endstop: -4
position_max: 212.5
position_min: -4
homing_speed: 50
homing_retract_dist: 0

[tmc2130 stepper_y]
cs_pin: PG2
interpolate: True
stealthchop_threshold: 0
run_current: .281738
hold_current: .281738
sense_resistor: 0.220
diag1_pin: !PK7
driver_IHOLDDELAY: 8
driver_TPOWERDOWN: 0
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 1
driver_HSTRT: 5
driver_PWM_FREQ: 2
driver_PWM_GRAD: 2
driver_PWM_AMPL: 230
driver_PWM_AUTOSCALE: True
driver_SGT: 3

[autotune_tmc stepper_z]
motor: prusa-z

[stepper_z]
step_pin: PC2
dir_pin: !PL2
enable_pin: !PA5
microsteps: 16
rotation_distance: 8
endstop_pin: probe:z_virtual_endstop
position_max: 210
position_min: -2
homing_speed: 13.333

[tmc2130 stepper_z]
cs_pin: PK5
run_current: .53033
hold_current: .53033
sense_resistor: 0.220
diag1_pin: !PK6
interpolate: True
driver_IHOLDDELAY: 8
driver_TPOWERDOWN: 0
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 1
driver_HSTRT: 5
driver_PWM_FREQ: 2
driver_PWM_GRAD: 4
driver_PWM_AMPL: 200
driver_PWM_AUTOSCALE: True
driver_SGT: 4

### EXTRUDER
[extruder]
full_steps_per_rotation: 200
rotation_distance: 22.85696
max_extrude_cross_section: 50.0
max_extrude_only_velocity: 120.0
max_extrude_only_accel: 1250.0
max_extrude_only_distance: 200
nozzle_diameter: 0.4
filament_diameter: 1.750
pressure_advance: 0.06
pressure_advance_smooth_time: 0.040
step_pin: PC3
dir_pin: PL6
enable_pin: !PA4
microsteps: 16
heater_pin: PE5
sensor_type: ATC Semitec 104GT-2
sensor_pin: PF0
max_temp: 285
min_extrude_temp: 170
min_temp: 0
control: pid
pid_Kp:21.837
pid_Ki:1.234
pid_Kd:96.629

[autotune_tmc extruder]
motor: prusa-xye

[tmc2130 extruder]
cs_pin: PK4
interpolate: True
run_current: .513757
hold_current: .513757
sense_resistor: 0.220
diag1_pin: !PK3
driver_IHOLDDELAY: 8
driver_TPOWERDOWN: 0
driver_TBL: 2
driver_TOFF: 3
driver_HEND: 1
driver_HSTRT: 5
driver_PWM_FREQ: 2
driver_PWM_GRAD: 4
driver_PWM_AMPL: 240
driver_PWM_AUTOSCALE: True
driver_SGT: 3

[gcode_arcs]
resolution: 0.25

[firmware_retraction]
retract_length: 0.5

 

### BED MESH AND PROBE
[bed_mesh]
horizontal_move_z: 2
mesh_min: 35, 6
mesh_max: 240,198
# Odd number of probe points per dimension (3x3, 5x5, 7x7) is better as then the area near the center screw is probed
probe_count: 7,7
#probe_count: 5,5
#probe_count: 3,3
speed: 100
algorithm: bicubic
fade_start: 1.0
fade_end: 10.0
move_check_distance: 3.0
split_delta_z: .025
bicubic_tension: .2
mesh_pps: 0,0 #Don't generate interperlated points so our mesh is precise with screw tilt adjust
# Avoid magnets
faulty_region_1_min: 100.583, 187.376
faulty_region_1_max: 122.083, 229.376
faulty_region_2_min: 125.672, -18.124
faulty_region_2_max: 147.172, 23.876
faulty_region_3_min: 192.261, 5.126
faulty_region_3_max: 234.261, 26.626
faulty_region_4_min: 114.422, 39.876
faulty_region_4_max: 135.922, 81.876
faulty_region_5_min: 21.422, 87.126
faulty_region_5_max: 42.922, 129.126
faulty_region_6_min: 54.172, 97.376
faulty_region_6_max: 96.172, 118.876
faulty_region_7_min: 154.172, 97.376
faulty_region_7_max: 196.172, 118.876
faulty_region_8_min: 205.136, 87.126
faulty_region_8_max: 226.636, 129.126
faulty_region_9_min: 114.422, 134.376
faulty_region_9_max: 135.922, 176.376
faulty_region_10_min: 176.177, 191.394
faulty_region_10_max: 218.177, 212.894

[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BASE_BED_MESH_CALIBRATE
gcode:
BED_MESH_CLEAR
BASE_BED_MESH_CALIBRATE

[safe_z_home]
home_xy_position: 128,110
speed: 50.0
z_hop: 15
z_hop_speed: 15.0
move_to_previous: False

[probe]
pin: PB4
x_offset: 23
y_offset: 5
speed: 20.0
z_offset : 1.480 # default is zero. update this to your Z offset. this is just a safe value so you don't crash the nozzle against the pei plate
samples: 3 # Sampling, primarily for bed mesh. 3 is fine for normal PINDA probes.
samples_result: average
sample_retract_dist: 1.0

# if you are using a pinda v2 with 4 cables you can read the pinda inbuilt thermistor temperature
# [temperature_sensor pinda]
# sensor_type: EPCOS 100K B57560G104F
# sensor_pin: PF3
# min_temp: 0
# max_temp: 100
# gcode_id: C

 

[screws_tilt_adjust]
# SW Nylock Mod: Screw 1 uses the 6mm metallic spacer so its
# height is considered the baseline. For tilt adjust using the
# command SCREWS_TILT_CALCULATE or MACRO ADJUST_BED_SCREWS, this has to be your Screw 1:
#
# ******************
# * S7 S8 S9 *
# * *
# Bed: * S5 S1 S6 *
# * *
# * S2 S3 S4 *
# ******************
#
screw1: 128,110
screw1_name: Center
screw2: 13,6
screw2_name: Front Left
screw3: 13,115
screw3_name: Front Center
screw4: 13,210
screw4_name: Front Right
screw5: 123,6
screw5_name: Center Left
screw6: 123,210
screw6_name: Center Right
screw7: 228,6
screw7_name: Back Left
screw8: 228,115
screw8_name: Back Center
screw9: 228,210
screw9_name: Back Right
horizontal_move_z: 10.
speed: 50.
screw_thread: CCW-M3

[gcode_macro ADJUST_BED_SCREWS]
gcode:
# Heat the bed at 80ºc to proceed with a more accurate process
M140 S80 ; start heating bed to 80ºc
G28 ; home
Tram_Z ; tram z aka calibrate z

M190 S80 ; wait for bed to reach 80ºc
G4 P300000 ; Waits 5 min for the bed temp to stabilize
# HOT TEMPERATURE! BE CAREFUL WHEN TOUCHING THE BED OR THE BED SCREWS
# HOT TEMPERATURE! BE CAREFUL WHEN TOUCHING THE BED OR THE BED SCREWS
# HOT TEMPERATURE! BE CAREFUL WHEN TOUCHING THE BED OR THE BED SCREWS
# HOT TEMPERATURE! BE CAREFUL WHEN TOUCHING THE BED OR THE BED SCREWS

SCREWS_TILT_CALCULATE SAMPLE_RETRACT_DIST=1
G1 X180 Y199 Z50 F1000
M190 S0 ; turn off bed heater
M117 !! ATTENTION BED IS HOT !!
UPDATE_DELAYED_GCODE ID=clear_display DURATION=3
M117 remove pei sheet
UPDATE_DELAYED_GCODE ID=clear_display DURATION=3
M117 adjust bed screws
UPDATE_DELAYED_GCODE ID=clear_display DURATION=3
# REPEAT THIS MACRO UNTIL PERFECTION

[menu __main __setup __calib __Ajust_Bed_Screws]
type: command
enable: {not printer.idle_timeout.state == "Printing"}
name: Adjust Bed Screws
gcode:
ADJUST_BED_SCREWS

[gcode_macro G80]
gcode:
M117 Bed leveling
BED_MESH_CALIBRATE
G1 X0 Y0 Z0.4 F4000
M117
M400

[gcode_macro G81]
gcode:
BED_MESH_OUTPUT

### ADXL
[input_shaper]
shaper_freq_x: 52.287 # frequency for the X mark of the test model
shaper_freq_y: 48.438 # frequency for the Y mark of the test model
shaper_type: mzv
damping_ratio_x: 0.1
damping_ratio_y: 0.12

### FILAMENT SENSOR
[filament_switch_sensor filament_sensor]
pause_on_runout: True
runout_gcode:
M118 Filament Runout Detected
M600
CONDITIONAL_BEEP i=3 dur=300 freq=400
insert_gcode:
M118 Filament Load Detected
LOAD_FILAMENT
event_delay: 3.0
# If you have issues with movement after the runout_gcode executes
# you may increase the pause_delay. It should be noted that this
# is a workaround for an issue with how Octoprint handles
# acknowledgments. This issue is schedule to be fixed in the next
# release, after which the "pause_delay" option will likely be removed.
pause_delay: 0.01
switch_pin: !PK0

#[delayed_gcode DISABLEFILAMENTSENSOR] #DISABLE FILAMENT SENSOR ON STARTUP
#initial_duration: 1
#gcode:
# SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=0

[gcode_macro M600] # Color Change
description: Color change
gcode:
{% set X = params.X|default(0)|float %}
{% set Y = params.Y|default(0)|float %}
{% set Z = params.Z|default(10)|float %}
SAVE_GCODE_STATE NAME=M600_state
PAUSE
G91
G1 E-.8 F2700
G1 Z{Z}
G90
G1 X{X} Y{Y} F3000
G91
G1 E-50 F1000
RESTORE_GCODE_STATE NAME=M600_state

[gcode_macro UNLOAD_FILAMENT]
gcode:
SAVE_GCODE_STATE NAME=unload_state
G91
{% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %}
M117 Heating...
# Heat up hotend to provided temp or 220 as default as that should work OK with most filaments.
M109 S{params.TEMP|default(220, true)}
{% endif %}
M117 Unloading filament...
G92 E0.0
G91
G1 E-45 F5000
G1 E-15 F1000
G1 E-20 F1000
G90
G92 E0.0
M400
M117 Remove Filament Now!
M300 S300 P1000
M117 Filament unloaded!
RESTORE_GCODE_STATE NAME=unload_state
UPDATE_DELAYED_GCODE ID=clear_display DURATION=5

[gcode_macro LOAD_FILAMENT]
gcode:
SAVE_GCODE_STATE NAME=load_state
G91
# Heat up hotend to provided temp or 220 as default as that should work OK with most filaments.
{% if params.TEMP is defined or printer.extruder.can_extrude|lower == 'false' %}
M117 Heating...
M109 S{params.TEMP|default(220, true)}
{% endif %}
M117 Loading filament...
# Load the filament into the hotend area.
G92 E0.0
G91
G1 E70 F400
G1 E40 F100
G90
G92 E0.0
M400
M117 Filament loaded!
RESTORE_GCODE_STATE NAME=load_state
UPDATE_DELAYED_GCODE ID=clear_display DURATION=5

[menu __filament __change]
type: command
name: Change Filament
gcode:
M600

[menu __filament __resume]
type: command
name: Resume
gcode:
RESUME

#####################
### MACROS
#####################

[respond]
default_type: command

[skew_correction]

[input_shaper]

[virtual_sdcard]
path: ~/printer_data/gcodes

[display_status]

[pause_resume]

[force_move]
enable_force_move: True

[gcode_macro M486]
gcode:
CLEAR_PAUSE

[gcode_macro M300]
gcode:
# Use a default 1kHz tone if S is omitted.
{% set S = params.S|default(1000)|int %}
# Use a 10ms duration is P is omitted.
{% set P = params.P|default(100)|int %}
SET_PIN PIN=BEEPER_pin VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 }
G4 P{P}
SET_PIN PIN=BEEPER_pin VALUE=0

[delayed_gcode clear_display]
initial_duration: 0.
gcode:
M117

[menu __main __octoprint] # we are not using this menu so we are going to remove it
type: disabled

[pause_resume]

[display_status]

[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
variable_park: True
gcode:
## Move head and retract only if not already in the pause state and park set to true
{% if printer.pause_resume.is_paused|lower == 'false' and park|lower == 'true'%}
_TOOLHEAD_PARK_PAUSE_CANCEL
{% endif %}
TURN_OFF_HEATERS
CANCEL_PRINT_BASE
SDCARD_RESET_FILE
# Raise nozzle by 60mm
G1 Z60 F3000
G90
# Disable steppers
M84

[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
gcode:
PAUSE_BASE
_TOOLHEAD_PARK_PAUSE_CANCEL

[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
##### read extrude from _TOOLHEAD_PARK_PAUSE_CANCEL macro #####
{% set extrude = printer['gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL'].extrude %}
#### get VELOCITY parameter if specified ####
{% if 'VELOCITY' in params|upper %}
{% set get_params = ('VELOCITY=' + params.VELOCITY) %}
{%else %}
{% set get_params = "" %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == 'true' %}
M83
G1 E{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == 'true' %} M82 {% endif %}
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
RESUME_BASE {get_params}
CLEAR_PAUSE

[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
description: Helper: park toolhead used in PAUSE and CANCEL_PRINT
variable_extrude: 1.0
gcode:
##### set park positon for x and y #####
# default is your max posion from your printer.cfg
{% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %}
{% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
{% set z_park_delta = 2.0 %}
##### calculate save lift position #####
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% if act_z < (max_z - z_park_delta) %}
{% set z_safe = z_park_delta %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == 'true' %}
M83
G1 E-{extrude} F2100
{% if printer.gcode_move.absolute_extrude |lower == 'true' %} M82 {% endif %}
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
{% if "xyz" in printer.toolhead.homed_axes %}
G91
G1 Z{z_safe} F900
G90
G1 X{x_park} Y{y_park} F6000
{% if printer.gcode_move.absolute_coordinates|lower == 'false' %} G91 {% endif %}
{% else %}
{action_respond_info("Printer not homed")}
{% endif %}

[gcode_macro Tram_Z] # Prusa's calibrate Z
description: Tram Z axis
gcode:
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% if printer.toolhead.homed_axes != "xyz" %}
G28
{% endif %}
G1 X20 Y0
G1 Z{max_z-10} F2000 #Update with Z height.
FORCE_MOVE STEPPER=stepper_z Distance=20 Velocity=10
G1 Z{max_z-50} F2000 # Move down
G28 Z # Home again

[gcode_macro G34]
gcode:
Tram_Z

[menu __main __setup __calib __Tram_Z]
type: command
enable: {not printer.idle_timeout.state == "Printing"}
name: Tram Z Axis
gcode:
G34

[gcode_macro PREHEAT_PLA]
gcode:
# Start bed heating
M140 S60
# Start nozzle heating
M104 S200

[gcode_macro PREHEAT_PETG]
gcode:
# Start bed heating
M140 S90
# Start nozzle heating
M104 S240

[gcode_macro PREHEAT_TPU]
gcode:
# Start bed heating
M140 S50
# Start nozzle heating
M104 S190

[gcode_macro PID_TEST_BED]
gcode:
# Parameters
{% set TARGETTEMP = params.TEMP|default(70)|int %}

{% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
{% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
G28
G90
G1 X{max_x/2} Y{max_y/2} Z40 F6000
PID_CALIBRATE HEATER=< TARGET={TARGETTEMP}

[gcode_macro PID_TEST_HOTEND]
gcode:
# Parameters
{% set TARGETTEMP = params.TEMP|default(245)|int %}

{% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
{% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
G28
G90
G1 X{max_x/2} Y{max_y/2} Z10 F6000
M106 S64
PID_CALIBRATE HEATER=extruder TARGET={TARGETTEMP}
M107 ; Turn off print cooling fan

[gcode_macro PURGE_LINE]
gcode:
M117 Priming ...
G92 E0.0 ; reset extruder
G90 ; Absolute positioning
G0 X5 Y-3.0 F5000 ; Moves to starting point outside print area
G0 Z0.4 F500 ; Raises Z to 0.4
G91 ; Incremental positioning
G92 E0.0 ; reset extruder position
G90 ; Absolute positioning
G1 X50.0 E8.0 F1000.0 ; start intro line
G1 X90.0 E24.0 F1000.0 ; finish thicker
G92 E0.0
G90 ; Absolut position

[gcode_macro PRINT_START]
gcode:
# edit slicer
# M104 S0 ; Stops PrusaSlicer from sending temp waits separately
# M140 S0
# print_start EXTRUDER=[first_layer_temperature[initial_extruder]] BED=[first_layer_bed_temperature]

# Parameters
{% set bed = params.BED|int %}
{% set hotend = params.HOTEND|int %}
{% set chamber = params.CHAMBER|default(0)|int %}

M73 P0 ; clear LCD progress bar
M82 ; extruder to absolute mode
G92 E0 ; set extruder to zero
M140 S{bed} ; get bed heating up
M117 Bed Heating and Homing
G28 ; home all axis
G90 ; absolute positioning
M190 S{bed} ; wait for bed temp
G4 P300000 ; Waits 5 min for the bed temp to stabilize
# TEMPERATURE_WAIT SENSOR="temperature_sensor pinda" MINIMUM={chambertemp} ; enable if you have a pinda v2 with 4 cables and you want to wait for the pinda to reach slicer chamber temperature

G80 ; bed leveling and bed mesh calibration
M117 Leveling
BED_MESH_PROFILE LOAD=default ; load bed mesh
SCREWS_TILT_CALCULATE MAX_DEVIATION=0.01 ; will abort the print if the configured limit is exceeded

M107 ; Turns off the PT-fan
M104 S{hotend} ; set extruder temp
M109 S{hotend} ; wait for extruder temp
M117 Hotend Heating
PURGE_LINE; ; execute macro purge line
M400 ; clear buffer
M117 Printing...

[gcode_macro PRINT_END]
gcode:
CONDITIONAL_BEEP I=2 DUR=30 FREQ=8500

M400 ; wait for buffer to clear
G92 E0 ; zero the extruder
G1 F1000.0 ; set feed rate
G1 E-3 ; retract
G91 ; relative positioning

# Set safe speeds
{% set zVelocity = printer.configfile.settings.printer.max_z_velocity|default(15)|int %}
{% set maxVelocity = printer.configfile.settings.printer.max_velocity|default(200)|int %}
{% set zVelocityAdjusted = (0.95 * zVelocity * 60)|int %}
{% set maxVelocityAdjusted = (0.95 * maxVelocity * 60)|int %}

# Get Boundaries
{% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
{% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
{% set max_z = printer.configfile.config["stepper_z"]["position_max"]|float %}

# Check end position to determine safe direction to move
{% if printer.toolhead.position.x < (max_x - 20) %}
{% set x_safe = 20.0 %}
{% else %}
{% set x_safe = -20.0 %}
{% endif %}

{% if printer.toolhead.position.y < (max_y - 20) %}
{% set y_safe = 20.0 %}
{% else %}
{% set y_safe = -20.0 %}
{% endif %}

{% set lift_height = 25.0 %}
{% if printer.toolhead.position.z < (max_z - lift_height) %}
{% set z_safe = lift_height %}
{% else %}
{% set z_safe = max_z - printer.toolhead.position.z %}
{% endif %}

G0 Z{z_safe} F{zVelocityAdjusted} ; move nozzle up
G0 X{x_safe} Y{y_safe} F{maxVelocityAdjusted} ; move nozzle to remove stringing
TURN_OFF_HEATERS ; turn off heaters
M107 ; turn off fan
G90 ; absolute positioning
G0 X60 Y{max_y} F3600 ; park nozzle at rear
M221 S100 ; Reset Filament Flowrate
M84XYE ; disable xye motors
M117 Printer Ready ; LCD status message

[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
G91
G1 X-2 Y-2 E-1 F300
G1 Z50 F3000 ; Raise nozzle by 50mm
G90
TURN_OFF_HEATERS
M107
CLEAR_PAUSE
SDCARD_RESET_FILE
BASE_CANCEL_PRINT
CUSTOM_PRINT_CANCELED

[gcode_macro CUSTOM_PRINT_CANCELED]
gcode:
M117 Print canceled

 

How to install RPi as a secondary mcu?

If you want to read the internal temperature of the RPI or use other functions such as an ADXL connected to the RPI GPIO Pins you need to install the RPi as secondary MCU on klipper

After installing Klipper, access via SSH and run:

cd ~/klipper/
sudo cp ./scripts/klipper-mcu.service /etc/systemd/system/
sudo systemctl enable klipper-mcu.service

Compile the new firmware to flash internally

cd ~/klipper/
make menuconfig

In the menu, set “Microcontroller Architecture” to “Linux process,” then save and exit.
To build / compile and install the new micro-controller code, run:

sudo service klipper stop
make flash
sudo service klipper start

If klippy.log reports a “Permission denied” error when attempting to connect to /tmp/klipper_host_mcu then you need to add your user to the tty group. The following command will add the “pi” user to the tty group:

sudo usermod -a -G tty pi

 

 

On the Next chapter we are to review the printer.cfg thoroughly, make a perfect first layer with nylock mod, adjust bed screws, z offset and probe calibration, PID tunning, changes to make on the slicer and first print.

Shopping Cart

COMING SOON

Nitehawk36