1 /*
2 * Copyright (c) 2018 Bosch Sensortec GmbH
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/drivers/sensor.h>
10 #include <stdio.h>
11
main(void)12 int main(void)
13 {
14 const struct device *const dev = DEVICE_DT_GET_ONE(bosch_bme680);
15 struct sensor_value temp, press, humidity, gas_res;
16
17 if (!device_is_ready(dev)) {
18 printk("sensor: device not ready.\n");
19 return 0;
20 }
21
22 printf("Device %p name is %s\n", dev, dev->name);
23
24 while (1) {
25 k_sleep(K_MSEC(3000));
26
27 sensor_sample_fetch(dev);
28 sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
29 sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
30 sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
31 sensor_channel_get(dev, SENSOR_CHAN_GAS_RES, &gas_res);
32
33 printf("T: %d.%06d; P: %d.%06d; H: %d.%06d; G: %d.%06d\n",
34 temp.val1, temp.val2, press.val1, press.val2,
35 humidity.val1, humidity.val2, gas_res.val1,
36 gas_res.val2);
37 }
38 return 0;
39 }
40