I would like some help on my simple project: i wanted to test a BME280 sensor i got from Aliexpress. I verified that the chip is a BME280 and not a BMP280.
The problem is that I can find the sensor when running an I2C scan, but using the example sketch i get the error message: ``` "Could not find a valid BME280 sensor, check wiring!"
As you can see from the image i uploaded, the scanner finds the sensor ad the address 0x76, but when running the example scketch i get the error.
I have also tried both 3.3V and 5V to power the breakout (instructions from aliexpress page state that it is a 5V board) and there seems to be a voltage regulator on the backside
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-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
See the LICENSE file for details.
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
while(!Serial); // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
// default settings
status = bme.begin();
// 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();
}
which only gets me this error:
BME280 test
20:56:59.055 -> Could not find a valid BME280 sensor, check wiring, address, sensor ID!
20:56:59.119 -> SensorID was: 0x0
20:56:59.151 -> ID of 0xFF probably means a bad address, a BMP 180 or BMP 085
20:56:59.215 -> ID of 0x56-0x58 represents a BMP 280,
20:56:59.247 -> ID of 0x60 represents a BME 280.
20:56:59.311 -> ID of 0x61 represents a BME 680.
Ln 90, Col 2
ALKS ESP32
on COM15
2
the library was installed with the Arduino IDE library manager.
21:26:03.759 -> Scanning...
21:26:03.759 -> I2C device found at address 0x3C
21:26:03.821 -> I2C device found at address 0x76
21:26:03.821 -> done
so it sees correctly the display at 0x3c and the sensor at 0x76. Which should mean that at least the electrical connections are working
i have also tested the same connection without the display and I've changed my ESP32 board for another one, and also tried changing the default I2C pins but i always get the same result: device found by scanner but not recognised from library
Considering that you've already tested the connections and showed the I2C found at 0x76, the only suggestion I have is related to the sensor initialization. Try this version of the code:
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-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
See the LICENSE file for details.
***************************************************************************/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
while(!Serial); // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
// default settings
status = bme.begin(0x76); //<--changed this line
// 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();
}
@Brazilino thanks! yeah Sorry i forgot to mention that I have also tried changing the initialization as you kindly mentioned, in fact you can see in the first image that I posted (with which I learned that is not ideal to screenshot code) that the code already had that change (the begin with the 0x76 address). I'm starting to think the chip is broken, maybe the soldering process killed it, don't know. I just find it weird that the scanner finds it.
I am open to other suggestions if anybody has ideas, thanks
Thank you so much @arneko ! This solved the problem! I installed this library and the example code worked instantly, i was near to throwing it in the trash .