19
18

More than 5 years have passed since last update.

Raspberry Pi 2で気温・気圧・高度センサのBMP180を使う

Posted at

以前EdisonArduinoでBMP180の気温・気圧・高度センサを使ってみました。Raspberry Piにはプルアップ用抵抗が最初から付いています。BMP180などI2C通信するブレイクアウトの場合はGPIOのプルアップが不要で使えます。また、AdafruitからBMP用のPythonライブラリも提供されているので初心者に優しいセンサーです。Arduino、Edison、Raspberry Piのどれでも使えるので1つあるといろいろ楽しめます。

I2Cの設定

Raspberry Pi 2とセンサーデータで遊ぶための初期設定に書いた方法でI2Cの設定をしています。

使い方

準備

スイッチサイエンスからSparkFun製BMP180を購入しました。SparkFunの配線方法ページを見ながらつないでいきます。Pythonプログラムから使用するライブラリはAdafruitのAdafruit_Python_BMPを使います。

ブレッドボード配線

以下のように配線します。

DA (SDA)     (BMP180)  -> SDA1 P02 (Raspberry Pi)
CL (SCL)     (BMP180)  -> SCL1 P03 (Raspberry Pi)
"-" (GND)    (BMP180)  -> GND  P09 (Raspberry Pi)
"+" (VDD)    (BMP180)  -> 3.3v P01 (Raspberry Pi)

raspi-2-bmp180.png

配線が終わったらi2cdetectコマンドで確認します。アドレスは0x77です。

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

ライブラリのインストール

最初にPythonの開発用ライブラリをインストールします。GitHubのAdafruitリポジトリからAdafruit_Python_BMPをcloneします。

$ sudo apt-get update
$ sudo apt-get install git build-essential python-dev python-smbus
$ cd ~/
$ git clone https://github.com/adafruit/Adafruit_Python_BMP.git

sudoでPythonのパッケージをインストールします。

$ cd ~/python_apps/Adafruit_Python_BMP
$ sudo python setup.py install
...
Installed /usr/local/lib/python2.7/dist-packages/spidev-3.0-py2.7-linux-armv7l.egg
Finished processing dependencies for Adafruit-BMP==1.5.0

センサーデータ取得

examplesのディレクトリに移動してサンプルのテストプログラムを実行します。BMP180だけで3種類のデータが取れました。

  • 気温: 29.10 度C
  • 気圧: 100,640.00 パスカル
  • 高度: 57.19 メートル
  • 海面気圧 : 100,635.00 パスカル
$ cd ~/python_apps/Adafruit_Python_BMP/examples
$ sudo python simpletest.py
Temp = 29.10 *C
Pressure = 100640.00 Pa
Altitude = 57.19 m
Sealevel Pressure = 100635.00 Pa
19
18
1

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
19
18