Nano ESP32 I2C BME280 not working

Hello
I try to set up a new project with my Nano ESP32 and a BME280 connected via the I2C bus.

Layout BME280:
VCC --> ESP32 Pin 3.3V
GND --> ESP32 Pin GND
SCL --> ESP32 Pin A5
SDA --> ESP32 Pin A4

Used Code:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>


#define I2C_SDA 11  //GPIO 11 --> A5
#define I2C_SCL 12  //GPIO 12 --> A4

#define SEALEVELPRESSURE_HPA (1013.25)

TwoWire I2CBME = TwoWire(0);
Adafruit_BME280 bme; // I2C

unsigned long delayTime;

void setup() {
    
    
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));
    
    unsigned status;
    
    
    I2CBME.begin(I2C_SDA, I2C_SCL, 100000);
    status = bme.begin(0x76, &I2CBME);
     
    // You can also pass in a Wire library object like &Wire2
    // status = bme.begin(0x76, &Wire2)
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        //while (1) delay(10);
    }
    
    Serial.println("-- Default Test --");
    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();
}

In the Arduino IDE I used the Setting: Pin numbering "By GPIO Number". I need this seeting cause of the second part of my project which is a connection to a wireshark e paper display via SPI which is already working fine. So I like to continue with this setting. Means at the end I like to have the e paper display working together with the BME280. So I tried to test the BME280 in a seperate check with this code.

Fault behaviour: The BME280 is not been detected. The status variable returns a fault value and serial Monitor displays: "Could not find a valid BME280 sensor, check wiring, address, sensor ID!"

Is this a know problem?
Thanks for helping me.
Best regards Mascho

Do you know what GPIO pins are reserved for I2C?

1 Like

Posting an annotated schematic would be very helpful. Be sure to include the GPIO numbers as well as the pin numbers you are using. This will make it much easier to understand your setup and provide accurate assistance.

Layout BME280:
VCC --> ESP32 Pin 3.3V
GND --> ESP32 Pin GND
SCL --> ESP32 Pin A5, GPIO 11
SDA --> ESP32 Pin A4, GPIO 12

I checked the A4 and A5 Pins with an Oszi and can see there is some communication. Nevertheless the BME280 will not be recognized and a continous communication e.g. for temp reading will not take place.
I also checked with second Nano ESP32 and second BME280. No effect.

What happens when you try the i2c scanner sketch?

Did you check the i2c address with an address scanner?
Is your BMP280 a 5V device or a 3.3V device? You may have damaged it when a 3.3V devices is exposed to 5V control signals (my BMP280 /UNO works good this combination isprogrammed via a BMP280.h library - I suggest to test alternative libraries! ).
success, Photoncatcher

In the mean time I have added my CCS811 sensor to the same I2C Bus. CCS811 is working fine. BME280 still silent.

#include"Adafruit_CCS811.h"
#include <Adafruit_BME280.h>

Adafruit_CCS811 ccs;
Adafruit_BME280 bme;


void setup() {

  unsigned status;
  
  Serial.begin(9600);
  Serial.println("CCS811 test");
  if(!ccs.begin())
  {
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }

    status = bme.begin();



// Warten, bis der Sensor bereit ist while(!ccs.available());
}
void loop()
{
  if(ccs.available())
  {
    if(!ccs.readData())
    {
      Serial.print("CO2: ");
      Serial.print(ccs.geteCO2());
      Serial.print("ppm, TVOC: ");
      Serial.println(ccs.getTVOC());
    }
  }

  delay(1000);

    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");


  delay(1000);



}

Serial Monitor:
11:54:36.031 -> CO2: 454ppm, TVOC: 8
11:54:37.014 -> Temperature = 0.00 °C
11:54:38.043 -> CO2: 447ppm, TVOC: 7
11:54:39.021 -> Temperature = 0.00 °C
11:54:40.050 -> CO2: 418ppm, TVOC: 2
11:54:41.040 -> Temperature = 0.00 °C

The i2c scanner reports:
12:02:50.306 -> Scanning for I2C devices ...
12:02:50.306 -> I2C device found at address 0x5A
12:02:50.352 -> I2C device found at address 0x76

5A is the CCS811
76 the BME280 but still getting no datas back

Try

  status = bme.begin(0x76);
  if(!status)
  {
    Serial.println("Failed to start BME280 sensor! Please check your wiring.");
    while(1);
  }

Is hitting the "while(1)" endless loop.

I also tried with second lib package from "Spark Fun BME280". Same result, BME280 not working.

The SCL (clockline) is running with 10us period means 100kHz. Maybe too fast for the BME280 when connected to Nano ESP32?

Bosch Datasheet tells: Digital interface I²C up to 3.4 MHz

That's the standard/default i2c speed. Your other sensor is working ok at that same speed. I do not think it is a problem.

Try your other BME280 again but with the modified sketch.

I tested now 3 of the BME280 with my Nano ESP32. No way, all are not running.
Then I took my old Uno Board and same result as with the Nano ESP32. The I2C scanner will detect the ASIC but a further communication is not possible.
I feel the ASICs are damaged for some reason. Will buy some new one and then check again.
Will close the topic for now and will reopen once new ASICs are tested.

Thank you all for your help and your inputs for supporting me.
Best regards
Mascho

2 Likes