si7021 - Driver for Si7013/Si7020/Si7021/HTU21D/SHT2x and compatible

group si7021

ESP-IDF driver for Si7013/Si7020/Si7021/HTU21D/SHT2x and compatible temperature and humidity sensors.

Copyright (C) 2019 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

SI7021_I2C_ADDR

I2C address.

SI7021_MAX_HEATER_CURRENT

Maximum current of the heater for Si70xx.

Enums

enum si7021_device_id_t

Device model for Si70xx.

Values:

enumerator SI_MODEL_SI7013

Si7013.

enumerator SI_MODEL_SI7020

Si7020.

enumerator SI_MODEL_SI7021

Si7021.

enumerator SI_MODEL_SAMPLE

Engineering sample.

enumerator SI_MODEL_UNKNOWN

Unknown model.

enum si7021_resolution_t

Measurement resolution.

Values:

enumerator SI7021_RES_RH12_T14

Relative humidity: 12 bits, temperature: 14 bits.

enumerator SI7021_RES_RH08_T12

Relative humidity: 8 bits, temperature: 12 bits.

enumerator SI7021_RES_RH10_T13

Relative humidity: 10 bits, temperature: 13 bits.

enumerator SI7021_RES_RH11_T11

Relative humidity: 11 bits, temperature: 11 bits.

Functions

esp_err_t si7021_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • port: I2C port

  • sda_gpio: SDA GPIO pin

  • scl_gpio: SCL GPIO pin

esp_err_t si7021_free_desc(i2c_dev_t *dev)

Free device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t si7021_reset(i2c_dev_t *dev)

Reset device.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t si7021_get_heater(i2c_dev_t *dev, bool *on)

Get heater state.

This function is supported by:

  • SI7013

  • SI7020

  • SI7021

  • SHT2x

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] on: true if heater enabled

esp_err_t si7021_set_heater(i2c_dev_t *dev, bool on)

Switch heater on/off.

This function is supported by:

  • SI7013

  • SI7020

  • SI7021

  • SHT2x

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • on: if true, heater will be enabled

esp_err_t si7021_get_heater_current(i2c_dev_t *dev, uint8_t *level)

Get heater current.

This function is supported by:

  • SI7013

  • SI7020

  • SI7021

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] level: Heater current, see datasheet

esp_err_t si7021_set_heater_current(i2c_dev_t *dev, uint8_t level)

Set heater current.

This function is supported by:

  • SI7013

  • SI7020

  • SI7021

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • level: Heater current, see datasheet

esp_err_t si7021_get_resolution(i2c_dev_t *dev, si7021_resolution_t *r)

Get measurement resolution.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] r: Resolution

esp_err_t si7021_set_resolution(i2c_dev_t *dev, si7021_resolution_t r)

Set measurement resolution.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • r: Resolution

esp_err_t si7021_measure_temperature(i2c_dev_t *dev, float *t)

Measure temperature.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] t: Temperature, deg. Celsius

esp_err_t si7021_measure_humidity(i2c_dev_t *dev, float *rh)

Measure relative humidity.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] rh: Relative humidity, %

esp_err_t si7021_get_serial(i2c_dev_t *dev, uint64_t *serial, bool sht2x_mode)

Get serial number of device.

This function is supported by:

  • SI7013

  • SI7020

  • SI7021

  • SHT2x

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] serial: Serial no.

  • sht2x_mode: true for SHT2x devices

esp_err_t si7021_get_device_id(i2c_dev_t *dev, si7021_device_id_t *id)

Get device model.

This function is supported by:

  • SI7013

  • SI7020

  • SI7021

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] id: Device model