Device Driver for Sensirion SHT30/SHT31/SHT35 Humidity and Temperature Sensors. More...

Detailed Description

Device Driver for Sensirion SHT30/SHT31/SHT35 Humidity and Temperature Sensors.

Author
Gunar Schorcht gunar.nosp@m.@sch.nosp@m.orcht.nosp@m..net

Definition in file sht3x.h.

#include <stdint.h>
#include <stdbool.h>
#include "periph/i2c.h"
+ Include dependency graph for sht3x.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sht3x_params_t
 SHT3x device initialization parameters. More...
 
struct  sht3x_dev_t
 SHT3x sensor device data structure. More...
 
#define SHT3X_I2C_ADDR_1   (0x44)
 possible I2C slave addresses More...
 
#define SHT3X_I2C_ADDR_2   (0x45)
 ADDR pin connected to VDD.
 
enum  sht3x_error_codes {
  SHT3X_OK, SHT3X_ERROR_I2C, SHT3X_ERROR_CRC, SHT3X_ERROR_STATUS,
  SHT3X_ERROR_MEASURE_CMD_INV
}
 Driver error codes (returned as negative values) More...
 
enum  sht3x_mode_t {
  SHT3X_SINGLE_SHOT = 0, SHT3X_PERIODIC_0_5_MPS, SHT3X_PERIODIC_1_MPS, SHT3X_PERIODIC_2_MPS,
  SHT3X_PERIODIC_4_MPS, SHT3X_PERIODIC_10_MPS
}
 SHT3x measurement modes. More...
 
enum  sht3x_repeat_t { SHT3X_HIGH = 0, SHT3X_MEDIUM, SHT3X_LOW }
 SHT3x repeatability levels. More...
 
int sht3x_init (sht3x_dev_t *dev, const sht3x_params_t *params)
 Initialize the SHT3x sensor device. More...
 
int sht3x_read (sht3x_dev_t *dev, int16_t *temp, int16_t *hum)
 Read SHT3x measurement results (temperature and humidity) More...
 

Macro Definition Documentation

◆ SHT3X_I2C_ADDR_1

#define SHT3X_I2C_ADDR_1   (0x44)

possible I2C slave addresses

ADDR pin connected to GND/VSS

Definition at line 30 of file sht3x.h.

Enumeration Type Documentation

◆ sht3x_error_codes

Driver error codes (returned as negative values)

Enumerator
SHT3X_OK 

no error

SHT3X_ERROR_I2C 

I2C communication failure.

SHT3X_ERROR_CRC 

CRC check failed.

SHT3X_ERROR_STATUS 

sensor has wrong status

SHT3X_ERROR_MEASURE_CMD_INV 

measurement command not executed

Definition at line 36 of file sht3x.h.

◆ sht3x_mode_t

SHT3x measurement modes.

Enumerator
SHT3X_SINGLE_SHOT 

single shot measurement

SHT3X_PERIODIC_0_5_MPS 

periodic with 0.5 measurements per second (mps)

SHT3X_PERIODIC_1_MPS 

periodic with 1 measurements per second (mps)

SHT3X_PERIODIC_2_MPS 

periodic with 2 measurements per second (mps)

SHT3X_PERIODIC_4_MPS 

periodic with 4 measurements per second (mps)

SHT3X_PERIODIC_10_MPS 

periodic with 10 measurements per second (mps)

Definition at line 47 of file sht3x.h.

◆ sht3x_repeat_t

SHT3x repeatability levels.

The stated repeatability is 3 times the standard deviation of multiple consecutive measurements at the stated repeatability and at constant ambient conditions. It is a measure for the noise on the physical sensor output. Different measurement modes allow for high/medium/low repeatability. [Datasheet SHT3x-DIS]

The configured repeatability level determines the time required for a measurement:

Reapeatability T typ. RH typ. Maximum Measurement Duration
high 0.04 0.08 15.5 ms
medium 0.08 0.15 6.5 ms
low 0.15 0.21 4.5 ms
Enumerator
SHT3X_HIGH 

high repeatability

SHT3X_MEDIUM 

medium repeatability

SHT3X_LOW 

low repeatability

Definition at line 75 of file sht3x.h.

Function Documentation

◆ sht3x_init()

int sht3x_init ( sht3x_dev_t dev,
const sht3x_params_t params 
)

Initialize the SHT3x sensor device.

This function initializes the sensor device.

If the sensor device is configured in any periodic measurement mode, it immediately starts the periodic measurement with configured measurement period and configured repeatability.

In single-shot mode, the sensor device goes into the sleep mode to save power. The single measurement is started when sht3x_read is called.

Parameters
[in]devDevice descriptor of SHT3x device to be initialized
[in]paramsSHT3x initialization parameters
Returns
0 on success or negative error code, see sht3x_error_codes

◆ sht3x_read()

int sht3x_read ( sht3x_dev_t dev,
int16_t *  temp,
int16_t *  hum 
)

Read SHT3x measurement results (temperature and humidity)

The function returns the results of one measurement once they are available.

If the single-shot measurement mode is configured, the function

  • starts the measurement according to the configured repeatability
  • waits for the sensor to complete the measurement depending on the configured repeatability, and
  • returns the measurement results.
Note
Since in single-shot measurement mode the measurement is only started when this function is called, it delays the calling task up to 16 ms, depending on the configured repeatability, in order to wait for the results of the measurement.

In the periodic measurement modes, the function returns the results of the last periodic measurement, if already available.

Note
The sht3x_read function should be called less frequently than the periodic measurements are performed. Otherwise, the function implicitly delays the calling task until the results of the next measurement cycle become available to avoid data underrun and sensor blocking.

For either temp or hum also NULL can be passed, if only one value is of interest.

Parameters
[in]devDevice descriptor of SHT3x device to read from
[out]tempTemperature in hundredths of a degree Celsius
[out]humRelative Humidity in hundredths of a percent
Returns
0 on success or negative error code, see sht3x_error_codes