概要

  • BME280 を買ってみたので動確したときのメモ
  • 買ったのはこれ $2.81
  • 秋月だとこれが \1080
  • Datasheet はここの Downloads → Datasheet

Raspbery Pi 3 で動確

  • Raspbery Pi 3 と接続
  • i2cdetect でデバイスアドレスが 0x76 であることを確認

    pi@raspberrypi:~ $ 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] 
         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 --                         
    
  • i2cdump してみる

    pi@raspberrypi:~ $ i2cdump 1 0x76
    No size specified (using byte-data access)
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-1, address 0x76, mode byte
    Continue? [Y/n] 
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
    00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    80: 8c 50 89 1f 6e 32 79 06 50 6f 8a 68 32 00 1a 92    ?P??n2y?Po?h2.??
    90: e1 d6 d0 0b a1 1b 8e ff f9 ff 0c 30 20 d1 88 13    ???????.?.?0 ???
    a0: 00 4b 96 00 00 00 00 00 00 00 00 00 33 00 00 c0    .K?.........3..?
    b0: 00 54 00 00 00 00 60 02 00 01 ff ff 1f 60 03 00    .T....`?.?..?`?.
    c0: 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00    ................
    d0: 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    `...............
    e0: 00 58 01 00 16 2b 03 1e 94 41 ff ff ff ff ff ff    .X?.?+???A......
    f0: ff 00 00 00 00 00 00 80 00 00 80 00 00 80 00 80    .......?..?..?.?
    
    • Datasheet に書かれている以下のレジスタは変化せず。どこかで計測開始のトリガーをかける必要がありそう。

      5.4.7 Register 0xF7…0xF9 “press” (_msb, _lsb, _xsb)
      5.4.8 Register 0xFA…0xFC “temp” (_msb, _lsb, _xsb)
      5.4.9 Register 0xFD…0xFE “hum” (_msb, _lsb)

  • Switch Science さんの Python スクリプトで確認

    • ここの [Clone or download] で落とす。 git clone するか zip で持ってくるか。
    • zip で持ってきた場合、以下で解凍

      pi@raspberrypi:~/Downloads $ unzip BME280-master.zip 
      Archive:  BME280-master.zip
      aabccb113698c97b02fa4c15735588b1399efb34
         creating: BME280-master/
         creating: BME280-master/Arduino/
         creating: BME280-master/Arduino/BME280_I2C/
        inflating: BME280-master/Arduino/BME280_I2C/BME280_I2C.ino  
         creating: BME280-master/Arduino/libraries/
         creating: BME280-master/Arduino/libraries/SSCI_BME280/
        inflating: BME280-master/Arduino/libraries/SSCI_BME280/SSCI_BME280.cpp  
        inflating: BME280-master/Arduino/libraries/SSCI_BME280/SSCI_BME280.h  
         creating: BME280-master/Arduino/libraries/SSCI_BME280/examples/
        inflating: BME280-master/Arduino/libraries/SSCI_BME280/examples/ESP8266_BME280_sample.ino  
        inflating: BME280-master/Arduino/libraries/SSCI_BME280/keywords.txt  
        inflating: BME280-master/LICENSE   
         creating: BME280-master/Python27/
        inflating: BME280-master/Python27/bme280_sample.py  
       extracting: BME280-master/Python27/requirements.txt  
        inflating: BME280-master/README.md  
      
    • 実行したら温湿度気圧が取れたので、動確としては終了。後はスクリプトの中を読めばわかるはず。

      pi@raspberrypi:~/Downloads $ cd BME280-master/Python27/
              
      pi@raspberrypi:~/Downloads/BME280-master/Python27 $ pip install smbus2
      Collecting smbus2
        Using cached https://www.piwheels.org/simple/smbus2/smbus2-0.2.1-py2.py3-none-any.whl
      Installing collected packages: smbus2
      Successfully installed smbus2-0.2.1
              
      pi@raspberrypi:~/Downloads/BME280-master/Python27 $ python bme280_sample.py 
      temp : 25.74  ℃
      pressure : 1013.68 hPa
      hum :  66.61 %
              
      pi@raspberrypi:~/Downloads/BME280-master/Python27 $ python bme280_sample.py 
      temp : 25.76  ℃
      pressure : 1013.66 hPa
      hum :  66.56 %