Published Example Script, 'Exception was unhandled'

Good morning!
First day back, and it’s a new opportunity to learn.

I am using an example BME680 script from the libary. It uses an OLED that isn’t doing anything.

I’m using the WeMos D1 Mini/ESP32. The upload looks completely normal.
I messed around with the ESP32 Download Tool, and I thought I screwed it up, but that was the ESP8266 Mini, not this one. And it works fine.

This is the serial output:

Rebooting...
)�
��ܠ��J��1�R���䃔�֊�BME680 test
Guru Meditation Error: Core  1 panic'ed (IntegerDivideByZero). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d3cf0  PS      : 0x00060330  A0      : 0x800d1158  A1      : 0x3ffb1f10  
A2      : 0x3ffbebe8  A3      : 0x00000000  A4      : 0x00000001  A5      : 0x00000015  
A6      : 0x00000000  A7      : 0x3ffbebe8  A8      : 0x800d3cf0  A9      : 0x3ffb1ee0  
A10     : 0x04c4b400  A11     : 0x00000016  A12     : 0x00000000  A13     : 0x00000064  
A14     : 0x00000000  A15     : 0x60013000  SAR     : 0x0000000a  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  

Backtrace: 0x400d3cf0:0x3ffb1f10 0x400d1155:0x3ffb1f30 0x400d1b12:0x3ffb1f50 0x400d0df3:0x3ffb1f80 0x400d4f47:0x3ffb1fb0 0x40088a59:0x3ffb1fd0
1 Like

And this is the code:

/***************************************************************************
  This is a library for the BME680 gas, humidity, temperature & pressure sensor
  Designed specifically to work with the Adafruit BME680 Breakout
  ----> http://www.adafruit.com/products/3660
  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!
  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);

Adafruit_SSD1306 display = Adafruit_SSD1306();

void setup() {
  Serial.begin(9600);
  Serial.println(F("BME680 test"));

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  // init done
  display.display();
  delay(100);
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(WHITE);

  if (!bme.begin()) {
    Serial.println("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.setCursor(0,0);
  display.clearDisplay();

  if (! bme.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = "); Serial.print(bme.temperature); Serial.println(" *C");
  display.print("Temperature: "); display.print(bme.temperature); display.println(" *C");

  Serial.print("Pressure = "); Serial.print(bme.pressure / 100.0); Serial.println(" hPa");
  display.print("Pressure: "); display.print(bme.pressure / 100); display.println(" hPa");

  Serial.print("Humidity = "); Serial.print(bme.humidity); Serial.println(" %");
  display.print("Humidity: "); display.print(bme.humidity); display.println(" %");

  Serial.print("Gas = "); Serial.print(bme.gas_resistance / 1000.0); Serial.println(" KOhms");
  display.print("Gas: "); display.print(bme.gas_resistance / 1000.0); display.println(" KOhms");

  Serial.println();
  display.display();
  delay(2000);
}
1 Like

There are several 1306 OLED screens. I’m surprised it doesn’t specify one. I’m using the 64 x 128.

This is the actual error:

Somewhere in the code, something was divided by zero.

In the register dump, PC is the program counter and is likely to be the address, or thereabouts, of the problem. Not helpful though, unless you have a symbol map created by the compiler - assuming it can do so.

Looking at the code, all obvious divisions look correct - I see no zeros. My assumption is that it’s in the library code.

Good luck finding it. :sob:

Cheers,
Norm.

1 Like

That is indeed a strange one.

I would suggest you add something like …

Serial.println("got this far");
Serial.flush();

… to the code and keep moving it until you find the offending line/statement. You already know the initial Serial.begin()/Serial.printlin() works, so put it before the if (!bme.begin()) test for starters, and see if the message prints before the ESP32 crashes. If it does, the breakage is further down, so move it down. If it doesn’t, the breakage is higher up, so move it up. Reload, repeat. :wink:

The importance of the Serial.flush()? … it ensures anything waiting in the serial buffer (i.e. the message you just told it to send) is sent before moving onto the next bit of code.

Edit: I would also try updating that OLED constructor as it really doesn’t look right -

i.e. change

Adafruit_SSD1306 display = Adafruit_SSD1306();

to

Adafruit_SSD1306 display(128, 64, &Wire);