- Fri Nov 26, 2021 10:27 am
#92921
I also had problems detecting the sensor myself. The code usually stopped when checking ID "0X60". I used the "BlueDot BME280 Library" version 1.0.9, which can be downloaded in Library Manager.
BME280 -> ID 0x60
BMP280 -> ID 0x58 (!!!! without humidity sensor !!!!)
I used the following code for easier detection: ///////////////////// - START - /////////////////////
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "BlueDot_BME280.h"
BlueDot_BME280 bme = BlueDot_BME280();
float temperature, humidity, pressure, altitude;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // sda= GPIO_21 /scl= GPIO_22
delay(100);
// i2c address scanner code
byte error, address;
int nDevices;
Serial.print("=============================================\n");
nDevices = 0;
for(address = 1; address < 127; 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.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow 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("---------------------------------------------\n");
}
// BMP280/BME280 settings and calibration
bme.parameter.communication = 0; //Choose communication protocol
bme.parameter.I2CAddress = 0x76; //Choose I2C Address
bme.parameter.sensorMode = 0b11; //Choose sensor mode
bme.parameter.IIRfilter = 0b100; //Setup for IIR Filter
bme.parameter.tempOversampling = 0b101; //Setup Temperature Ovesampling
bme.parameter.tempOutsideCelsius = 15; //default value of 15°C
bme.parameter.humidOversampling = 0b101;
bme.parameter.pressOversampling = 0b101;
bme.parameter.pressureSeaLevel = 1013.25; //default value of 1013.25 hPa
bme.init();
// Detecting sensor ID
Serial.println("=============================================");
Serial.print("------------ ID senzorja: 0x"); Serial.print(bme.checkID(),16); Serial.print(" ------------\n");
Serial.println("---------------------------------------------");
Serial.println("ID of 0xFF probably means a bad address, a BMP 180 or BMP 085");
Serial.println("ID of 0x56-0x58 represents a BMP 280");
Serial.println("ID of 0x60 represents a BME 280");
Serial.println("ID of 0x61 represents a BME 680\n");
}
void loop() {
// Printing sensors values
Serial.print("- Temperature :"); Serial.print(bme.readTempC()); Serial.println(" °C");
Serial.print("- Humidity :"); Serial.print(bme.readHumidity()); Serial.println(" [%]");
Serial.print("- Pressure :"); Serial.print(bme.readPressure()); Serial.println(" hPa");
Serial.print("- Altitude :"); Serial.print(bme.readAltitudeMeter()); Serial.println(" m");
delay(30000);
}
///////////////////// - END - /////////////////////
Serial monitor: =============================================
I2C device found at address 0x68
I2C device found at address 0x76
---------------------------------------------
=============================================
------------ ID senzorja: 0x58 ------------
---------------------------------------------
ID of 0xFF probably means a bad address, a BMP 180 or BMP 085
ID of 0x56-0x58 represents a BMP 280
ID of 0x60 represents a BME 280
ID of 0x61 represents a BME 680
- Temperature :28.69 °C
- Humidity :0.00 [%]
- Pressure :946.81 hPa
- Altitude :566.36 m