sht3x - Driver for Sensirion SHT3x digital temperature and humidity sensor¶
- group sht3x
ESP-IDF driver for Sensirion SHT3x digital temperature and humidity sensor.
Forked from https://github.com/gschorcht/sht3x-esp-idf
Copyright (c) 2017 Gunar Schorcht https://github.com/gschorcht Copyright (c) 2019 Ruslan V. Uss unclerus@gmail.com
BSD Licensed as described in the file LICENSE
Typedefs
-
typedef uint8_t sht3x_raw_data_t[SHT3X_RAW_DATA_SIZE]¶
Enums
-
enum sht3x_mode_t¶
Possible measurement modes.
Values:
-
enumerator SHT3X_SINGLE_SHOT¶
one single measurement
-
enumerator SHT3X_PERIODIC_05MPS¶
periodic with 0.5 measurements per second (mps)
-
enumerator SHT3X_PERIODIC_1MPS¶
periodic with 1 measurements per second (mps)
-
enumerator SHT3X_PERIODIC_2MPS¶
periodic with 2 measurements per second (mps)
-
enumerator SHT3X_PERIODIC_4MPS¶
periodic with 4 measurements per second (mps)
-
enumerator SHT3X_PERIODIC_10MPS¶
periodic with 10 measurements per second (mps)
-
enumerator SHT3X_SINGLE_SHOT¶
Functions
-
esp_err_t sht3x_init_desc(sht3x_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)¶
Initialize device descriptor.
- Parameters
dev – Device descriptor
port – I2C port
addr – Device address
sda_gpio – SDA GPIO
scl_gpio – SCL GPIO
- Returns
ESP_OK
on success
-
esp_err_t sht3x_free_desc(sht3x_t *dev)¶
Free device descriptor.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t sht3x_init(sht3x_t *dev)¶
Initialize sensor.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t sht3x_set_heater(sht3x_t *dev, bool enable)¶
Enable/disable heater.
- Parameters
dev – Device descriptor
enable – True to enable, false to disable
- Returns
ESP_OK
on success
-
esp_err_t sht3x_measure(sht3x_t *dev, float *temperature, float *humidity)¶
High level measurement function.
For convenience this function comprises all three steps to perform one measurement in only one function:
Starts a measurement in single shot mode with high reliability
Waits using
vTaskDelay()
until measurement results are availableReturns the results in kind of floating point sensor values
This function is the easiest way to use the sensor. It is most suitable for users that don’t want to have the control on sensor details.
Note
The function delays the calling task up to 30 ms to wait for the measurement results. This might lead to problems when function is called from a software timer callback function.
- Parameters
dev – Device descriptor
temperature – Temperature in degree Celsius
humidity – Humidity in percent
- Returns
ESP_OK
on success
-
uint8_t sht3x_get_measurement_duration(sht3x_repeat_t repeat)¶
Get the duration of a measurement in RTOS ticks.
The function returns the duration in RTOS ticks required by the sensor to perform a measurement for the given repeatability. Once a measurement is started with function sht3x_start_measurement() the user task can use this duration in RTOS ticks directly to wait with function
vTaskDelay()
until the measurement results can be fetched.Note
The duration only depends on repeatability level. Therefore, it can be considered as constant for a repeatability.
- Parameters
repeat – Repeatability, see type sht3x_repeat_t
- Returns
Measurement duration given in RTOS ticks
-
esp_err_t sht3x_start_measurement(sht3x_t *dev, sht3x_mode_t mode, sht3x_repeat_t repeat)¶
Start the measurement in single shot or periodic mode.
The function starts the measurement either in single shot mode (exactly one measurement) or periodic mode (periodic measurements) with given repeatability.
In the single shot mode, this function has to be called for each measurement. The measurement duration has to be waited every time before the results can be fetched.
In the periodic mode, this function has to be called only once. Also the measurement duration has to be waited only once until the first results are available. After this first measurement, the sensor then automatically performs all subsequent measurements. The rate of periodic measurements can be 10, 4, 2, 1 or 0.5 measurements per second (mps).
Note
Due to inaccuracies in timing of the sensor, the user task should fetch the results at a lower rate. The rate of the periodic measurements is defined by the parameter
mode
.- Parameters
dev – Device descriptor
mode – Measurement mode, see type sht3x_mode_t
repeat – Repeatability, see type sht3x_repeat_t
- Returns
ESP_OK
on success
-
esp_err_t sht3x_stop_periodic_measurement(sht3x_t *dev)¶
Stop the periodic mode measurements.
The function stops the measurements in periodic mode (periodic measurements) and the sensor returns in single shot mode
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t sht3x_get_raw_data(sht3x_t *dev, sht3x_raw_data_t raw_data)¶
Read measurement results from sensor as raw data.
The function read measurement results from the sensor, checks the CRC checksum and stores them in the byte array as following.
data[0] = Temperature MSB data[1] = Temperature LSB data[2] = Temperature CRC data[3] = Humidity MSB data[4] = Humidity LSB data[2] = Humidity CRC
In case that there are no new data that can be read, the function fails.
- Parameters
dev – Device descriptor
raw_data – Byte array in which raw data are stored
- Returns
ESP_OK
on success
-
esp_err_t sht3x_compute_values(sht3x_raw_data_t raw_data, float *temperature, float *humidity)¶
Computes sensor values from raw data.
- Parameters
raw_data – Byte array that contains raw data
temperature – Temperature in degree Celsius
humidity – Humidity in percent
- Returns
ESP_OK
on success
-
esp_err_t sht3x_get_results(sht3x_t *dev, float *temperature, float *humidity)¶
Get measurement results in form of sensor values.
The function combines function sht3x_get_raw_data() and function sht3x_compute_values() to get the measurement results.
In case that there are no results that can be read, the function fails.
- Parameters
dev – Device descriptor
temperature – Temperature in degree Celsius
humidity – Humidity in percent
- Returns
ESP_OK
on success
-
struct sht3x_t¶
- #include <sht3x.h>
Device descriptor.
Public Members
-
sht3x_mode_t mode¶
used measurement mode
-
sht3x_repeat_t repeatability¶
used repeatability
-
bool meas_started¶
indicates whether measurement started
-
uint64_t meas_start_time¶
measurement start time in us
-
bool meas_first¶
first measurement in periodic mode
-
sht3x_mode_t mode¶
-
typedef uint8_t sht3x_raw_data_t[SHT3X_RAW_DATA_SIZE]¶