Skip to content

Commit

Permalink
samples: sensor: bme680 added sample code
Browse files Browse the repository at this point in the history
Sample code for the BME680 environmental sensor

Signed-off-by: Bosch Sensortec <[email protected]>
  • Loading branch information
BST-Github-Admin authored and MaureenHelm committed May 31, 2019
1 parent b05d5ff commit 992819b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
12 changes: 12 additions & 0 deletions samples/sensor/bme680/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2018 Bosch Sensortec GmbH
#
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
53 changes: 53 additions & 0 deletions samples/sensor/bme680/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.. _bme680:

BME680: Integrated environmental sensor
#####################################################

Description
***********

This sample application periodically (every 3s) measures the ambient temperature
in degrees Celsius, atmospheric pressure in kilopascal, relative humidity in percentage,
and gas sensor resistance in ohms. The result is written to the console.

References
**********

- BME680: https://www.bosch-sensortec.com/bst/products/all_products/bme680

Wiring
*******

This sample uses the BME680 sensor controlled using the I2C interface.
Connect Supply: **VDD**, **VDDIO**, **GND** and Interface: **SDA**, **SCL**.
The supply voltage can be in the 1.8V to 3.6V range.
Depending on the baseboard used, the **SDA** and **SCL** lines require Pull-Up
resistors.

Building and Running
********************

This project outputs sensor data to the console. It requires a BME680
sensor. It should work with any platform featuring a I2C peripheral interface.
It does not work on QEMU.
In this example below the :ref:`nrf52_pca10040` board is used.


.. zephyr-app-commands::
:zephyr-app: samples/sensors/bme680
:board: nrf52_pca10040
:goals: build flash

Sample Output
=============

.. code-block:: console
Device 0x20002b74 name is BME680
T: 23.988877; P: 97.648568; H: 53.689533; G: 1035.211466
T: 24.168500; P: 97.648866; H: 53.565966; G: 1046.677896
T: 24.336533; P: 97.648596; H: 53.353663; G: 1058.656533
T: 24.589696; P: 97.648366; H: 53.958864; G: 1072.155863
T: 24.856631; P: 97.648322; H: 53.553669; G: 1096.448788
<repeats endlessly>
5 changes: 5 additions & 0 deletions samples/sensor/bme680/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BME680=y

7 changes: 7 additions & 0 deletions samples/sensor/bme680/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sample:
name: BME680 Sensor sample
tests:
test:
harness: sensor
tags: samples sensor
depends_on: i2c bme680
33 changes: 33 additions & 0 deletions samples/sensor/bme680/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <stdio.h>

void main(void)
{
struct device *dev = device_get_binding(DT_BOSCH_BME680_0_LABEL);
struct sensor_value temp, press, humidity, gas_res;

printf("Device %p name is %s\n", dev, dev->config->name);

while (1) {
k_sleep(3000);

sensor_sample_fetch(dev);
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
sensor_channel_get(dev, SENSOR_CHAN_GAS_RES, &gas_res);

printf("T: %d.%06d; P: %d.%06d; H: %d.%06d; G: %d.%06d\n",
temp.val1, temp.val2, press.val1, press.val2,
humidity.val1, humidity.val2, gas_res.val1,
gas_res.val2);
}
}

0 comments on commit 992819b

Please sign in to comment.