Close

Advanced Klipper Configuration and Patching

A project log for Not Just a Reflow Oven

Making a GCode controlled Toaster Oven with Klipper and Octoprint.

clearchrisclearchris 05/14/2020 at 01:430 Comments

So far, we have an oven, one heater configured, PID tuned and ready to go.  It's able to hold steady at low temperatures for use cases like dehydrating 3d printing filament.  But we have more heaters, and we need to also use those for other uses like reflow.  Let's add to our configuration and use all the heaters at once.  (Hell yeah!)

First we add the other mechanical relay module pins to the config.  This should look familiar from earlier.

[output_pin resistive_top]
pin: ar2
pwm: false
value: 1
shutdown_value: 1
hardware_pwm: false

[output_pin halogen_bottom]
pin: ar8
pwm: false
value: 1
shutdown_value: 1
hardware_pwm: false

[output_pin resistive_bottom]
pin: ar7
pwm: false
value: 1
shutdown_value: 1
hardware_pwm: false

 Also a gcode macro to handle configuring the pins

[gcode_macro setup_full_halogen_resistive]
gcode:
    TURN_OFF_HEATERS
    SET_PIN PIN=resistive_bottom VALUE=0
    SET_PIN PIN=resistive_top VALUE=0
    SET_PIN PIN=halogen_bottom VALUE=0
    SET_PIN PIN=halogen_top VALUE=0
    G4 P500

Remember, low means on when using some of these relay modules.

Now on to add a new "generic_heater".

[heater_generic fullhalogenresistive]
gcode_id: T1
heater_pin: ar5
sensor_type: MAX6675
sensor_pin: PB2
spi_software_sclk_pin: PB5
#CHRIS:  hardware spi requires mosi pin on chip that has none
spi_software_mosi_pin: PB3
spi_software_miso_pin: PB4
spi_speed: 100000
control = pid 
pid_Ki=2.047 
pid_Kd=352.665
pid_Kp=200
min_temp: 0
max_temp: 300

Note the gcode_id of T1.  We are specifying that this heater is "tool 1" instead of "tool 0" like the prior one.  This allows us to graph it in OctoPrint, after editing the "Printer Configuration" and specifying that the machine has two tools/hotends.  The graph can get a bit messy if you add many tools, so only add what you think you need.

Don't forget to add a "verify_heater" section, though at full blast, you may be OK with the default settings.

Now, if you reload, klipper will complain that your configuration is invalid, because you are sharing pins with your temperature sensor and your heater.  This is an valid safety feature, that I disabled.

Here be dragons.

Klipper has a feature implemented whereby some devices can share a pin.  I took advantage of this, and changed five lines to get this working.

My local git of klipper is at commit bf6f84b82d5942cf8a854a39a88826e7d11e1be9 and here is my patch that disables the pin sharing for heaters and the SPI bus.  The Klipper code base moves VERY fast and I wouldn't even guarantee that this patch would work if you did a git clone as of the time of this writing.

https://cdn.hackaday.io/files/1716197342547296/burn_your_house_down.patch

Depending on your sensor selection (anything not SPI) this might not work for you.  But the fix is pretty simple, read the code backtrace when klipper gives the error message.

Ok, since we have thoroughly voided our warranty, what can we now do?

We can now set up multiple pid settings for different heater configurations, which is essential.  You shouldn't use the pid parameters for one heater when you turn on all the heaters.

We can also set up different pid loops for different situations.  The most sailent situation I can think of is if you have a particularly touchy chip, you could use two different PID loops on the same set of heaters, one for aggressive heating, and another more conservative PID loop for holding at a temperature.

Discussions