Hello,
I believe I managed to make the chamber heater work with the DS18B20 sensor with only little changes in the code.
- Change to heaters.py
######################################################################
# Heater
######################################################################
+SLOW_SENSOR_THRESHOLD = 1.0
+MAX_DURATION_SLOW_SENSOR = 25
KELVIN_TO_CELSIUS = -273.15
MAX_HEAT_TIME = 5.0
AMBIENT_TEMP = 25.
@@ -53,7 +54,10 @@ class Heater:
pwm_cycle_time = config.getfloat('pwm_cycle_time', 0.100, above=0.,
maxval=self.pwm_delay)
self.mcu_pwm.setup_cycle_time(pwm_cycle_time)
- self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
+ if(self.sensor.get_report_time_delta() >= SLOW_SENSOR_THRESHOLD):
+ self.mcu_pwm.setup_max_duration(MAX_DURATION_SLOW_SENSOR)
+ else:
+ self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
- printer.cfg:
[mcu rpi]
serial: /tmp/klipper_host_mcu
[heater_generic heater_chamber]
heater_pin: rpi:gpio23
sensor_type: DS18B20
serial_no: 28-186b5e1e64ff
control: watermark
max_delta: 2.0
sensor_mcu: rpi
min_temp: 0
max_temp: 100
ds18_report_time: 1.0
pwm_cycle_time: 1.0
[verify_heater heater_chamber]
max_error: 300
check_gain_time:480
hysteresis: 5
heating_gain: 1
- Klipper macros:
[gcode_macro SET_HEATER_TEMPERATURE_AND_WAIT]
description: Set heater temperature and wait for temperature to be reached
gcode:
#Parameters
{% set heater = params.HEATER %}
{% set target_temp = params.TARGET|float %}
SET_HEATER_TEMPERATURE HEATER={heater} TARGET={target_temp}
{% if target_temp != 0 %}
TEMPERATURE_WAIT SENSOR="heater_generic {heater}" MINIMUM={target_temp} ; Wait for bed temp (within 1 degree)
{% endif %}
[gcode_macro PRINT_START]
gcode:
# Parameters
{% set bedtemp = params.BED|int %}
{% set hotendtemp = params.HOTEND|int %}
{% set chambertemp = params.CHAMBER|default(0)|int %}
# Other variables
{% set bedtempSlicer = bedtemp %}
{% set bedtempRange = 10 %}
{% set maxVelocity = printer.configfile.settings.printer.max_velocity|default(200)|int %}
{% set maxVelocityAdjusted = (0.90 * maxVelocity * 60)|int %}
{% if printer.configfile.settings.safe_z_home %}
{% set startX = printer.configfile.settings.safe_z_home.home_xy_position[0]|float %}
{% set startY = printer.configfile.settings.safe_z_home.home_xy_position[1]|float %}
{% endif %}
{% set bedtempAlmost = ((bedtemp - 2, 0, printer.heater_bed.temperature|int)|max, bedtemp)|max %}
{% set hotendtempStepOne = ((hotendtemp, printer[printer.toolhead.extruder].temperature|int)|min, 150)|max %}
{% set hotendtempStepTwo = ((hotendtemp, printer[printer.toolhead.extruder].temperature|int)|min, 170)|max %}
# If bed-temp-almost is higher than bed-temp by a maximum of 10C
{% if bedtempAlmost > bedtemp %}
{% if (bedtempAlmost - bedtempRange) <= bedtemp %}
{% set bedtemp = bedtempAlmost %}
{% endif %}
{% endif %}
BED_MESH_PROFILE LOAD=default ; NOTE if not using a mesh, comment out this line
ADJUST_FILAMENT_SENSOR_STATUS ENABLE=1
G90 ; absolute positioning
SET_HEATER_TEMPERATURE HEATER=heater_chamber TARGET={chambertemp} ; set and don't wait for chamber temp
M140 S{bedtempAlmost} ; set & don't wait for bed temp
M104 S{hotendtempStepOne} ; set & don't wait for hotend temp
G28 X Y Z
{% if printer.configfile.settings.safe_z_home %}
G1 X{startX} Y{startY} F{maxVelocityAdjusted}
{% endif %}
M190 S{bedtempAlmost} ; set & wait for bed temp
M104 S{hotendtempStepTwo} ; set & don't wait for hotend temp
M190 S{bedtemp} ; set & wait for bed temp
M140 S{bedtempSlicer} ; set & don't wait for bed temp ; set temp to sliced setting regardless
M104 S{hotendtemp} ; set & don't wait for hotend temp
G28 Z ; final z homing
G1 X0 Y0 F{maxVelocityAdjusted}
M109 S{hotendtemp} ; set & wait for hotend temp
SET_HEATER_TEMPERATURE_AND_WAIT HEATER=heater_chamber TARGET={chambertemp} ; set and wait for chamber temp
G1 Z20 F3000 ; move nozzle away from bed
- Machine G-Code in OrcaSlicer:
PRINT_START BED=[first_layer_bed_temperature] HOTEND={first_layer_temperature[initial_extruder]} CHAMBER=[chamber_temperature]
I was able to set a temperature in the filament settings, slice the part, start the print on the printer. The heater starts and the print starts only after the temperature is reached.
I was able to print a OrcaCube until the end with a set temperature of 40°C as a test.
I will test further but it seems to be working as expected.
USE AT YOUR OWN RISK.