From a074af7c871633f2fad5dd207f9945a020a0cde5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 5 Mar 2020 11:46:01 -0500 Subject: [PATCH] adc_temperature: Add builtin definition for PT1000 sensors Signed-off-by: Kevin O'Connor --- config/example-extras.cfg | 13 +++++++++++++ klippy/extras/adc_temperature.py | 14 ++++++++++++-- test/klippy/temperature.cfg | 4 ++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index 1ff7c10b..eee10fd5 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -874,6 +874,19 @@ #voltage_offset: 0 # The ADC voltage offset (in Volts). The default is 0. +# Directly connected PT1000 sensor. The following parameters are +# available in heater sections that use one of these sensors. +#[extruder] +# See the "extruder" section in example.cfg for a description of +# heater parameters. The parameters below describe sensor parameters. +#sensor_type: PT1000 +#sensor_pin: +# Analog input pin connected to the sensor. This parameter must be +# provided. +#pullup_resistor: 4700 +# The resistance (in ohms) of the pullup attached to the sensor. The +# default is 4700 ohms. + # Custom thermistors (one may define any number of sections with a # "thermistor" prefix). A custom thermistor may be used in the # sensor_type field of a heater config section. (For example, if one diff --git a/klippy/extras/adc_temperature.py b/klippy/extras/adc_temperature.py index 7a4cc8d2..0ec13776 100644 --- a/klippy/extras/adc_temperature.py +++ b/klippy/extras/adc_temperature.py @@ -132,7 +132,7 @@ class LinearResistance: def __init__(self, config, samples): self.pullup = config.getfloat('pullup_resistor', 4700., above=0.) try: - self.li = LinearInterpolate(samples) + self.li = LinearInterpolate([(r, t) for t, r in samples]) except ValueError as e: raise config.error("adc_temperature %s in heater %s" % ( str(e), config.get_name())) @@ -156,7 +156,7 @@ class CustomLinearResistance: if t is None: break r = config.getfloat("resistance%d" % (i,)) - self.samples.append((r, t)) + self.samples.append((t, r)) def create(self, config): lr = LinearResistance(config, self.samples) return PrinterADCtoTemperature(config, lr) @@ -266,6 +266,11 @@ PT100 = [ (1000, 4.48), (1100, 4.73) ] +PT1000 = [ + (0., 1000.), (100., 1385.1), (200., 1758.6), (300., 2120.5), + (400., 2470.9), (500., 2809.8), +] + def load_config(config): # Register default sensors pheater = config.get_printer().lookup_object("heater") @@ -278,6 +283,11 @@ def load_config(config): func = (lambda config, params=params: PrinterADCtoTemperature(config, LinearVoltage(config, params))) pheater.add_sensor_factory(sensor_type, func) + for sensor_type, params in [("PT1000", PT1000)]: + func = (lambda config, params=params: + PrinterADCtoTemperature(config, + LinearResistance(config, params))) + pheater.add_sensor_factory(sensor_type, func) def load_config_prefix(config): if config.get("resistance1", None) is None: diff --git a/test/klippy/temperature.cfg b/test/klippy/temperature.cfg index 83e5efa4..36570c3e 100644 --- a/test/klippy/temperature.cfg +++ b/test/klippy/temperature.cfg @@ -129,6 +129,10 @@ resistance3: 3000 sensor_type: my_custom_resistance_adc sensor_pin: analog5 +[temperature_sensor test_PT1000] +sensor_type: PT1000 +sensor_pin: analog9 + [controller_fan test_controller_fan] pin: ar17