sts3x - Driver for Sensirion STS3x digital temperature sensor
- group sts3x
ESP-IDF driver for Sensirion STS3x digital temperature sensors.
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 Copyright (c) 2023 Christian Skjerning https://github.com/slimcdk
BSD-3 Licensed as described in the file LICENSE
Typedefs
-
typedef uint8_t sts3x_raw_data_t[STS3X_RAW_DATA_SIZE]
Enums
-
enum sts3x_mode_t
Possible measurement modes.
Values:
-
enumerator STS3X_SINGLE_SHOT
one single measurement
-
enumerator STS3X_PERIODIC_05MPS
periodic with 0.5 measurements per second (mps)
-
enumerator STS3X_PERIODIC_1MPS
periodic with 1 measurements per second (mps)
-
enumerator STS3X_PERIODIC_2MPS
periodic with 2 measurements per second (mps)
-
enumerator STS3X_PERIODIC_4MPS
periodic with 4 measurements per second (mps)
-
enumerator STS3X_PERIODIC_10MPS
periodic with 10 measurements per second (mps)
-
enumerator STS3X_SINGLE_SHOT
Functions
-
esp_err_t sts3x_init_desc(sts3x_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 sts3x_free_desc(sts3x_t *dev)
Free device descriptor.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OK
on success
-
esp_err_t sts3x_init(sts3x_t *dev)
Initialize sensor.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OK
on success
-
esp_err_t sts3x_set_heater(sts3x_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 sts3x_measure(sts3x_t *dev, float *temperature)
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
- Returns:
ESP_OK
on success
-
uint8_t sts3x_get_measurement_duration(sts3x_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 sts3x_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 sts3x_repeat_t
- Returns:
Measurement duration given in RTOS ticks
-
esp_err_t sts3x_start_measurement(sts3x_t *dev, sts3x_mode_t mode, sts3x_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 sts3x_mode_t
repeat – Repeatability, see type sts3x_repeat_t
- Returns:
ESP_OK
on success
-
esp_err_t sts3x_stop_periodic_measurement(sts3x_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 sts3x_get_raw_data(sts3x_t *dev, sts3x_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.
In case that there are no new data that can be read, the function fails.data[0] = Temperature MSB data[1] = Temperature LSB data[2] = Temperature CRC data[3] = Humidity MSB data[4] = Humidity LSB data[2] = Humidity CRC
- Parameters:
dev – Device descriptor
raw_data – Byte array in which raw data are stored
- Returns:
ESP_OK
on success
-
esp_err_t sts3x_compute_values(sts3x_raw_data_t raw_data, float *temperature)
Computes sensor values from raw data.
- Parameters:
raw_data – Byte array that contains raw data
temperature – Temperature in degree Celsius
- Returns:
ESP_OK
on success
-
esp_err_t sts3x_get_results(sts3x_t *dev, float *temperature)
Get measurement results in form of sensor values.
The function combines function sts3x_get_raw_data() and function sts3x_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
- Returns:
ESP_OK
on success
-
struct sts3x_t
- #include <sts3x.h>
Device descriptor.
Public Members
-
sts3x_mode_t mode
used measurement mode
-
sts3x_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
-
sts3x_mode_t mode
-
typedef uint8_t sts3x_raw_data_t[STS3X_RAW_DATA_SIZE]