#include #include #include // Change this if you want altitude computed for your location #define SEALEVEL_HPA (1013.25f) // Try both common I2C addresses Adafruit_BME680 bme; // use the default constructor bool beginBME680() { // SDA on pin 21 and SCL on pin 22 Wire.begin(21, 22); // Try 0x76 first if (bme.begin(0x76, &Wire)) { Serial.println("[BME680] Found at 0x76"); return true; } // Then 0x77 if (bme.begin(0x77, &Wire)) { Serial.println("[BME680] Found at 0x77"); return true; } Serial.println("[BME680] Sensor not found at 0x76 or 0x77. Check wiring/power."); return false; } void setupBME680() { // Oversampling & filter settings tuned for ~1 Hz updates bme.setTemperatureOversampling(BME680_OS_8X); bme.setHumidityOversampling(BME680_OS_2X); bme.setPressureOversampling(BME680_OS_4X); bme.setIIRFilterSize(BME680_FILTER_SIZE_3); // Enable gas heater: 320°C for 150 ms (typical example) bme.setGasHeater(320, 150); } void setup() { Serial.begin(115200); while (!Serial) { delay(100); } Serial.println("\n[BOOT] BME680 serial demo (1 Hz)"); if (!beginBME680()) { // Stay here so you can read the error while (true) { delay(1000); } } setupBME680(); } void loop() { // Trigger a reading and wait for completion if (!bme.performReading()) { Serial.println("[BME680] Failed to perform reading!"); delay(1000); return; } // Values from the Adafruit_BME680 library: float temperatureC = bme.temperature; // °C float pressureHpa = bme.pressure / 100.0f; // Pa -> hPa float humidityPct = bme.humidity; // % float gasOhms = bme.gas_resistance; // Ω float altitudeM = bme.readAltitude(SEALEVEL_HPA);// meters (approx.) // Print nicely Serial.print("T: "); Serial.print(temperatureC, 2); Serial.print(" °C | "); Serial.print("RH: "); Serial.print(humidityPct, 1); Serial.print(" % | "); Serial.print("P: "); Serial.print(pressureHpa, 2); Serial.print(" hPa | "); Serial.print("Gas: ");Serial.print(gasOhms, 0); Serial.print(" Ω | "); Serial.print("Alt: ");Serial.print(altitudeM, 1); Serial.println(" m"); // 1 Hz update delay(1000); }