# This file contains common pin mappings for RAMBo boards. To use this
# config, the firmware should be compiled for the AVR atmega2560.

# See docs/Config_Reference.md for a description of parameters.
[gcode_macro CALIBRATE_NOZZLE_OFFSET]
description: Move to center of bed and calibrate nozzle offset
gcode:
  G90 
  G0 X100 Y155 F1500
  PROBE_CALIBRATE

[gcode_macro LEVEL_BED]
description: "Level the bed manually."
gcode:
  BED_SCREWS_ADJUST

[gcode_macro CHECK_DEVIATION]
description: "Check the deviation of the bed from the last loaded mesh."
gcode:
  SCREWS_TILT_CALCULATE MAX_DEVIATION=0.05

[gcode_macro LIZ_IS_A_BAKA]
description: "Liz is a baka, so here's her start G-Code >.<"
gcode:
  BED_MESH_CALIBRATE
  BED_MESH_PROFILE SAVE=default

[gcode_macro _START_GCODE]
description: "The gcode that should be called from your slicer at the beginning of a print."
gcode:
  # Ender 3 Custom Start G-code
  G90
  G1 X2 Y30 Z30 F1500
  G1 Z0.28 F240
  G92 E0
  G1 Y220 E10 F1500 ; prime the nozzle
  G1 X2.3 F5000
  G92 E0
  G1 Y30 E10 F1200 ; prime the nozzle
  G92 E0
  G1 Z5 F1500 ; don't scratch the build plate

[gcode_macro _END_GCODE]
description: "The gcode that should be called from your slicer at the end of a print."
gcode:
  G91 # Relative positioning
  G1 E-2 F2700 # Retract a bit
  G1 E-2 Z0.2 F2400 # Retract and raise Z
  G1 X5 Y5 F3000 # Wipe out
  G1 Z10 # Raise Z more
  G90 # Absolute positioning
  
  G1 X0 Y220 # Present print
  M106 S0 # Turn-off fan
  M104 S0 # Turn-off hotend
  M140 S0 # Turn-off bed
  
  M84 X Y E # Disable all steppers but Z

[stepper_x]
step_pin: PC0
dir_pin: PL1
enable_pin: !PA7
microsteps: 16
# rotation_distance: 40 # Default, seems 3mm short on a 10mm move
# rotation_distance: 28 # Test 1, seems to move 1-2mm too far
# rotation_distance: 30 # Test 2, seems to move 1mm too far
rotation_distance: 33
endstop_pin: ^!PB6
#endstop_pin: ^PA2
position_endstop: 0
position_max: 298
homing_speed: 50

[stepper_y]
step_pin: PC1
dir_pin: !PL0
enable_pin: !PA6
microsteps: 16
# rotation_distance: 40 # Default, Seems 4mm overshot
# rotation_distance: 42 # Test 1, Still seems 3-4mm overshot
rotation_distance: 46
endstop_pin: ^!PB5
#endstop_pin: ^PA1
position_endstop: 0
position_max: 280
homing_speed: 50

[stepper_z]
step_pin: PC2
dir_pin: PL2
enable_pin: !PA5
microsteps: 16
# rotation_distance: 8 # Default, seems 1mm too short
# rotation_distance: 7.2 # Test 1, seems 3mm overshot
# rotation_distance: 8.33 # Test 2, still seems 1mm under
rotation_distance: 8
endstop_pin: probe:z_virtual_endstop
#endstop_pin: !PB4
#endstop_pin: ^PC7
# position_endstop: 0.5
position_max: 250

[bltouch]
sensor_pin: ^PB4
control_pin: PL5
x_offset: -44
y_offset: 8
z_offset: 3.0

[bed_mesh]
speed: 120
horizontal_move_z: 7
mesh_min: 30, 40
mesh_max: 250, 230
probe_count: 5
mesh_pps: 3
algorithm: bicubic

[safe_z_home]
home_xy_position: 140, 140
speed: 50
z_hop: 10
z_hop_speed: 5

