WeMos (b2) BMP280 SPI気圧温度表示

 

気圧センサーとNikia 5110と同時に使いたい。

まず前回BMP180センサーの利用を考える。こちらはI2Cで通信する。WemosのPinoutを見ると、SPIとI2Cは共有するなく、同時に使えそうだが、しかしいくら試してもうまくいかない。

そこでBMP280センサーの利用を考える。こちらは、SPIとI2C両方利用可能。

The chip select (CSB) and serial data output (SDO) pins of the BMP 280 are necessary only when SPI-based (four-wire) communication is applied. For SPI, keep an eye on the pin assignments: VCC-VCC/GND-GND/SCL-SCK/SDA-MOSI/CSB-SS/SDO-MISO. Now to the official schematic of the GY-BM E/P 280 module:

Contents

ライブラリの追加

センサーをライブラリ追加

BMP280センサーを利用する

ライブラリからBMP280を検索して、追加してください

スクリーンショット 2017-09-08 15.39.45

 測定値

まずSPIで気圧を測って見る。

/***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor
  Designed specifically to work with the Adafruit BMEP280 Breakout 
  ----> http://www.adafruit.com/products/2651
  These sensors use I2C or SPI to communicate, 2 or 4 pins are required 
  to interface.
  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!
  Written by Limor Fried & Kevin Townsend for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK D5
#define BMP_MISO D6
#define BMP_MOSI D7 
#define BMP_CS D0

// Adafruit_BMP280 bmp; // I2C
Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
// Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  if (!bmp.begin()) {  
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
}

void loop() {
    Serial.print(F("Temperature = "));
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print(F("Pressure = "));
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");

    Serial.print(F("Approx altitude = "));
    Serial.print(bmp.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

シリアルから、ちゃんと表示できた。次はNikia 5110とSPIを仲良くできるか。

Temperature = 26.45 *C
Pressure = 100922.89 Pa
Approx altitude = 33.53 m

次は、気圧センサーとNikia 5110同時に使うため、SPIで通信する環境を作る。