It is not recognizing the BME280, however, when I run the I2C Scanner, it finds them…. I have checked many times and I can’t find any problem / solution…. Please help!
enter image description here
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1022)
Adafruit_BME280 bme1; // I2C
Adafruit_BME280 bme2; // I2C
// Select I2C BUS
void TCA9548A(uint8_t bus){
Wire.beginTransmission(0x70); // TCA9548A address
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
}
void printValues(Adafruit_BME280 bme, int bus) {
TCA9548A (bus);
Serial.print("Sensor number on bus");
Serial.println(bus);
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();
}
void setup() {
Serial.begin(115200);
// Start I2C communication with the Multiplexer
Wire.begin();
// Init sensor on bus number 0
TCA9548A(0);
if (!bme1.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor on bus 0, check wiring!");
while (1);
}
Serial.println();
// Init sensor on bus number 1
TCA9548A(1);
if (!bme2.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor on bus 1, check wiring!");
while (1);
}
}
void loop() {
printValues(bme1, 0);
printValues(bme2, 1);
delay(5000);
}
Serial output:
12:02:06.477 -> Could not find a valid BME280 sensor on bus 0, check wiring!
Scanner I2C results:
12:37:34.158 -> TCAScanner ready!
12:37:34.158 -> TCA Port #0
12:37:34.196 -> Found I2C 0x76
12:37:34.196 -> TCA Port #1
12:37:34.196 -> Found I2C 0x76
12:37:34.196 -> TCA Port #2
12:37:34.196 -> TCA Port #3
12:37:34.227 -> TCA Port #4
12:37:34.265 -> TCA Port #5
12:37:34.265 -> TCA Port #6
12:37:34.265 -> TCA Port #7
I need to get the values of those two BME280 sensors, I have the need to put 4 in total, but I have wired these two to test the process….. That is why I am using the multiplexer.
New contributor
Ruben de Jesús Moraga Ramírez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.