• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

boards/03-Aug-2024-5447

src/03-Aug-2024-10570

CMakeLists.txtD03-Aug-2024223 96

KconfigD03-Aug-2024396 2316

README.rstD03-Aug-20246.1 KiB165124

arduino_i2c.overlayD03-Aug-2024398 2018

arduino_spi.overlayD03-Aug-2024381 1815

prj.confD03-Aug-202442 32

rpi_pico_spi_pio.overlayD03-Aug-2024801 3733

sample.yamlD03-Aug-20241 KiB4140

README.rst

1.. _bme280:
2
3BME280 Humidity and Pressure Sensor
4###################################
5
6Overview
7********
8
9This sample shows how to use the Zephyr :ref:`sensor` API driver for the
10`Bosch BME280`_ environmental sensor.
11
12.. _Bosch BME280:
13   https://www.bosch-sensortec.com/products/environmental-sensors/humidity-sensors-bme280/
14
15The sample periodically reads temperature, pressure and humidity data from the
16first available BME280 device discovered in the system. The sample checks the
17sensor in polling mode (without interrupt trigger).
18
19Building and Running
20********************
21
22The sample can be configured to support BME280 sensors connected via either I2C
23or SPI. Configuration is done via :ref:`devicetree <dt-guide>`. The devicetree
24must have an enabled node with ``compatible = "bosch,bme280";``. See
25:dtcompatible:`bosch,bme280` for the devicetree binding and see below for
26examples and common configurations.
27
28If the sensor is not built into your board, start by wiring the sensor pins
29according to the connection diagram given in the `BME280 datasheet`_ at
30page 38.
31
32.. _BME280 datasheet:
33   https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf
34
35Boards with a built-in BME280
36=============================
37
38Your board may have a BME280 node configured in its devicetree by default. Make
39sure this node has ``status = "okay";``, then build and run with:
40
41.. zephyr-app-commands::
42   :zephyr-app: samples/sensor/bme280
43   :goals: build flash
44   :board: adafruit_feather_m0_basic_proto
45
46BME280 via Arduino SPI pins
47===========================
48
49If you wired the sensor to a SPI peripheral on an Arduino header, build and
50flash with:
51
52.. zephyr-app-commands::
53   :zephyr-app: samples/sensor/bme280
54   :goals: build flash
55   :gen-args: -DDTC_OVERLAY_FILE=arduino_spi.overlay
56
57The devicetree overlay :zephyr_file:`samples/sensor/bme280/arduino_spi.overlay`
58works on any board with a properly configured Arduino pin-compatible SPI
59peripheral.
60
61BME280 via Arduino I2C pins
62===========================
63
64If you wired the sensor to an I2C peripheral on an Arduino header, build and
65flash with:
66
67.. zephyr-app-commands::
68   :zephyr-app: samples/sensor/bme280
69   :goals: build flash
70   :gen-args: -DDTC_OVERLAY_FILE=arduino_i2c.overlay
71
72The devicetree overlay :zephyr_file:`samples/sensor/bme280/arduino_i2c.overlay`
73works on any board with a properly configured Arduino pin-compatible I2C
74peripheral.
75
76BME280 via Raspberry Pi Pico
77============================
78
79The default assignment of the built-in spi0 device on the :ref:`rpi_pico` is
80to GPIO16 through GPIO19.  With the sensor wired to those lines, build and
81flash with:
82
83.. zephyr-app-commands::
84   :zephyr-app: samples/sensor/bme280
85   :goals: build flash
86   :board: rpi_pico
87
88An alternative is to use PIO serving as an SPI device.  The devicetree
89overlay :zephyr_file:`samples/sensor/bme280/rpi_pico_spi_pio.overlay`
90demonstrates using PIO SPI with the sensor wired to arbitrary GPIO pins.
91Build and flash with:
92
93.. zephyr-app-commands::
94   :zephyr-app: samples/sensor/bme280
95   :goals: build flash
96   :board: rpi_pico
97   :gen-args: -DDTC_OVERLAY_FILE=rpi_pico_spi_pio.overlay
98
99Note that miso-gpios, mosi-gpios, and clk-gpios need to be assigned to the
100selected PIO device in pinctrl, while cs-gpios should not;  chip select is
101controlled by the SPI context and must operate as a conventional GPIO pin,
102not under control of PIO.
103
104Board-specific overlays
105=======================
106
107If your board's devicetree does not have a BME280 node already, you can create
108a board-specific devicetree overlay adding one in the :file:`boards` directory.
109See existing overlays for examples.
110
111The build system uses these overlays by default when targeting those boards, so
112no ``DTC_OVERLAY_FILE`` setting is needed when building and running.
113
114For example, to build for the :ref:`adafruit_feather_m0_basic_proto` using the
115:zephyr_file:`samples/sensor/bme280/boards/adafruit_feather_m0_basic_proto.overlay`
116overlay provided with this sample:
117
118.. zephyr-app-commands::
119   :zephyr-app: samples/sensor/bme280
120   :goals: build flash
121   :board: adafruit_feather_m0_basic_proto
122
123Sample Output
124=============
125
126The sample prints output to the serial console. BME280 device driver messages
127are also logged. Refer to your board's documentation for information on
128connecting to its serial console.
129
130Here is example output for the default application settings, assuming that only
131one BME280 sensor is connected to the standard Arduino I2C pins:
132
133.. code-block:: none
134
135   [00:00:00.379,760] <dbg> BME280.bme280_init: initializing "BME280_SPI" on bus "SPI_3"
136   [00:00:00.379,821] <dbg> BME280.bme280_init: bad chip id 0xff
137   [00:00:00.379,821] <dbg> BME280.bme280_init: initializing "BME280_I2C" on bus "I2C_0"
138   [00:00:00.380,340] <dbg> BME280.bme280_init: ID OK
139   [00:00:00.385,559] <dbg> BME280.bme280_init: BME280_I2C OK
140   *** Booting Zephyr OS build zephyr-v2.4.0-2940-gbb732ada394f  ***
141   Found device BME280_I2C, getting sensor data
142   temp: 20.260000; press: 99.789019; humidity: 46.458984
143   temp: 20.260000; press: 99.789480; humidity: 46.424804
144   temp: 20.250000; press: 99.789246; humidity: 46.423828
145
146Here is example output for the default application settings, assuming that two
147different BME280 sensors are connected to the standard Arduino I2C and SPI pins:
148
149.. code-block:: none
150
151   [00:00:00.377,777] <dbg> BME280.bme280_init: initializing "BME280_SPI" on bus "SPI_3"
152   [00:00:00.377,838] <dbg> BME280.bme280_init: ID OK
153   [00:00:00.379,608] <dbg> BME280.bme280_init: BME280_SPI OK
154   [00:00:00.379,638] <dbg> BME280.bme280_init: initializing "BME280_I2C" on bus "I2C_0"
155   [00:00:00.380,126] <dbg> BME280.bme280_init: ID OK
156   [00:00:00.385,345] <dbg> BME280.bme280_init: BME280_I2C OK
157   *** Booting Zephyr OS build zephyr-v2.4.0-2940-gbb732ada394f  ***
158   Found device BME280_I2C, getting sensor data
159   temp: 20.150000; press: 99.857675; humidity: 46.447265
160   temp: 20.150000; press: 99.859121; humidity: 46.458984
161   temp: 20.150000; press: 99.859234; humidity: 46.469726
162
163That the driver logs include a line saying ``BME280_I2C OK`` in both cases, but
164``BME280_SPI OK`` is missing when that device is not connected.
165