Heltec WiFi Lora32 V3 with BME280 sensor

There is a communication problem with the Heltec WiFi LoRa 32(V3), ESP32S3 + SX1262 and BME280 sensor that has internal pull-up resistors.

I scanned the I2C and the result is 0x76. I use pin 41 and 42.
I have already tried with new cables, changing the setClock speed, tested with other heltec devices and bme sensors and changing from 3.3v to 5v.

Some have written that it works properly only with pin 17 and 18, but I have also read about many others who could make it work with other pins so I wanted to ask you if there is something wrong with this code, if I may need to change libraries and/or maybe help me fix it.

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

#define BME_SDA 41
#define BME_SCL 42
#define BME_I2C_ADDRESS 0x76

TwoWire Wire2(1);
Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);
  Serial.println("BME280 ID Test");

  Wire2.begin(BME_SDA, BME_SCL);
  Wire2.setClock(100000);

  if (!bme.begin(BME_I2C_ADDRESS, &Wire2)) {
    Serial.println("Could not find a valid BME280 sensor!");
    Serial.println("Check wiring and address.");
    while (1);
  }

  Serial.print("BME280 Sensor ID: 0x");
  Serial.println(bme.sensorID(), 16);
}

void loop() {
  // Do nothing
}

Thank you in advance

A common problem is that the sensor you got is not actually a BME280, but rather a BMP280. Adafruit in their libraries usually include an example that scans for the chip presence (or it is included in some of the other examples) - it usually gives some information on whether the sensor that was found is actually a BME280 or something that is not really a BME280 but closely related.
Or, if you have some other board like an Arduino, try a BME280 example for that board and check if the sensor is actually alright. That would narrow down the search space significantly :slight_smile:

My esteemed colleague appears to have skipped the first paragraph:

If a scan of the bus is bringing up a device on address 0x76 then you have I2C mostly working. It’s likely which module the driver code is talking to.

You could just swap your code to try a BMP280.

And as ever, provide serial debug output as we don’t know if it’s not finding or reporting an Id issue.

Hey, thank you for your answers.
I have tried also with the BMP280 library but I still get the same error.
Here is the output I receive in the serial monitor with the code I have provided above:

Build:Mar 27 2021

rst:0x1 (POWERON),boot:0x29 (SPI_FAST_FLASH_BOOT)

SPIWP:0xee

mode:DIO, clock div:1

load:0x3fce2820,len:0x1188

load:0x403c8700,len:0x4

load:0x403c8704,len:0xbf0

load:0x403cb700,len:0x30e4

entry 0x403c88ac

BME280 ID Test

Could not find a valid BME280 sensor!

Check wiring and address.

This is the output with the BMP280 library:

Build:Mar 27 2021

rst:0x1 (POWERON),boot:0x28 (SPI_FAST_FLASH_BOOT)

SPIWP:0xee

mode:DIO, clock div:1

load:0x3fce2820,len:0x1188

load:0x403c8700,len:0x4

load:0x403c8704,len:0xbf0

load:0x403cb700,len:0x30e4

entry 0x403c88ac

BMP280 Test

Could not initialize BMP280. Check wiring or I2C address.

Is this BME board from a know good vendor like Adafruit or Sparkfun?

I’ve a collection of BMP/BME boards with odd markings to indicate which type of sensor are on the board, plus various solder jumpers on the PCB, all of which are in the “naughty box” as being a PitA to get running. Plus a few generic sensor boards that just won’t work.

So you may have a clone or badly implemented or just not working board.

If you have a boring old Arduino Uno or Nano I’d try connecting it to that as @bns suggested. And if you have another sensor board, try that. Or even just to sanity check your ESP is working on I2C OK, try a different I2C device.