Environmental Sensor FeatherWing Sample
Last updated on: December 31, 2019
The sensor shield sample sets up the sensors available on the Icarus shield and reads values from the sensors in a loop.
In order to use the sensors on the shield the following directives are enabled in the
These include and enable the I2C driver and the sensor library.
Additionally the sample configures the following directives in the
These enable the Zephyr sensor driver and the use of the individual sensor drivers.
The sample initializes each of the sensors getting the device bindings from the Icarus device tree (they are added to the device tree by the
actinius_icarus_ns.overlay file that can be found in the root folder of the project):
struct device* bme280 = device_get_binding("BME280");struct device* ccs881 = device_get_binding("CCS811");struct device* opt3001 = device_get_binding("OPT3001");struct device* si7060 = device_get_binding("SI7060");
then reads each sensor values in a loop using the Zephyr sensor library and prints them.
The following code shows how the measured values are retrieved from the sensors:
BME280sensor_sample_fetch(bme280);struct sensor_value temp;sensor_channel_get(bme280, SENSOR_CHAN_AMBIENT_TEMP, &temp);struct sensor_value press;sensor_channel_get(bme280, SENSOR_CHAN_PRESS, &press);struct sensor_value humidity;sensor_channel_get(bme280, SENSOR_CHAN_HUMIDITY, &humidity);
CCS811sensor_sample_fetch(ccs881);struct sensor_value co2;sensor_channel_get(ccs881, SENSOR_CHAN_CO2, &co2);struct sensor_value voc;sensor_channel_get(ccs881, SENSOR_CHAN_VOC, &voc);
OPT3001sensor_sample_fetch(opt3001);struct sensor_value lux;sensor_channel_get(opt3001, SENSOR_CHAN_LIGHT, &lux);
SI7060sensor_sample_fetch(si7060);struct sensor_value temp;sensor_channel_get(si7060, SENSOR_CHAN_AMBIENT_TEMP, &temp);
In order to convert the value returned from the sensors to a double, the sensor library provides a helper method:double value_float = sensor_value_to_double(&sensor_value);