samples/sensor/bme280/README.html · samples/sensor/bme280/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Sensor · Environment

BME280 습도·압력 센서

온도·기압·습도를 polling하고 여섯 배선·overlay 구성을 board별 build 명령과 함께 설명합니다.

Official pathsamples/sensor/bme280/README.html
Source filesamples/sensor/bme280/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Arduino I2C/SPI, Raspberry Pi Pico SPI/PIO, 내장 node와 board 전용 overlay를 모두 다룹니다.

Values

Temp · Pressure · RH

Buses

I2C · SPI · PIO

Config

Devicetree overlays

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 4836B2502CA52E6193DCCB36341E942B01AACF5F781483EBA376FA01F28E6FE4
.. _bme280:

BME280 Humidity and Pressure Sensor
###################################

Overview
********

This sample shows how to use the Zephyr :ref:`sensor` API driver for the
`Bosch BME280`_ environmental sensor.

.. _Bosch BME280:
   https://www.bosch-sensortec.com/products/environmental-sensors/humidity-sensors-bme280/

The sample periodically reads temperature, pressure and humidity data from the
first available BME280 device discovered in the system. The sample checks the
sensor in polling mode (without interrupt trigger).

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

The sample can be configured to support BME280 sensors connected via either I2C
or SPI. Configuration is done via :ref:`devicetree <dt-guide>`. The devicetree
must have an enabled node with ``compatible = "bosch,bme280";``. See
:dtcompatible:`bosch,bme280` for the devicetree binding and see below for
examples and common configurations.

If the sensor is not built into your board, start by wiring the sensor pins
according to the connection diagram given in the `BME280 datasheet`_ at
page 38.

.. _BME280 datasheet:
   https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf

Boards with a built-in BME280
=============================

Your board may have a BME280 node configured in its devicetree by default. Make
sure this node has ``status = "okay";``, then build and run with:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/bme280
   :goals: build flash
   :board: adafruit_feather_m0_basic_proto

BME280 via Arduino SPI pins
===========================

If you wired the sensor to a SPI peripheral on an Arduino header, build and
flash with:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/bme280
   :goals: build flash
   :gen-args: -DDTC_OVERLAY_FILE=arduino_spi.overlay

The devicetree overlay :zephyr_file:`samples/sensor/bme280/arduino_spi.overlay`
works on any board with a properly configured Arduino pin-compatible SPI
peripheral.

BME280 via Arduino I2C pins
===========================

If you wired the sensor to an I2C peripheral on an Arduino header, build and
flash with:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/bme280
   :goals: build flash
   :gen-args: -DDTC_OVERLAY_FILE=arduino_i2c.overlay

The devicetree overlay :zephyr_file:`samples/sensor/bme280/arduino_i2c.overlay`
works on any board with a properly configured Arduino pin-compatible I2C
peripheral.

BME280 via Raspberry Pi Pico
============================

The default assignment of the built-in spi0 device on the :ref:`rpi_pico` is
to GPIO16 through GPIO19.  With the sensor wired to those lines, build and
flash with:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/bme280
   :goals: build flash
   :board: rpi_pico

An alternative is to use PIO serving as an SPI device.  The devicetree
overlay :zephyr_file:`samples/sensor/bme280/rpi_pico_spi_pio.overlay`
demonstrates using PIO SPI with the sensor wired to arbitrary GPIO pins.
Build and flash with:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/bme280
   :goals: build flash
   :board: rpi_pico
   :gen-args: -DDTC_OVERLAY_FILE=rpi_pico_spi_pio.overlay

Note that miso-gpios, mosi-gpios, and clk-gpios need to be assigned to the
selected PIO device in pinctrl, while cs-gpios should not;  chip select is
controlled by the SPI context and must operate as a conventional GPIO pin,
not under control of PIO.

Board-specific overlays
=======================

If your board's devicetree does not have a BME280 node already, you can create
a board-specific devicetree overlay adding one in the :file:`boards` directory.
See existing overlays for examples.

The build system uses these overlays by default when targeting those boards, so
no ``DTC_OVERLAY_FILE`` setting is needed when building and running.

For example, to build for the :ref:`adafruit_feather_m0_basic_proto` using the
:zephyr_file:`samples/sensor/bme280/boards/adafruit_feather_m0_basic_proto.overlay`
overlay provided with this sample:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/bme280
   :goals: build flash
   :board: adafruit_feather_m0_basic_proto

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

The sample prints output to the serial console. BME280 device driver messages
are also logged. Refer to your board's documentation for information on
connecting to its serial console.

