WeMos (6) BMP180 I2C気圧温度表示

Specification

  • Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
  • Up to 0.03hPa / 0.25m resolution
  • -40 to +85°C operational range, +-2°C temperature accuracy

Wiring

Make the following connections

  • GND <-> GND
  • 3V3 <-> VIN (or 3Vo)
  • D1 <-> SCL
  • D2 <-> SDA

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

BMP180センサーを利用する

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

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

単体プログラム

ただシリアルモニタに表示するだけのプログラム

#include <Wire.h>
#include <Adafruit_BMP085.h>
 
Adafruit_BMP085 bmp;
 
void setup() 
{
  Serial.begin(9600);
  //Wire.begin (4, 5);
  if (!bmp.begin()) 
  {
    Serial.println("Could not find BMP180 or BMP085 sensor at 0x77");
    while (1) {}
  }
}
 
void loop() 
{
  Serial.print("Temperature = ");
  Serial.print(bmp.readTemperature());
  Serial.println(" Celsius");
 
  Serial.print("Pressure = ");
  Serial.print(bmp.readPressure());
  Serial.println(" Pascal");
 
 
  Serial.println();
  delay(5000);
}

1602に表示するプログラム

/*
 * 
 */
#include <Wire.h> 
#include <Adafruit_BMP085.h>
#include <LiquidCrystal_I2C.h>

Adafruit_BMP085 bmp;

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
  lcd.begin(0,2);  // sda=GPIO_0, scl=GPIO_2

  lcd.init();

  // Turn on the backlight.
  lcd.backlight();
    
  // Print a message to the LCD.
  lcd.print("hello, world!");

  if (!bmp.begin()) 
  {
    Serial.println("Could not find BMP180 or BMP085 sensor at 0x77");
    while (1) {}
  }
}

void loop()
{

  lcd.setCursor(0, 0);
  lcd.print("Temp = ");
  lcd.print(bmp.readTemperature());
  lcd.println(" Celsius");
     
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("Pres = ");
  lcd.print(bmp.readPressure());
  lcd.print(" Pascal ");
  lcd.print(millis() / 1000);
}

表示画面

Arduino UNO (6) i2c scanner

i2c のアドレスを確かめるため、下記のプログラムを動かせばいい。

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
 
#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

結果は、シリアルモニターで繰り返し表示する。

Scanning...
I2C device found at address 0x27  !
done

Scanning...
I2C device found at address 0x27  !
done

Scanning...
I2C device found at address 0x27  !
done