Flying Bear Ghost 6 with Macros

Configuration for Flying Bear Ghost 6.

To make it easy to use “plug and play” the Raspberry is connected to the controller via USB and the stepper drivers (TMC2225/2208) are configured in “Standalone” mode.
This allows you to use the printer without having to make any hardware modifications.
However, the display will remain black as a downside.

Pause, Resume and Cancel macros are by default in mansail.cfg

PURGE BLOB Macro
LEVELING Macro
CENTER XYZ Macro
UNLOAD FILAMENT Macro
LOAD FILAMENT Macro

To initiate the heating of both the build plate and extruder simultaneously, you can use the following Start G-Code:

SuperSlicer

M140 S[first_layer_bed_temperature] ; set bed temp
M104 S{first_layer_temperature[initial_extruder]+extruder_temperature_offset[initial_extruder]} ; set hotend temp
START_PRINT
M190 S[first_layer_bed_temperature] ; wait for bed
M109 S{first_layer_temperature[initial_extruder]+extruder_temperature_offset[initial_extruder]} ; wait for hotend

CURA

M140 S{material_bed_temperature_layer_0} ; set bed temp
M104 S{material_print_temperature_layer_0} ; set hotend temp
START_PRINT
M190 S{material_bed_temperature_layer_0} ; wait for bed
M109 S{material_print_temperature_layer_0} ; wait for hotend

#####################################################################
#####################################################################
#   Flying Bear GHOST 6   MKS Nano4 V3.1 Controller Board
#####################################################################
#####################################################################

#####################################################################
#   Printer Settings
#####################################################################

[mcu]
#serial: /dev/serial/by-id/usb-Klipper_stm32f407xx_3A0051000E50475532323720-if00
restart_method: command

[printer]
kinematics: corexy
square_corner_velocity: 5.0
max_velocity: 150
max_accel: 3000
max_accel_to_decel: 1000
max_z_velocity: 10
max_z_accel: 100

[filament_switch_sensor filament_detection]
pause_on_runout: True
switch_pin: PA4

[temperature_sensor mcu_temp]
sensor_type: temperature_mcu
min_temp: 0
max_temp: 80

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

[output_pin Light]
pin: !PE6
value: 1

#[input_shaper]
#shaper_freq_x: 39.4
#shaper_type_x: mzv
#shaper_freq_y: 39.4
#shaper_type_y: mzv


#####################################################################
#   Stepper motors Settings
#####################################################################

[stepper_x]
step_pin: PE3
dir_pin: !PE2
enable_pin: !PE4
microsteps: 16
rotation_distance: 20
endstop_pin: !PA15
position_endstop: -2
position_min:-2
position_max: 255
homing_speed: 80

[stepper_y]
step_pin: PE0
dir_pin: !PB9
enable_pin: !PE1
microsteps: 16
rotation_distance: 20
endstop_pin: !PD2
position_endstop: -2
position_min:-2
position_max: 210
homing_speed: 80

[stepper_z]
step_pin: PB5
dir_pin: !PB4
enable_pin: !PB8
microsteps: 32
rotation_distance: 8
endstop_pin: !PC8
homing_speed: 30
second_homing_speed: 2
position_min: -5
position_max: 210
position_endstop: 0

[extruder]
step_pin: PD6
dir_pin: PD3
enable_pin: !PB3
heater_pin: PE5
sensor_pin: PC1
microsteps: 32
rotation_distance: 15.3983016
nozzle_diameter: 0.400
filament_diameter: 1.75
sensor_type: NTC 100K MGB18-104F39050L32
control: pid
pid_Kp: 12.306
pid_Ki: 0.398
pid_Kd: 95.063
min_temp: 0
max_temp: 280
min_extrude_temp: 185
max_extrude_cross_section: 25
#pressure_advance = 0.02
#pressure_advance_smooth_time: 0.02


#####################################################################
#   Buildplate Settings
#####################################################################

[heater_bed]
heater_pin: PA0
sensor_type: NTC 100K MGB18-104F39050L32
sensor_pin: PC0
control: pid
pid_Kp: 66.052
pid_Ki: 1.483
pid_Kd: 735.659
min_temp: 0
max_temp: 120

[bed_screws]
screw1: 28,31
screw1_name: front left screw
screw2: 228,31
screw2_name: front right screw
screw3: 228,181
screw3_name: back right screw
screw4: 28,181
screw4_name: back left screw
speed: 100


#####################################################################
#   Cooling Settings
#####################################################################

[heater_fan nozzle_fan]
heater: extruder
heater_temp: 50
shutdown_speed: 1.0
fan_speed: 1.0
pin: PC14

