Chat freely about anything...

User avatar
By Gawan
#41302 Hi,

I have a NodeMCU 1.0 and a WeMos D1 mini.
I want to connect a BME280 sensor via I2C and I am using the Adafruit_BME280_Library

Unfortunately it simply does not work :(

The example code sais:


Adafruit_BME280 bme; // I2C
bme.begin()


Unfortunately I can not set up the I2C pins the way I want. So I have to find out the "original" I2C pins and I don't succeed so far.

All I get is this:
Code: Select allBME280 test
Could not find a valid BME280 sensor, check wiring!

Soft WDT reset

ctx: cont
sp: 3ffefa10 end: 3ffefbf0 offset: 01b0

>>>stack>>>
3ffefbc0:  3fffdc20 00000000 3ffefc3c 40201cb9 
3ffefbd0:  00000000 00000000 3ffeebb4 40202e4e 
3ffefbe0:  00000000 00000000 3ffeebd0 40100114 
<<<stack<<<


My sketch is a very simple one - it looks like this:

Code: Select all/***************************************************************************
  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.

  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
 ***************************************************************************/

#include <Wire.h>
#include <SPI.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);

void setup() {

 
  Serial.begin(115200);
  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);
}


Can anyone help me please to find the right I2C wiring ?

BR
Gawan
User avatar
By martinayotte
#41303 Since this Adafruit_BME280 is generally used by plain Arduino, it assume I2C pins. To make it working on ESP8266, it needs to provide the pin numbers you are using. So, in the library code https://github.com/adafruit/Adafruit_BM ... 80.cpp#L46 , you need to change the line where I2C is been initialized to something like :

Code: Select allWire.begin(0, 2);

Also, make sure to have PullUp resistors, such 4K7, to both SDA/SCL pins
User avatar
By Gawan
#41305 Hi,

I have changed the source code of the library to Wire.begin(0,2) and connected the Pins D3 and D4.

But I did not yet try resistors, because they were not necessary on my UNO where everything works fine ...

you mean:
D3 --- 4K7 ---- SDA
D4 --- 4K7 --- SCL
?