Here is example output for the default application settings, assuming that only
one BME280 sensor is connected to the standard Arduino I2C pins:

.. code-block:: none

   [00:00:00.379,760] <dbg> BME280.bme280_init: initializing "BME280_SPI" on bus "SPI_3"
   [00:00:00.379,821] <dbg> BME280.bme280_init: bad chip id 0xff
   [00:00:00.379,821] <dbg> BME280.bme280_init: initializing "BME280_I2C" on bus "I2C_0"
   [00:00:00.380,340] <dbg> BME280.bme280_init: ID OK
   [00:00:00.385,559] <dbg> BME280.bme280_init: BME280_I2C OK
   *** Booting Zephyr OS build zephyr-v2.4.0-2940-gbb732ada394f  ***
   Found device BME280_I2C, getting sensor data
   temp: 20.260000; press: 99.789019; humidity: 46.458984
   temp: 20.260000; press: 99.789480; humidity: 46.424804
   temp: 20.250000; press: 99.789246; humidity: 46.423828

Here is example output for the default application settings, assuming that two
different BME280 sensors are connected to the standard Arduino I2C and SPI pins:

.. code-block:: none

   [00:00:00.377,777] <dbg> BME280.bme280_init: initializing "BME280_SPI" on bus "SPI_3"
   [00:00:00.377,838] <dbg> BME280.bme280_init: ID OK
   [00:00:00.379,608] <dbg> BME280.bme280_init: BME280_SPI OK
   [00:00:00.379,638] <dbg> BME280.bme280_init: initializing "BME280_I2C" on bus "I2C_0"
   [00:00:00.380,126] <dbg> BME280.bme280_init: ID OK
   [00:00:00.385,345] <dbg> BME280.bme280_init: BME280_I2C OK
   *** Booting Zephyr OS build zephyr-v2.4.0-2940-gbb732ada394f  ***
   Found device BME280_I2C, getting sensor data
   temp: 20.150000; press: 99.857675; humidity: 46.447265
   temp: 20.150000; press: 99.859121; humidity: 46.458984
   temp: 20.150000; press: 99.859234; humidity: 46.469726

That the driver logs include a line saying ``BME280_I2C OK`` in both cases, but
``BME280_SPI OK`` is missing when that device is not connected.

Part 3

한국어 전문 번역

개요

이 sample은 Zephyr sensor API driver로 Bosch BME280 environmental sensor를 사용하는 방법을 보여 줍니다.

System에서 발견한 첫 번째 BME280 device의 temperature, pressure와 humidity data를 주기적으로 읽습니다. Sensor는 interrupt trigger가 없는 polling mode로 확인합니다.

빌드 및 실행

Sample은 I2C 또는 SPI로 연결된 BME280 sensor를 지원하도록 구성할 수 있습니다. Configuration은 Devicetree에서 하며, compatible = "bosch,bme280";인 활성 node가 있어야 합니다. 자세한 property는 bosch,bme280 binding을 참고하십시오.

Sensor가 board에 내장되어 있지 않다면 BME280 datasheet 38쪽의 connection diagram에 따라 sensor pin을 먼저 배선합니다.

BME280이 내장된 board

Board Devicetree에 BME280 node가 기본 구성되어 있을 수 있습니다. Node의 status = "okay";를 확인하고 다음처럼 build하고 실행합니다.

# From the root of the zephyr repository
west build -b adafruit_feather_m0_basic_proto samples/sensor/bme280
west flash

Arduino SPI pin으로 연결한 BME280

Sensor를 Arduino header의 SPI peripheral에 연결했다면 다음처럼 build하고 flash합니다. 아래 공식 렌더링의 -b None 자리에는 실제 사용할 board 이름을 지정해야 합니다.

# From the root of the zephyr repository
west build -b None samples/sensor/bme280 -- -DDTC_OVERLAY_FILE=arduino_spi.overlay
west flash

samples/sensor/bme280/arduino_spi.overlay Devicetree overlay는 Arduino pin과 호환되도록 SPI peripheral이 올바르게 구성된 모든 board에서 동작합니다.

Arduino I2C pin으로 연결한 BME280

Sensor를 Arduino header의 I2C peripheral에 연결했다면 다음처럼 build하고 flash합니다. 마찬가지로 실제 board 이름을 선택합니다.

# From the root of the zephyr repository
west build -b None samples/sensor/bme280 -- -DDTC_OVERLAY_FILE=arduino_i2c.overlay
west flash