[extruder]
step_pin: PC3
dir_pin: !PL6
enable_pin: !PA4
microsteps: 16
# rotation_distance: 33.500 # Original Setting, seems ??x too small
# rotation_distance: 16.75 # Initial test, seems to extrude 1/2 supposed
# rotation_distance: 8.375 # Test Two, still seems 1/2
# rotation_distance: 4.25 # Old Extruder Setup
rotation_distance: 7.9797 # Copied from Replimat
nozzle_diameter: 0.400
heater_pin: PH6
# filament_diameter: 2.850
filament_diameter: 1.750
# sensor_type: EPCOS 100K B57560G104F # Either it's not connecting right, or this is the wronf sensor
sensor_type: NTC 100K MGB18-104F39050L32 # Probably just disconnected
sensor_pin: PF0
#control: pid
#pid_Kp: 22.2
#pid_Ki: 1.08
#pid_Kd: 114
min_temp: 0
max_temp: 990

#[extruder1]
#step_pin: PC4
#dir_pin: PL7
#enable_pin: !PA3
#heater_pin: PH4
#sensor_pin: PF1
#...

[heater_bed]
heater_pin: PE5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PF2
control: watermark
min_temp: 0
max_temp: 130
max_power: 1.0

[verify_heater heater_bed]
heating_gain: 1
check_gain_time: 60

[fan]
pin: PH3

[heater_fan heatbreak_cooling_fan]
pin: PH5

[mcu]
serial: /dev/serial/by-id/usb-UltiMachine__ultimachine.com__RAMBo_6403335373035101E171-if00
baud: 250000

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

[ad5206 stepper_digipot]
enable_pin: PD7
# Scale the config so that the channel value can be specified in amps.
# (For Rambo v1.0d boards, use 1.56 instead.)
scale: 2.08
# Channel 1 is E0, 2 is E1, 3 is unused, 4 is Z, 5 is X, 6 is Y
channel_1: 1.34
channel_2: 1.0
channel_4: 1.1
channel_5: 1.1
channel_6: 1.1

# Enable 16 micro-steps on steppers X, Y, Z, E0, E1
[static_digital_output stepper_config]
pins:
    PG1, PG0,
    PK7, PG2,
    PK6, PK5,
    PK3, PK4,
    PK1, PK2

[static_digital_output yellow_led]
pins: !PB7

# Common EXP1 / EXP2 (display) pins
[board_pins]
aliases:
    # Common EXP1/EXP2 headers found on RAMBo v1.4
    EXP1_1=PE6, EXP1_3=PG3, EXP1_5=PJ2, EXP1_7=PJ7, EXP1_9=<GND>,
    EXP1_2=PE2, EXP1_4=PG4, EXP1_6=PJ3, EXP1_8=PJ4, EXP1_10=<5V>,
    # EXP2 header
    EXP2_1=PB3, EXP2_3=PJ5, EXP2_5=PJ6, EXP2_7=PD4, EXP2_9=<GND>,
    EXP2_2=PB1, EXP2_4=PB0, EXP2_6=PB2, EXP2_8=PE7, EXP2_10=PH2
    # Pins EXP2_1, EXP2_6, EXP2_2 are also MISO, MOSI, SCK of bus "spi"

# See the sample-lcd.cfg file for definitions of common LCD displays.
[include mainsail.cfg]

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bltouch]
#*# z_offset = 2.288
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 	-1.065000, -0.857500, -0.817500, -0.865000, -0.927500
#*# 	-0.592500, -0.502500, -0.442500, -0.482500, -0.522500
#*# 	-0.172500, -0.070000, -0.027500, -0.040000, -0.057500
#*# 	0.182500, 0.265000, 0.312500, 0.302500, 0.332500
#*# 	0.480000, 0.610000, 0.670000, 0.715000, 0.735000
#*# x_count = 5
#*# y_count = 5
#*# mesh_x_pps = 3
#*# mesh_y_pps = 3
#*# algo = bicubic
#*# tension = 0.2
#*# min_x = 30.0
#*# max_x = 250.0
#*# min_y = 39.989999999999995
#*# max_y = 230.0
#*#
#*# [extruder]
#*# control = pid
#*# pid_kp = 23.769
#*# pid_ki = 1.248
#*# pid_kd = 113.201
