Problem with BMP280 and NodeMCU v3

I have a problem with the BMP280 sensor, I connect SCL to D1, SDA to D2, GND to GND and VCC to VCC of the NodeMCU v3.
I use this code

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

//Adafruit_BMP280 bme; // I2C
Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
  
void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  while (!bme.begin(0x76)) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    delay(1000);
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

And it gives me this

Could not find a valid BMP280 sensor, check wiring!

I try to change 0x77 to 0x76 but it still doesn't work.

Hi @namodev

run the code
I2C Scanner - esp8266 learning

to identify the address and if your I2C interface works correctly.

RV mineirin

It's giving me this

Scanning...
No I2C devices found

Hi @namodev

here's something weird.

In the description you say that your BMP280 module is connected to:
SCL to D1, SDA to D2, GND to GND and VCC to VCC.
So I made the assumption that he was I2C.
But in your code you use the pins of a SPI module.
After all, is your module I2C or SPI?

PS: I think it accepts both modes.

Pinouts

Save Subscribe

adafruit_products_BMP280_top_pinouts.jpg

sensors_pinout.jpg

Power Pins:

  • Vin - this is the power pin. Since the sensor chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
  • 3Vo - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
  • GND - common ground for power and logic

SPI Logic pins:

All pins going into the breakout have level shifting circuitry to make them 3-5V logic level safe. Use whatever logic level is on Vin!

  • SCK - This is the SPI Clock pin, its an input to the chip
  • SDO - this is the Serial Data Out / Microcontroller In Sensor Out pin, for data sent from the BMP280 to your processor
  • SDI - this is the Serial Data In / Microcontroller Out Sensor In pin, for data sent from your processor to the BMP280
  • CS - this is the Chip Select pin, drop it low to start an SPI transaction. Its an input to the chip

If you want to connect multiple BMP280's to one microcontroller, have them share the SDI, SDO and SCK pins. Then assign each one a unique CS pin.

I2C Logic pins:

  • SCK - this is also the I2C clock pin (SCL), connect to your microcontroller's I2C clock line.
  • SDI - this is also the I2C data pin (SDA), connect to your microcontroller's I2C data line.

Are you using these 2 pins for I2S?
SCK - this is also the I2C clock pin (SCL), connect to your microcontroller's I2C clock line.
SDI - this is also the I2C data pin (SDA), connect to your microcontroller's I2C data line.

RV mineirin

I just don't know whats is SPI, before I use I2C.

And this is my sensor

Hi @namodev
This is I2C.
But your sketch is for SPI.

RV mineirin

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
  
void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  while (!bme.begin(0x76)) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    delay(1000);
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

This still doesn't work