I found a BME680 example that uses different libraries than the one I used yesterday the raised the unhandled exception error.
The code worked. I was getting sensor data in the serial monitot.
Then I added the 1306 OLED. It compiled and uploaded just fine, and then kerplooey:
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <Adafruit_GFX.h> //Libraries for the OLED and BMP280
#include <Adafruit_SSD1306.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_SSD1306 display(128, 64, &Wire, 8); //Declaring the display name (display)
Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
void setup()
{
Serial.begin(9600);
bme.begin();
while (!Serial)
;
Serial.println(F("BME680 async test"));
if (!bme.begin())
{
Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
while (1)
;
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop()
{
display.clearDisplay();
// Tell BME680 to begin measurement.
unsigned long endTime = bme.beginReading();
if (endTime == 0)
{
Serial.println(F("Failed to begin reading :("));
return;
}
Serial.print(F("Reading started at "));
Serial.print(millis());
Serial.print(F(" and will finish at "));
Serial.println(endTime);
Serial.println(F("You can do other work during BME680 measurement."));
delay(50); // This represents parallel work.
// There's no need to delay() until millis() >= endTime: bme.endReading()
// takes care of that. It's okay for parallel work to take longer than
// BME680's measurement time.
// Obtain measurement results from BME680. Note that this operation isn't
// instantaneous even if milli() >= endTime due to I2C/SPI latency.
if (!bme.endReading())
{
Serial.println(F("Failed to complete reading :("));
return;
}
Serial.print(F("Reading completed at "));
Serial.println(millis());
Serial.print(F("Temperature = "));
Serial.print(bme.temperature);
Serial.println(F(" *C"));
Serial.print(F("Pressure = "));
Serial.print(bme.pressure / 100.0);
Serial.println(F(" hPa"));
Serial.print(F("Humidity = "));
Serial.print(bme.humidity);
Serial.println(F(" %"));
Serial.print(F("Gas = "));
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(F(" KOhms"));
Serial.print(F("Approx. Altitude = "));
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(F(" m"));
Serial.println();
display.setCursor(0, 0); //Oled display, just playing with text size and cursor to get the display you want
display.setTextColor(WHITE);
display.setTextSize(1);
display.print("Temp");
display.setCursor(0, 18);
display.print(bme.temperature, 1);
display.setCursor(50, 17);
display.setTextSize(1);
display.print("C");
display.setTextSize(1);
display.setCursor(65, 0);
display.print("Pres");
display.setCursor(65, 10);
display.print(bme.pressure, 0);
display.setCursor(110, 10);
display.print("hPa");
display.setCursor(65, 25);
display.print("Hum");
display.setCursor(90, 25);
display.print(bme.humidity, 0);
display.setCursor(110, 25);
display.print("m");
display.display();
delay(2000);
}