BMP280 shows wrong datas.

Hi guys, i’m trying to use a BMP280 to see pressure and altitude, but always appears “Temperature 0ºC”, “Pressure 0 hPa” and “Altitude 44330m”
My code is:

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

#define BMP_SCK 2
#define BMP_SDI 14
#define BMP_CS 12
#define BMP_SDO 13


Adafruit_BMP280 bmp280(BMP_CS, BMP_SDI, BMP_SDO,  BMP_SCK);
  
void setup() {
  Serial.begin(9600);
  bmp280.begin();
 
}
  
void loop() {
    // Temperature in Celsius 
    Serial.print("Temperature = ");
    Serial.print(bmp280.readTemperature());
    Serial.println(" *C");
    // Pressure in Pascal 
    Serial.print("Pressure = ");
    Serial.print(bmp280.readPressure());
    Serial.println(" Pa");
    // Altitude in Meters 
    Serial.print("Approx altitude = ");
    Serial.print(bmp280.readAltitude(1013.25)); 
    Serial.println(" m");
    Serial.println();
    delay(2000);
}

I’m using a SPI set, I soldered the pins on the sensor and also tryed to use a BME280 library.
My board is an NODEMCU ESP8266.
I don’t know what’s wrong, help me please! Thanks a lot!

Don't know the BMP specifically, but it looks like you are not actually communicating with the sensor and the sketch is returning the default values, so double check wiring, relevent ports are enabled, and if you can put a 'scope on it to see if you are getting response or find another way to see any write/response.

I see that you are using the Adafruit library but you haven't stated whether or not you are using a sensor module provided by Adafruit. There are two possible I2C addresses for the sensor. Adafruit uses one of them (which is the default for the library) and most other modules use the other.

There's a reason why the Adafruit examples include a check to see if the 'begin' function is successful. You have chosen not to include this test.

Don

Try the I2C scanner to confirm communication with the bus and the I2C address.

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

AmphenolSensors:
Don't know the BMP specifically, but it looks like you are not actually communicating with the sensor and the sketch is returning the default values, so double check wiring, relevent ports are enabled, and if you can put a 'scope on it to see if you are getting response or find another way to see any write/response.

Hi, thanks for share your knowledge, i will try that, but i think the BMP280 wiring is correct.

floresta:
I see that you are using the Adafruit library but you haven't stated whether or not you are using a sensor module provided by Adafruit. There are two possible I2C addresses for the sensor. Adafruit uses one of them (which is the default for the library) and most other modules use the other.

There's a reason why the Adafruit examples include a check to see if the 'begin' function is successful. You have chosen not to include this test.

Don

Alright, i think that i understandod, but i'm using a SPI communication, have i to change this? Or just try to change the I2C address?

groundFungus:
Try the I2C scanner to confirm communication with the bus and the I2C address.

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
 Serial.begin (115200); //*****  make sure serial monitor baud matches *****

// Leonardo: wait for serial port to connect
 while (!Serial)
   {
   }

Serial.println ();
 Serial.println (“I2C scanner. Scanning …”);
 byte count = 0;
 
 Wire.begin();
 for (byte i = 1; i < 120; i++)
 {
   Wire.beginTransmission (i);
   if (Wire.endTransmission () == 0)
     {
     Serial.print (“Found address: “);
     Serial.print (i, DEC);
     Serial.print (” (0x”);
     Serial.print (i, HEX);
     Serial.println (")");
     count++;
     delay (1);  // maybe unneeded?
     } // end of good response
 } // end of for loop
 Serial.println (“Done.”);
 Serial.print (“Found “);
 Serial.print (count, DEC);
 Serial.println (” device(s).”);
}  // end of setup

void loop() {}

Have i to run in my sketch with the code or run in a solo sketch with just the I2C Scan?
Sorry for my unexperience and for the bad english!

Well, if you are using SPI then you are using SPI. I don't understand why the topic of I²C has come in. Have you tried running the example sketch from Adafruit?

dyso:
Well, if you are using SPI then you are using SPI. I don't understand why the topic of I²C has come in. Have you tried running the example sketch from Adafruit?

Sorry about that. I missed his mention of SPI in the original post.

Don

Hi Hotdoug,
With several cheap BMP280s the Adafruit library might not work. Arggh.
Try this one:

