スイッチサイエンス の BME280搭載 温湿度・気圧センサモジュール

Raspberry Pi2 で、Pythonのサンプルプログラムを動かして温度・湿度・気圧を一応取得出来たので方法を残しておきます。

■ハードウェアについて

今回使った BME280搭載 温湿度・気圧センサモジュールは、スイッチサイエンスから出ているものです。
1cm×2cmのサイズで、温度・湿度・気圧の3種類の環境情報が取得可能です。
接続は、I2CとSPIで接続できます。
電源電圧は、DC1.8V~3.3V
Raspberry Pi とつないで動作させることができます。

スイッチサイエンス商品ページ
https://www.switch-science.com/catalog/2236/

Amazonでも買えます。

■Raspberry Pi 2との接続

SDO: Hi,LoでI2Cアドレスが決まる(Hiの時 0x77, Loの時 0x76)そうで、今回はGND(Lo)につなぐ(サンプルプログラムが0x76で書かれてる)。
SCK: I2C SCL
SDI: I2C SDA
CSB: 3.3V これはなんで3.3Vなのか謎。そのうち調べる。
GND: GND
Vcore: Vioはつながっているので特につながなくてもいいはず。
Vio: 3.3V

BME280_raspberrypi

 

■raspi-configでI2Cを有効にする

raspi-config を起動してI2Cを有効にします。

$ sudo raspi-config

raspi-config 8 Advanced Options

raspi-config A7 I2C

あと、YES。

■設定

/etc/modules に i2c-dev を追加

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-dev

 

■I2Cのアドレスを確認

$ sudo i2cdetect 1
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --

 

■サンプルプログラム取得

$ wget https://raw.githubusercontent.com/SWITCHSCIENCE/BME280/master/Python27/bme280_sample.py
--2015-08-16 03:36:21-- https://raw.githubusercontent.com/SWITCHSCIENCE/BME280/master/Python27/bme280_sample.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 103.245.222.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|103.245.222.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3867 (3.8K) [text/plain]
Saving to: `bme280_sample.py'

100%[================================================>] 3,867 --.-K/s in 0s

2015-08-16 03:36:25 (13.3 MB/s) - `bme280_sample.py' saved [3867/3867]

 

■サンプルプログラム実行

$ sudo python bme280_sample.py
Traceback (most recent call last):
 File "bme280_sample.py", line 3, in <module>
 import smbus
ImportError: No module named smbus

エラーが出た。smbusってのがないっぽい。

■ソフトインストール

$ sudo apt-get install python-smbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
 python-smbus
0 upgraded, 1 newly installed, 0 to remove and 25 not upgraded.
Need to get 11.9 kB of archives.
After this operation, 95.2 kB of additional disk space will be used.
Get:1 http://archive.raspberrypi.org/debian/ wheezy/main python-smbus armhf 3.1.1+svn-1 [11.9 kB]
Fetched 11.9 kB in 1s (9,661 B/s)
Selecting previously unselected package python-smbus.
(Reading database ... 79545 files and directories currently installed.)
Unpacking python-smbus (from .../python-smbus_3.1.1+svn-1_armhf.deb) ...
Setting up python-smbus (3.1.1+svn-1) ...

 

■再度サンプルプログラム実行

$ sudo python bme280_sample.py
temp : 32.17 ℃
pressure : 1008.27 hPa
hum : 49.47 %

取得できた。でも気温が少し高めに出てる気がする。 とりあえずサンプルプログラムそのままで動かしたけど、微調整とかできるのかな?

 

参考

https://www.switch-science.com/catalog/2236/
http://qiita.com/masato/items/027e5c824ae75ab417c1
http://trac.switch-science.com/wiki/BME280

コメントする

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください