1
1

Philips の温湿度気圧センサ BME280。

IMG_20240712_212024.jpg

いろいろあるけれども、今回は中華製の紫色の格安モジュールでトライ。

IMG_20240712_143431.jpg

似ているけど大きさの違うモジュールが市場に出ている。

裏側。小さい方は生意気に電源レギュレータがついている。

IMG_20240712_143602.jpg

今回は RaspberryPi で動かしてみました。

環境

  • Raspberry Pi 3B
  • Raspberry Pi OS Lite (2024-07-04-raspios-bookworm-armhf-lite.img.xz)

接続

Grove Base HAT for Raspberry Pi Zero の Grove 端子で接続してみました

IMG_20240712_144001.jpg

cf.,「Grove Base HAT for Raspberry Pi Zero を使う」
https://qiita.com/nanbuwks/items/f880f12d139c8575665f

RaspberryPi で I2C を設定

I2C を有効化。

$ sudo raspi-config

テスト

$ sudo apt install i2c-tools
$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --       

アドレス 0x76 が見えています。

python で値を得る

モジュールをインストール
RPI.BME280を最初は使ってみましたが、ちょっとめんどくさかったので以下のようにしました。

https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/python-circuitpython-test
をもとに、

$ sudo pip install --break-system-package adafruit-circuitpython-bme280

プログラム

#!/usr/bin/env python3
import time
import board
from adafruit_bme280 import basic as adafruit_bme280

i2c = board.I2C()
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c,0x76)

while True:
    print(int( bme280.temperature),"℃  ",int( bme280.relative_humidity),"%  ", int(bme280.pressure),"hPa")
    time.sleep(1)
$ python3 bme280-1.py 
26 ℃   64 %   1017 hPa
26 ℃   64 %   1016 hPa
26 ℃   64 %   1017 hPa
.
.
.

うまく値が取得できました

I2Cアドレスを変更して2つのセンサを使用する

さて、SDO を Hi にすると I2C アドレスが 0x77 になります。

IMG_20240712_153043.jpg
こうしておいて、2つを並列で接続しました。

IMG_20240712_154009.jpg


$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 77 

2つとも認識しましたね

2センサ対応プログラム

#!/usr/bin/env python3
import time
import board
from adafruit_bme280 import basic as adafruit_bme280

i2c = board.I2C()
bme280_1 = adafruit_bme280.Adafruit_BME280_I2C(i2c,0x76)
bme280_2 = adafruit_bme280.Adafruit_BME280_I2C(i2c,0x77)

while True:
    print("sensor1:",int( bme280_1.temperature),"℃  ",int( bme280_1.relative_humidity),"%  ", int(bme280_1.pressure),"hPa")
    print("sensor2:",int( bme280_2.temperature),"℃  ",int( bme280_2.relative_humidity),"%  ", int(bme280_2.pressure),"hPa")
    print()
    time.sleep(1)
$ python3 bme280-2.py 
sensor1: 26 ℃   64 %   1017 hPa
sensor2: 25 ℃   85 %   1015 hPa

sensor1: 26 ℃   64 %   1017 hPa
sensor2: 25 ℃   85 %   1015 hPa

sensor1: 26 ℃   64 %   1017 hPa
sensor2: 25 ℃   85 %   1015 hPa

sensor1: 26 ℃   64 %   1017 hPa
sensor2: 25 ℃   85 %   1015 hPa
.
.
.

うまくいきました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1