Go Down

Topic: BME280 Sensor not working (Read 14574 times) previous topic - next topic

nzee

May 13, 2016, 06:58 pm Last Edit: May 13, 2016, 07:05 pm by nzee
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!

Code: [Select]
#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.




Koepel

Thank you for the sharp and large photos.

You are using this ? https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/wiring-and-test

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.

zoomx

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

s-h-a-w-n

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.

zoomx

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.

Eheran

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

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

CrossRoads

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).
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

zoomx

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.

leonline

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

zoomx

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!!!

wvmarle

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.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

zoomx

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

wvmarle

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.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

hnas66

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!

zoomx

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.

Go Up