samples/sensor/bme280/arduino_i2c.overlay Devicetree overlay는 Arduino pin과 호환되도록 I2C peripheral이 올바르게 구성된 모든 board에서 동작합니다.

Raspberry Pi Pico로 연결한 BME280

Raspberry Pi Pico의 내장 spi0 device는 기본적으로 GPIO16부터 GPIO19까지에 할당됩니다. Sensor를 이 line에 배선한 뒤 다음처럼 build하고 flash합니다.

# From the root of the zephyr repository
west build -b rpi_pico samples/sensor/bme280
west flash

대안으로 PIO를 SPI device처럼 사용할 수 있습니다. samples/sensor/bme280/rpi_pico_spi_pio.overlay는 임의 GPIO pin에 연결한 sensor와 PIO SPI를 사용하는 방법을 보여 줍니다.

# From the root of the zephyr repository
west build -b rpi_pico samples/sensor/bme280 -- -DDTC_OVERLAY_FILE=rpi_pico_spi_pio.overlay
west flash

선택한 PIO device의 pinctrl에는 miso-gpios, mosi-gpios, clk-gpios를 할당해야 하지만 cs-gpios는 할당하면 안 됩니다. Chip select는 SPI context가 제어하며 PIO가 아닌 일반 GPIO pin으로 동작해야 합니다.

Board 전용 overlay

Board Devicetree에 BME280 node가 없다면 boards directory에 node를 추가하는 board 전용 Devicetree overlay를 만들 수 있습니다. 기존 overlay를 예제로 참고하십시오.

Build system은 해당 board를 target으로 삼을 때 이 overlay를 기본 사용하므로 build와 실행 시 DTC_OVERLAY_FILE을 별도로 설정할 필요가 없습니다.

예를 들어 이 sample이 제공하는 samples/sensor/bme280/boards/adafruit_feather_m0_basic_proto.overlay를 사용해 adafruit_feather_m0_basic_proto용으로 build합니다.

# From the root of the zephyr repository
west build -b adafruit_feather_m0_basic_proto samples/sensor/bme280
west flash

출력 예

Sample은 serial console에 출력하며 BME280 device driver message도 log로 남깁니다. Serial console 연결 방법은 각 board 문서를 참고하십시오.

다음은 standard Arduino I2C pin에 BME280 sensor 하나만 연결했다고 가정한 default application 출력입니다.

[00:00:00.379,760] <dbg> BME280.bme280_init: initializing "BME280_SPI" on bus "SPI_3"
[00:00:00.379,821] <dbg> BME280.bme280_init: bad chip id 0xff
[00:00:00.379,821] <dbg> BME280.bme280_init: initializing "BME280_I2C" on bus "I2C_0"
[00:00:00.380,340] <dbg> BME280.bme280_init: ID OK
[00:00:00.385,559] <dbg> BME280.bme280_init: BME280_I2C OK
*** Booting Zephyr OS build zephyr-v2.4.0-2940-gbb732ada394f  ***
Found device BME280_I2C, getting sensor data
temp: 20.260000; press: 99.789019; humidity: 46.458984
temp: 20.260000; press: 99.789480; humidity: 46.424804
temp: 20.250000; press: 99.789246; humidity: 46.423828

다음은 standard Arduino I2C와 SPI pin에 서로 다른 BME280 sensor 두 개를 연결했다고 가정한 default application 출력입니다.

[00:00:00.377,777] <dbg> BME280.bme280_init: initializing "BME280_SPI" on bus "SPI_3"
[00:00:00.377,838] <dbg> BME280.bme280_init: ID OK
[00:00:00.379,608] <dbg> BME280.bme280_init: BME280_SPI OK
[00:00:00.379,638] <dbg> BME280.bme280_init: initializing "BME280_I2C" on bus "I2C_0"
[00:00:00.380,126] <dbg> BME280.bme280_init: ID OK
[00:00:00.385,345] <dbg> BME280.bme280_init: BME280_I2C OK
*** Booting Zephyr OS build zephyr-v2.4.0-2940-gbb732ada394f  ***
Found device BME280_I2C, getting sensor data
temp: 20.150000; press: 99.857675; humidity: 46.447265
temp: 20.150000; press: 99.859121; humidity: 46.458984
temp: 20.150000; press: 99.859234; humidity: 46.469726

두 경우 모두 driver log에 BME280_I2C OK가 있지만, SPI device를 연결하지 않은 첫 번째 경우에는 BME280_SPI OK가 없고 bad chip id 0xff가 표시됩니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.