[fan] #Print Cooling Blower Fans
pin: PB1

[fan_generic Chamber_Fan]
pin:PB0
kick_start_time: 0.1
max_power: 1.0


#####################################################################
#   Macros
#####################################################################


#########################
### RESET SPEEDS
#########################

[gcode_macro _RESETSPEEDS]
gcode:
    SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} 
    SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}  
    SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel} 
    SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer.configfile.settings.printer.square_corner_velocity} 


#########################
### START PRINT
#########################

# START_PRINT need to be mentioned in Slicer Start G-Code

[gcode_macro START_PRINT]
gcode:
    _RESETSPEEDS
    {% if printer.toolhead.homed_axes != "xyz" %}
    M117 Homing...
    G28
    {% endif %}
    G90
    G92 E0
    

#########################
### END PRINT
#########################

# END_PRINT need to be mentioned in Slicer End G-Code

[gcode_macro END_PRINT]
gcode:
    _RESETSPEEDS
    M140 S0
    M104 S0
    M106 S0
    M107
    G91
    G1 E-0.6 F60
    G1 Z3 F300
    G90
    G1 X0 Y210 F3000
    M84
    SET_FAN_SPEED FAN=Chamber_Fan SPEED=0 DURATION=120
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00
    SET_PIN PIN=Light VALUE=0.00
    SET_PIN PIN=Light VALUE=1.00


#########################
### PURGE BLOB
#########################

[gcode_macro PURGE_BLOB]
gcode:
    _RESETSPEEDS
    {% if printer.toolhead.homed_axes != "xyz" %}
    M117 Homing...
    G28
    {% endif %}
    {% set rand_pos = (30 + ( printer.system_stats.cputime * 1000 ) % 60) %}
    M117 Purging at X{ rand_pos }
    G92 E0                          ; zero the extruder
    G90                             ; absolute positioning
    G1 X{ rand_pos } Y10 Z1 F5000   ; Go to start pos for perge line
    G1 Z0.4 F600                    ; Lower to purge height
    G91                             ; relative positioning
    G1 X4 E40 F40                   ; Extrude blob of filament on the bed
    M106 P0                         ; Enable Cooling Fan
    G1 X20 Z5 F100                  ; Slow drag away from the blob with fans helping cool and break strings. Also raiz z zo the blob clears the fan duct
    G1 X5  Z-5.2 F3000              ; Now that the blob has cleared the duct we go back down for a short 0.2mm height extrusion
    G1 X5 E2 F180                   ; Slow 5mm extrude move to help with stringing
    G1 X30 E-1.4 F180               ; Fast move and retract to break strings and reduce ooze
    M106 P0 S0                      ; Disable Cooling Fan
    G92 E0                          ; zero the extruder
    G90                             ; absolute positioning
    G1 Y70 F5000
    G1 X5 F5000
    G1 Z0.4 F100


#########################
### BUILDPLATE LEVELING
#########################

[gcode_macro LEVELING]
gcode:
    _RESETSPEEDS
    BED_SCREWS_ADJUST


#########################
### UNLOAD FILAMENT
#########################

[gcode_macro UNLOAD_FILAMENT]
gcode:
    _RESETSPEEDS
    SAVE_GCODE_STATE NAME=UNLOADFILAMENT
    M83
    G1 E5 F120
    G1 E-6 F200
    G1 E-34 F900
    G1 E-50 F900
    M84 E
    RESTORE_GCODE_STATE NAME=UNLOADFILAMENT


#########################
### LOAD FILAMENT
#########################

[gcode_macro LOAD_FILAMENT]
gcode:
    _RESETSPEEDS
    SAVE_GCODE_STATE NAME=LOADFILAMENT
    M83
    G1 E50 F600
    G1 E30 F200
    G1 E6 F120
    RESTORE_GCODE_STATE NAME=LOADFILAMENT


#########################
### CENTER XYZ
#########################

[gcode_macro CENTER_XYZ]
gcode:
    _RESETSPEEDS
    SAVE_GCODE_STATE NAME=CENTER_XYZ
    {% if printer.toolhead.homed_axes != "xyz" %}
    M117 Homing...
    G28
    {% endif %}
    G90
    G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_maximum.y/2} Z{printer.toolhead.axis_maximum.z/2} F9000    
    M84
    RESTORE_GCODE_STATE NAME=CENTER_XYZ


#####################################################################
#   include's
#####################################################################
#Pause/Resume/Cancel/... are by default in mansail.cfg

[include mainsail.cfg]

[exclude_object]

[virtual_sdcard]
path: /home/pi/printer_data/gcodes


#####################################################################