ArduinoにSCL/SDAが見当たらない場合は,
Arduino SCL —> A5
Arduino SDA —> A4
のように読み替えて下さい。
BME280を動かすには,以下の2つのライブラリが必要です。
Adafruit Unified Sensor
Adafruit BME280
ファイル一式:SSH180217-1
bme280test1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme; // I2C unsigned long delayTime; void setup() { Serial.begin(9600); bool status; // default settings status = bme.begin(0x76); //read I2C address 0x76 if (!status) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } delayTime = 1000; Serial.println(); } void loop() { printValues(); delay(delayTime); } void printValues() { Serial.print("Temperature = "); Serial.print(bme.readTemperature()); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(bme.readPressure() / 100.0F); Serial.println(" hPa"); Serial.print("Approx. Altitude = "); Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); Serial.println(" m"); Serial.print("Humidity = "); Serial.print(bme.readHumidity()); Serial.println(" %"); Serial.println(); } |
bme280test2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme; // I2C unsigned long delayTime; void setup() { Serial.begin(9600); bool status; // default settings status = bme.begin(0x76); //read I2C address 0x76 if (!status) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } delayTime = 1000; Serial.println(); } void loop() { printValues(); delay(delayTime); } void printValues() { Serial.print(bme.readTemperature()); Serial.print(","); Serial.print(bme.readPressure() / 100.0F-1000); Serial.print(","); Serial.print(bme.readHumidity()); Serial.println(); } |