//BMP_Nano_001
// Notice -- 3.3 V device - this BMP280 has a voltage regulator on board

// pin layout:
//    VCC --> 5 V
//    GND --> GND
//    SCL --> A5 yellow wire
//    SDA --> A4 green wire

#include "BMP280.h"
#include "Wire.h"
#define P0 1011.30 //            1011.30 calibratieon my location - sea level

BMP280 bmp;

void setup()
{
  Serial.begin (9600);
  if(!bmp.begin()){
    Serial.println("BMP init failed!");
    while(1);
  }
  else Serial.println("BMP init success!");
  
  bmp.setOversampling(4);
  
}
void loop()
{
  double T,P;
  char result = bmp.startMeasurment();
 
  if(result!=0){
    delay(result);
    result = bmp.getTemperatureAndPressure(T,P);
    
      if(result!=0)
      {
        double A = bmp.altitude(P,P0);    
        Serial.print("T = \t");Serial.print(T,2); Serial.print(" degC\t");
        Serial.print("P = \t");Serial.print(P,1); Serial.print(" mBar\t");
        Serial.print("A = \t");Serial.print(A,2); Serial.println(" m");
       
      }
      else {
        Serial.println("Error.");
      }
  }
  else {
    Serial.println("Error.");
  }
  
  delay(1000);
}

Sucess, Photoncatcher

@photoncatcher

Thats not gonna work.

// pin layout:
//    VCC --> 5 V
//    GND --> GND
//    SCL --> A5 yellow wire
//    SDA --> A4 green wire

The code you uploaded is I²C and he is using SPI.

photoncatcher:
Hi Hotdoug,
With several cheap BMP280s the Adafruit library might not work. Arggh.
Try this one:

//BMP_Nano_001

// Notice -- 3.3 V device - this BMP280 has a voltage regulator on board

// pin layout:
//    VCC --> 5 V
//    GND --> GND
//    SCL --> A5 yellow wire
//    SDA --> A4 green wire

#include "BMP280.h"
#include "Wire.h"
#define P0 1011.30 //            1011.30 calibratieon my location - sea level

BMP280 bmp;

void setup()
{
 Serial.begin (9600);
 if(!bmp.begin()){
   Serial.println("BMP init failed!");
   while(1);
 }
 else Serial.println("BMP init success!");
 
 bmp.setOversampling(4);
 
}
void loop()
{
 double T,P;
 char result = bmp.startMeasurment();

if(result!=0){
   delay(result);
   result = bmp.getTemperatureAndPressure(T,P);
   
     if(result!=0)
     {
       double A = bmp.altitude(P,P0);    
       Serial.print("T = \t");Serial.print(T,2); Serial.print(" degC\t");
       Serial.print("P = \t");Serial.print(P,1); Serial.print(" mBar\t");
       Serial.print("A = \t");Serial.print(A,2); Serial.println(" m");
     
     }
     else {
       Serial.println("Error.");
     }
 }
 else {
   Serial.println("Error.");
 }
 
 delay(1000);
}



Sucess, Photoncatcher

Hi dude, thanks for sharing this code, but unfortnutely it's not working too, i think you are right when you say that adafruit library doesn't work with some types of sensors, but i don't know what i have to do now, because i have tryed a lot of ways, i bought a new sensor yesterday and it's still not working, i tested the wiring soldered and without soldered, i don't know what i'm gonna do, maybe i have to buy a different sensor. i'm lost haha.
I don't know if it helps but i'm trying to do this project: Estação meteorológica com NodeMCU | Curto Circuito

They use a different pinning. Did you check your pinning?

It's SPI! Don't get confused with I²C. If you want to use I²C, then connect it correctly.

dyso:
They use a different pinning. Did you check your pinning?

It's SPI! Don't get confused with I²C. If you want to use I²C, then connect it correctly.

I'm very confused about SPI and I2C, if i wanna change the SPI for I2C, what do i have to change in my code and wiring? Because the only thing that i don't test is change the SPI for I2C.
Can you help me with this?

For SPI you have 4 important lines:

  1. SCLK - Serial Clock
    2.MOSI - Master Out Slave In
  2. MISO - Master In Slave Out
  3. SS -Slave select

For I2C you have 2:

  1. SCL - Serial clock
  2. SDA - Serial Data

You should look at the pinout of your board.