HTU21D Sensor API

HTU21D humidity sensor

Enabling this sensor code requires certain configuration values to be present in the application’s configuration json. An example is given below:

{
    "sensors": {
        "htu21d": {
            "i2c_bus": "K_I2C1"
        }
    }
}

See the Kubos I2C Example for an example of how to use this sensor.

KSensorStatus htu21d_setup(void)

Setup the I2C interface for talking with the HTU21D.

Return
KSensorStatus - SENSOR_OK on success or SENSOR_WRITE_ERROR on error

KSensorStatus htu21d_read_temperature(float *temp)

Sends temperature command and reads back temperature data.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_ERROR, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • temp: pointer to temperature in celsius (-40.0 to 125.0)

KSensorStatus htu21d_read_humidity(float *hum)

Sends humidity command and reads back humidity data.

Return
KSensorStatus, SENSOR_OK on success, SENSOR_ERROR, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • hum: pointer to relative humidity in percentage (0.0 - 100.0)

KSensorStatus htu21d_reset(void)

Sends reset command which powers sensor off and on again.

Return
KSensorStatus - SENSOR_OK on success or SENSOR_WRITE_ERROR on error