Klipper3d / klipper

Klipper is a 3d-printer firmware
GNU General Public License v3.0
8.95k stars 5.16k forks source link

sensors: add sht31 support #6560

Closed nefelim4ag closed 1 month ago

nefelim4ag commented 2 months ago

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

JamesH1978 commented 2 months ago

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

nefelim4ag commented 2 months ago

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?

TheFuzzyGiggler commented 1 month ago

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)
nefelim4ag commented 1 month ago

@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

KevinOConnor commented 1 month ago

Thanks.

-Kevin