Instead using the ESP32, I connected a BME680 to a Heltec LoRa 32 V2 board.
As per Rui’s instruction in the I2C chapter, I wrote an address scanner (with special twowire handling to reflect changed SCA and SDL pins) and identified 0x77 as sensor. Which is correct.
Now I tried to change the BME680 sample code to also reflect different pins for SCA and SDL.
My code doesn’t work. – Any idea what needs to be changed?
/***************************************************************************
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
#include
#include “Adafruit_BME680.h”
#define I2C_SDA 17
#define I2C_SCL 22
/*
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
*/
#define SEALEVELPRESSURE_HPA (1013.25)
TwoWire I2CBME = TwoWire(0);
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);
Serial.println(F(“BME680 test”));
I2CBME.begin(I2C_SDA, I2C_SCL, 100000);
bool status;
status = bme.begin(0x77, &I2CBME);
if (!status) {
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() {
if (! bme.performReading()) {
Serial.println(“Failed to perform reading :(“);
return;
}
Serial.print(“Temperature = “);
Serial.print(bme.temperature);
Serial.println(” *C”);
Serial.print(“Pressure = “);
Serial.print(bme.pressure / 100.0);
Serial.println(” hPa”);
Serial.print(“Humidity = “);
Serial.print(bme.humidity);
Serial.println(” %”);
Serial.print(“Gas = “);
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(” KOhms”);
Serial.print(“Approx. Altitude = “);
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(” m”);
Serial.println();
delay(2000);
}
Error message: Failed to perform reading 🙁
Any help would be great and enjoy the peaceful time between the years!
-Pit
Hi.
I think you may be missing some steps to get reading from the sensor.
Check our basic tutorial here: https://randomnerdtutorials.com/esp32-bme680-sensor-arduino/
You’re missing this initialization:
// Tell BME680 to begin measurement.
unsigned long endTime = bme.beginReading();
if (endTime == 0) {
Serial.println(F("Failed to begin reading :("));
return;
}
if (!bme.endReading()) {
Serial.println(F("Failed to complete reading :("));
return;
}
After this initialization, you can get the readings.
Let me know if this solves the issue.
I haven’t used that sensor for a while, so I’m not quite sure.
Regards,
Sara
Hi Sara,
Thank you for your suggested code for initialization. –
The BME680 sensor is not detected anymore and
status = bme.begin(0x77, &I2CBME);
remains to stay permanently false.
Now I am back to the modified I2C Scanner, as I need to get the BME-Sensor detected in the first place.
8 : [ Well, sometimes it simply doesn’t work!
I’ll try another known working I2C device, to find common ground and at least detecting something.
If we don’t read us anymore, I’ll wish you, Rui and all ESP aficionados a peaceful new year and thanks a lot for your great support in the past year!
Yours Loetluemmel!
Hi.
Thank you. I also wish you a happy new year.
Make sure the sensor is properly connected and that it can be found by an I2C scanner sketch before proceeding.
Remember that if you’re not using the default I2C pins, you also need to change them on the I2C scanner sketch,
Regards,
Sara