klipper icon indicating copy to clipboard operation
klipper copied to clipboard

sensors: add sht31 support

Open nefelim4ag opened this issue 10 months ago • 1 comments

I don't know why no one added this before, because Klipper already has an SHT2x family So I got one and implemented support.

Hope it will be useful.

Thanks!


My current motivation: I have BME* family for the chamber and SHT because wider temperature support will be used for the filament hot box/dryer, I can and will heat it to 110 C, and support for humidity will help in that case. /* And SHT3x/SHT4x are easier to get nowadays */

Datasheet

nefelim4ag avatar Apr 11 '24 01:04 nefelim4ag

Thank you for submitting a PR, pleas refer to point 3 in "What to expect in a review" in https://github.com/Klipper3d/klipper/blob/master/docs/CONTRIBUTING.md and provide a signed off by line.

Thanks James

JamesH1978 avatar Apr 11 '24 07:04 JamesH1978

Just notice, I have tried to use a macro like "QUERY_SHT3X" and looks like a console from Fluidd just ignores the last 'X' and shows errors like:

Unknown command 'QUERY_SHT3'

Maybe if Klipper internally has some sort of special handling of trailing 'X' The module named with X on End is not perfect?

nefelim4ag avatar Apr 16 '24 11:04 nefelim4ag

I might be blind but I don't see anywhere you implement the GCode command

class SHT3X:
    def __init__(self, config):
        self.printer = config.get_printer()
        self.name = config.get_name().split()[-1]
        self.reactor = self.printer.get_reactor()
        self.i2c = bus.MCU_I2C_from_config(
            config, default_addr=SHT3X_I2C_ADDR, default_speed=100000)
        self.report_time = config.getint('sht3x_report_time', 1, minval=1)
        self.deviceId = config.get('sensor_type')
        self.temp = self.min_temp = self.max_temp = self.humidity = 0.
        self.sample_timer = self.reactor.register_timer(self._sample_sht3x)
        self.printer.add_object("sht3x " + self.name, self)
        self.printer.register_event_handler("klippy:connect",
                                            self.handle_connect)

You need to have something like

self.gcode.register_command('QUERY SH3X', self.cmd_QUERY_SHT3X,
           desc=self.cmd_QUERY_SHT3X_help)

and then define it

cmd_QUERY_SHT3X_help = ("Queries the values from the SHT3X Temp/Humidity Sensor")
def cmd_QUERY_SHT3X(self,gcmd):
     etime = self.reactor.monotonic()
     return self._sample_sht3x(etime)

TheFuzzyGiggler avatar Apr 19 '24 13:04 TheFuzzyGiggler

@TheFuzzyGiggler I mean something like this: https://github.com/Klipper3d/klipper/blob/2425a74638baa87efef3ca02253804d126101c8a/docs/Command_Templates.md?plain=1#L175

The same copy-paste macro for this sensor has been dropped by request of @KevinOConnor above.


So, I'm talking about trying to define a similar gcode macro. image image

nefelim4ag avatar Apr 20 '24 16:04 nefelim4ag

Thanks.

-Kevin

KevinOConnor avatar Apr 20 '24 22:04 KevinOConnor

Humidity is not displayed image

Murrdo avatar Jun 21 '24 18:06 Murrdo

@Murrdo which version of Klipper are you running? What does your macro look like?

From my point of view, this is an impossible error.

    def get_status(self, eventtime):
        return {
            'temperature': round(self.temp, 2),
            'humidity': round(self.humidity, 1),
        }

I think you have a typo in the macro, recheck the macro against other sensor examples.

nefelim4ag avatar Jun 22 '24 20:06 nefelim4ag