BME280 Sensor not working

Hello,

I’m using an Arduino UNO to read a BME280 sensor. However, when I send it the test code it outputs:

Could not find a valid BME280 sensor, check wiring!

#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);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BME280 test"));

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}

void loop() {
    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();
    delay(2000);
}

I’ve tried re-wiring and the 12c wiring but the yield the same result. Any advice is greatly appreciated.

Thank you for the sharp and large photos.

You are using this ? Arduino Test | Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout | Adafruit Learning System

Your wiring is for hardware SPI. Both hardware SPI and software SPI should work.
I think everything is wired okay.

I would like the see the bottom side of the module to check your soldering.
Could you move it to another location on the breadboard ? Some breadboards are low quality.
Perhaps the sensor module is broken.
Do you have a multimeter to measure the voltages of the module ?

Perhaps the I2C is a little easier. You can connect the wires and measure the voltages while the i2c_scanner is running.
http://playground.arduino.cc/Main/I2cScanner.

At this moment, the soldering of the pins is the first thing to check.

Check the address with an I2C scanner. My bme280 is on 76 and not 77 as in the Adafruit library.

1 Like

That was my problem, thank you!

Changing #define BME280_ADDRESS (0x77) for #define BME280_ADDRESS (0x76) in the library's Adafruit_BME280.h solved the problem.

1 Like

BME280 is a SPI or I2C sensor. It has two I2C addresses 0x77 and 0x76. The first is the default address, to have the latter you have to put SDO line to GND.
Adafruit boards have SPI and I2C pins so you can choose which address to use but cheap I2C only boards doesn't allow to choose the address.

Why do u need the address when connecting it to SPI?

OT: Is there a (easy) way to use existing SPI-pins as I2C?

See page 11, 30, 38
https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf
In SPI mode, there is a discrete slave select line to select the part that will respond, vs an address in I2C mode that the part must watch for and respond to.

If multiple parts are to be used, then pin 5, SDO, can be used as a chip select in I2C mode. Drive each devices SDO high with a unique signal. Drive SDO Low to one device and access it at address 76 - the other will be looking for address 77 and will not respond.
The SDOs can be from a shift register if you are short on pins.
Tho, if you had that many devices and chip select pins, I don't know why you wouldn't use the much faster SPI (up to 8 MHz) vs the slower I2C (400 KHz).

Usually these sensors take time for a measurement so faster SPI is useless.
If we talk about displays or ADCs you’re absolutely right, SPI is much better.

s-h-a-w-n:
Changing #define BME280_ADDRESS (0x77) for #define BME280_ADDRESS (0x76) in the library's Adafruit_BME280.h solved the problem.

Thank you. Solved my problem :wink:

Reading the documentation (I did it very late!!!!) it seems that you can use bme.begin(0x77) instead of changing the library as I did before.
I should have read the F.... manual!!!

CrossRoads:
Tho, if you had that many devices and chip select pins, I don't know why you wouldn't use the much faster SPI (up to 8 MHz) vs the slower I2C (400 KHz).

I2C: two pins for up to 128 devices. More than fast enough for the few bytes that you read from a sensor.
SPI: three pins for the bus plus one SS pin for each device. Makes you run out of pins fast.

For me, it's SPI for the MicroSD and I2C for just about everything else.

If you want to use more sensors, if all share the same address, may be difficult.

On the ESP8266 I'd just open a second I2C bus for such a situation, if it ever happens. Don't know how well the ATmega handles that. It just takes two extra pins, still a easy win over SPI in pin count: four BME280 sensors take seven pins for SPI, or four pins with two I2C buses. Well, I'm sure you can come up with a situation where it happens.

zoomx:
Check the address with an I2C scanner. My bme280 is on 76 and not 77 as in the Adafruit library.

after spending many hours changing esp, trying different ports I found that this was the problem, thanks!

When you have problems using an I2C chip the first action is to discover if it works using an I2C scanner taking care that some few chips have an address that is not recognized by the scanner because is longer that expected, 10 bits instead of 8, if I remember.

I2C standard address length is 7 bits.

10 bits gets tricky as it's more than a byte.

It is a new addressing
https://www.i2c-bus.org/addressing/10-bit-addressing/

Guys,

Hope you don’t mind asking the same question again.

I use this BME280, but when I try to run the same bme280test sketch as mentioned above the serial monitor doesn’t give any readings.

Only message on serial monitor: BME280 test

On the I2C_scanner: I2C Scanner
Scanning …

I use a stock Arduino Uno and the BME280 is connected I2C through pins A4 and A5 for SDA and SCL.

Best regards,
Mischa

If you don't see it show up on the I2C scanner, check wiring, make sure it's all connected properly.
If still nothing, take another - preferably known good - sensor, see if that one works. That confirms whether your wiring and so is correct, and that the other sensor is probably defective.
If you also don't see the known good one, start working on your wiring.

Well, the wiring is not that hard. 5V and GND from the Arduino board, Pin A5 to SCL, Pin A4 to SDA and 2 pullups from +5V to SDA and SCL.

I already tried another BPE280, but it "performs" the same (does nothing).

Yes, 5V is correct as the breakout board has an internal voltage regulator.

Regards,
Mischa