SHT3x - Temperature and rH

Description

Library for SHT3x family (SHT30, SHT31, SHT33, SHT35) of I2C temperature and relative humidity sensors.

The SHT3x is a fully calibrated, linearised and temperature compensated temperature and humidity sensor.

  • I2C interface with communication speed up to 1 MHz
  • Two user selectable addresses (chosen by chip pin)
  • Temperature range: -40 to 125°C ±0.2°C (SHT33: ±0.48°C, SHT35: ±0.1°C)
  • Relative humidity range: 0..100%rH ±2%rH (SHT35: ±1.5%rH)

OVERVIEW

SHT3x_Ab1stract:
This library can be used to handle SHT3x family (SHT30, SHT31, SHT33, SHT35) I2C temperature and relative humidity sensors.

Interfaces: 1x I2C

The SHT3x is a fully calibrated, linearised and temperature compensated temperature and humidity sensor.
  • I2C interface with communication speed up to 1 MHz
  • Two user selectable addresses (chosen by chip pin)
  • Temperature range: -40 to 125°C ±0.2°C (SHT33: ±0.48°C, SHT35: ±0.1°C)
  • Relative humidity range: 0..100%rH ±2%rH (SHT35: ±1.5%rH)
  • At least firmware version 01v012 is required for use with a rapidM2M M23.
    SHT3x_How_to_use:
    /* Hardware setup - as used on the "rapidM2M Base Starter" */ const { PORT_I2C = 0, // The first I2C interface should be used. ADDRPIN = 0, // Logic level of the chip's address pin // (either 0^="Low" or 1=^"High") } /* Control structures for available sensors */ static sht3x[TSHT3x]; // Control structure to manage the SHT3x /* 1 sec. timer is used for the general program sequence */ #callback MainTimer() { // Init with "open loop" value to identify missing measurements // (temp/rH simply stay unchanged in case of an error) static temp_ = S32_OL; // Temperature read from the SHT31 static rh_ = S32_OL; // Humidity read from the SHT31 new err= SHT3x_read( sht3x, temp_, rh_); // reads the measured values ​​from the SHT3x // Issues temperature, humidity and return value of the SHT3x_read function via the watch panel #watch( "temp_rh=%s°C %s%% %s", s32ToNamurStr( temp_,1), s32ToNamurStr( rh_), errorToStr( err)); } /* Application entry point */ main() { // Inits the I2C interface catch( rM2M_I2cInit( PORT_I2C, SHT3x_CLOCK, 0)); // Inits SHT3x and starts first measurement ("SHT3x_MODE_INTERLACED" is the default mode) catch( SHT3x_open( sht3x, PORT_I2C, ADDRPIN)); // Initialisation of a cyclic sec. timer setInterval(MainTimer, 1000); }

    BASIC

    SHT3x_CLOCK -

    typical I2C clock speed to be used

    SHT3x_MODE_x:

    operation mode for SHT3x

    SHT3x_MODE_INTERLACED - interlaced on-demand measurements (default: High quality)
    The first capture starts with SHT3x_open(), then immediately after each SHT3x_read().
  • Plus: No need to wait for results, capture cycle fits automatically to read frequency (lowers power consumption)
  • Minus: Captures may be out dated if read interval is quite long
  • Best to use with read intervals of 1..15s
  • SHT3x_MODE_INST - instant on-demand measurements (default: Low quality)
    Measurement is captured in front of each SHT3x_read().
  • Plus: Values are up-to-date
  • Minus: Waiting time during each SHT3x_read() which takes CPU cycles and power - see SHT3x_MODE_Qx flags below for timing
  • Best to use for very long read intervals >10s
  • SHT3x_MODE_CONT_100 - continous background measurement with 100ms period (default: Low quality)
    SHT3x_MODE_CONT_250 - continous background measurement with 250ms period (default: Medium quality)
    SHT3x_MODE_CONT_500 - continous background measurement with 500ms period (default: High quality)
    SHT3x_MODE_CONT_1000 - continous background measurement with 1000ms period (default: High quality)
    SHT3x_MODE_CONT_2000 - continous background measurement with 2000ms period (default: High quality)

    Applies to all SHT3x_MODE_CONT_x modes:
    Measurements are captured periodically in the background. The SHT3x_read() simply reads the last captured values.
    The SHT3x_MODE_CONT_x must be shorter than the read interval - otherwise SHT3x_read() may fail with ERROR_DONE.
  • Plus: Values are up-to-date without any waiting time in SHT3x_read()
  • Minus: Maximum power consumption by the chip
  • Best to use for long or varying read intervals if power consumption is not an affair

  • Applies to all modes:
    Quality flags (SHT3x_MODE_Qx) can optionally be used to choose another than the default quality
    SHT3x_open( ..., SHT3x_MODE_CONT_500 | SHT3x_MODE_QL)

    Example in SHT3x_How_to_use
    SHT3x_MODE_CONT_x:

    see SHT3x_MODE_x

    SHT3x_MODE_Qx:

    Flags to specify the quality for the measurements of the SHT3x

    The Quality flags can optionally be used to select a quality other than the default quality specified for the selected operation mode (SHT3x_MODE_x).
    SHT3x_open( ..., SHT3x_MODE_CONT_500 | SHT3x_MODE_QL)
    SHT3x_MODE_QL - low repeatability of typ. 0.15 °C / 0.21 %rH,
    <4ms duration
    SHT3x_MODE_QM - medium repeatability of typ. 0.08 °C / 0.15 %rH,
    <6ms duration
    SHT3x_MODE_QH - high repeatability of typ. 0.04 °C / 0.08 %rH,
    <15ms duration
    SHT3x_open(sht3x, i2c, addrpin, mode=SHT3x_MODE_INTERLACED)

    initializes the SHT3x


    Reads serial number and starts measurement (if not SHT3x_MODE_INST chosen). If the SHT3x has already been initialized, beforehand any running measurements are stopped and a soft reset is performed.

    sht3x : TSHT3x - empty control block
    i2c : s32 - I2C interface where SHT3x is connected to
    The I2C interface must be initialisation before using rM2M_I2cInit().
    addrpin : TpinValue - Logic level at the chip's address pin (either 0 for "Low" or 1 for "High")
    0 - I2C address A (0x44) should be used
    1 - I2C address B (0x45) should be used
    mode - operation mode / quality flags ( SHT3x_MODE_x | SHT3x_MODE_Qx )
    returns : Terror
    ERROR - Invalid I2C interface or I2C interface not opened yet
    ERROR_DONE - NACK detected (i.e. SHT3x not ready)
  • Failed to close SHT3x
  • Measurement could not be started
  • The serial number could not be read
  • ERROR_CRC - CRC check failed
    ERROR_TIMEOUT - Timeout when accessing the SHT3x
    < OK - If another error occurs
    Example in SHT3x_How_to_use
    SHT3x_close(sht3x[TSHT3x])

    closes SHT3x and grants minimum power consumption

    It stops any periodic measurement and performs a soft reset. The soft reset also turns off the heater.

    sht3x : TSHT3x - Control block of a specific SHT3x (Initialized by SHT3x_open() )
    returns : s32
    OK - if successful
    ERROR_DONE - NACK detected (i.e. SHT3x not ready)
    ERROR_CRC - CRC check failed
    ERROR_TIMEOUT - Timeout when accessing the SHT3x
    < OK - If another error occurs
    SHT3x_read(sht3x, &temp, &rh)

    reads the measured values ​​from the SHT3x.

    SHT3x_Ab1stract for range and resolution.
    Depending on the operating mode (SHT3x_MODE_x) set using SHT3x_open(), further actions are carried out:
  • SHT3x_MODE_INTERLACED - A new measurement is triggered after reading
  • SHT3x_MODE_INST - The measurement will be triggered before reading. The function then waits until the measurement has been performed. Only then can the measured values be returned.

  • sht3x : TSHT3x - Control block of a specific SHT3x (Initialized by SHT3x_open() )
    temp : s32 - [0.1°C] Buffer for the temperature, unchanged if result < OK
    rh : s32 - [1%] Buffer for the relative humidity, unchanged if result < OK
    returns : Terror
    OK - if successful
    ERROR_DONE - NACK detected (i.e. SHT3x not ready)
  • Measurement could not be started
  • No measurement data available (Either already read or SHT3x still busy with capturing)
    When using one of the SHT3x_MODE_CONT_x modes, choose a faster mode or expand the interval between SHT3x_read().
  • ERROR_CRC - Either one or both values had CRC errors and may not be updated
    ERROR_TIMEOUT - Timeout while waiting for the measurement to be completed in SHT3x_MODE_INST mode.
    ERROR_CLOSED - No operating mode set
    < OK - If another error occurs
    Example in SHT3x_How_to_use

    EXPERT

    SHT3x_CLOCK_MAX -

    absolute maximum I2C clock speed

    SHT3x_STATUS_x:

    result flags for SHT3x_readStatus()

    SHT3x_STATUS_ALERT - bit 15: Alert pending status
    0 - no pending alerts
    1 - at least one pending alert
    SHT3x_STATUS_HEATER - bit 13: Heater status
    0 - Heater OFF
    1 - Heater ON
    SHT3x_STATUS_ALERT_RH - bit 11: RH tracking alert
    0 - no alert
    1 - alert
    SHT3x_STATUS_ALERT_T - bit 10: T tracking alert
    0 - no alert
    1 - alert
    SHT3x_STATUS_RESET - bit 4: System reset detected
    0 - no reset detected since last ‘clear status register’ command
    1 - reset detected (hard reset, soft reset command or supply fail)
    SHT3x_STATUS_CMD_ERR - bit 1: Command status
    0 - last command executed successfully
    1 - last command not processed. It was either invalid, failed the integrated command checksum
    SHT3x_STATUS_WR_ERR - bit 0: Write data checksum status
    0 - checksum of last write transfer was correct
    1 - checksum of last write transfer failed
    SHT3x_readStatus(const sht3x[TSHT3x])

    reads status register of the SHT3x

    sht3x : TSHT3x - Control block of a specific SHT3x (Initialized by SHT3x_open() )
    returns : Terror
    >= 0 - SHT3x_STATUS_x flags
    ERROR_DONE - NACK detected (i.e. SHT3x not ready)
    ERROR_CRC - CRC check failed
    < OK - if another error occurs

    DEBUG

    SHT3x_dumpStatus(sht3x[TSHT3x], const prefix{}="SHT3x_dumpStatus", forceDump=0)

    issues current status (contents of the status register or errors when accessing the register) via the console if it has changed since the last call of this function

    sht3x : TSHT3x - Control block of a specific SHT3x (Initialized by SHT3x_open() )
    prefix : astr - Some text to print in front of the status
    forceDump : bool - Issue current status via the console ...
    true - in any case (if it changed or not)
    falese - only if it has changed since the last call
    returns : Terror
    >= 0 - SHT3x_STATUS_x flags
    ERROR_DONE - NACK detected (i.e. SHT3x not ready)
    ERROR_CRC - CRC check failed
    < OK - if another error occurs

    On this page

    SHT3x - Temperature and rH