Si7005 sensor

Github Repo C Header C source JS source
mongoose-os-libs/si7005 si7005.h    

Overview

Si7005 is a temperature and relative humidity sensor by Silicon Labs.

This library provides a driver for this device.

API documentation

See include/si7005.h.

Example

#include "mgos.h"

#include "si7005.h"

static void temp_timer_cb(void *arg) {
  float temp = si7005_read_temp();
  float rh = si7005_read_rh();
  LOG(LL_INFO, ("T %.2f RH %.2f", temp, rh));
  (void) arg;
}

enum mgos_app_init_result mgos_app_init(void) {
  if (si7005_probe()) {
    LOG(LL_INFO, ("Si7005 sensor found"));
    mgos_set_timer(1000, MGOS_TIMER_REPEAT, temp_timer_cb, NULL);
  } else {
    LOG(LL_WARN, ("Failed to init temp sensor"));
  }
  return MGOS_APP_INIT_SUCCESS;
}

Note: You need to make sure that I2C is enabled. This can be achieved by adding

config_schema:
  - ["i2c.enable", true]

to mos.yml. You may need to adjust SDA and SCL pins as well. See I2C library for details.


si7005_probe

bool si7005_probe(void);

Returns true if a sensor is present on the bus.

si7005_read_temp

float si7005_read_temp(void);

Performs conversion and returns temperature, in C, or INVALID_VALUE

si7005_read_rh

float si7005_read_rh(void);

Performs conversion and returns relative humidity, in %, or INVALID_VALUE. Note: Performs temperature measurement prior to the RH to perform temperature compensation.

si7005_set_heater

bool si7005_set_heater(bool on);

Turns the built-in heater element on or off.

si7005_probe_bus

bool si7005_probe_bus(struct mgos_i2c *i2c);
float si7005_read_temp_bus(struct mgos_i2c *i2c);
float si7005_read_rh_bus(struct mgos_i2c *i2c);
bool si7005_set_heater_bus(struct mgos_i2c *i2c, bool on);

Variants of the simple blocking methods above with custom bus.

si7005_start_conversion

bool si7005_start_conversion(struct mgos_i2c *i2c, bool temp, bool fast);

Start temperature or humidity conversion.

si7005_is_data_ready

bool si7005_is_data_ready(struct mgos_i2c *i2c);

Check if the data is ready.

si7005_read_data

float si7005_read_data(struct mgos_i2c *i2c, bool temp);

Read out the data. Note that RH value is linearized but not temp-compensated.

si7005_rh_tcomp

float si7005_rh_tcomp(float rh_val, float temp);

Perform temperature compensation of the RH reading.

edit this doc