rsc1975 / micropython-sht30

SHT30 sensor driver in pure python based on I2C bus
Apache License 2.0
46 stars 27 forks source link

SHT-30 alert functionality #2

Open tikky opened 4 years ago

tikky commented 4 years ago

Hello,

Thank you for this library. SHT30 sesnor comes with built-in alert pin which can be activated ex. if humidity is higher then set.

Details 3.5 (page 9) of datasheet: https://www.mouser.com/datasheet/2/682/Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital-971521.pdf

Could you be so kind to add this functionality, to set the temp or humidity alert?

I mean something like function writeAlertData in this Arduino library: https://github.com/closedcube/ClosedCube_SHT31D_Arduino/blob/master/src/ClosedCube_SHT31D.cpp

fpgirard commented 2 years ago

Hi - great module - I'm sure a lot of folks are using it! Can I suggest some improvements? It's very easy to abstract out the I2C module and Pins and make this module more adaptable to other hardware:

  1. remove the import machine line
  2. abstract I2C to a bus:
    def __init__(self, **bus**, delta_temp = 0, delta_hum = 0, i2c_address=DEFAULT_I2C_ADDRESS): self.i2c = bus self.i2c_addr = i2c_address self.set_delta(delta_temp, delta_hum) time.sleep_ms(50)
  3. remove the I2C init function and let the app developer handle his/her own I2C stuff. Doing the above will also fix the deprecated I2C function which has been replaced by SoftI2C.

I've made the above changes to your code and it's working great on the newer Wemos/Lolin E32S2 Mini and Pico.