I have buy from aliexpress this BMP 280 sensor. https://www.aliexpress.com/item/I2C-SPI-BMP280-3-3-Digital-Barometric-Pressure-Altitude-Sensor-High-Precision-Atmospheric-Module-for-arduino/32784469406.html?spm=2114.13010608.0.0.vhooc7
I used many libraries and sketches but it didn't work. I still have 0°C as temperature 0Pa and -21 000 meters.. I don't know how to do. Thanks to everyone for help. If you have similar sensor, please send sketch to me with libraries, you help me so much.
Please post links to the libraries you used. The module on aliexpress is cheaper than you get the sensor in the thousands so it might be a fake...
Post a wiring diagram of how you connected the sensor to the Arduino. And tell us which type of Arduino you use.!
Post the code you use for the tests.
This sensor has an I2C and an SPI interface so the wiring and the code has to match each other.
I used many .ino files and many BMP280.h libraries, Adafruit_Sensor library, Adabruit BMP280.h BMP180.h, also tried BME libraries. This sensor have BME280, but BMP280 too write at bottom. No one worked from these libraries. I am so sad guys.
I just received mine a few days back. I wired it for SPI and the default sketch is I2C
Your's looks like it may be a knock-off. No-where does it say made with a Bosch sensor.
Anyway,
Here's the sketch I used for my sensor, it works just fine:
Arduino Uno
13 - SCK
12 - SDO
11 - SDI
10 - CS
3.3V - VIN
GND - GND
/***************************************************************************
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 and open-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 BME_SCK 13// SCK to Pin 13
#define BME_MISO 12// SDO to Pin 12
#define BME_MOSI 11// SDI to Pin 11
#define BME_CS 10// CS to Pin 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("My weather station"));
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() * 9 / 5 + 32); // (reads in C) C * 9/5 + 32 to convert to "F"
Serial.println(" *F");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
// Serial.print("Approx. Altitude = ");
// Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)+4);// +4 to correct altitude
// Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" % ");
Serial.println();
delay(2000);
}
Then, I suspect you've wired it wrong.
Let us know what your connecting it to (Uno, Nano, Mega)?, How are you wiring it?
Like this:
Arduino Uno - BME
13 - SCK
12 - SDO
11 - SDI
10 - CS
3.3V - VIN
GND - GND
I am using Uno R3 (CH340 edition)
I got bad cables, original cables will came to me soon, but they worked, all work, i used it with DS18B20 sensor and worked good.
So, back to our BMP280. I take picture there too. Click and open it in in full resolution
My wiring:
VCC --> 3V
GND --> GND
SCK/SCL --> 13 PIN
SDA/SDI --> 11 PIN
CSB --> 10 PIN
SDO --> 12 PIN
Pins that came with the sensor, are not soldered, it can also be a problem?
martinius96:
Pins that came with the sensor, are not soldered, it can also be a problem?
Wait... What? Yes, that would be a BIG problem
Assuming since no further questions, you soldered the board and it works?
@martinius96 Well? How'd you make out? Does it work?
I soldered pins and it work. But.. Original Adafruit/Bosch libraries didn't work still sensor not found.
I found link to download .ino file at my manufacturer.
I got this code:
#include <Wire.h>
#define BME280_ADDRESS 0x76
unsigned long int hum_raw,temp_raw,pres_raw;
signed long int t_fine;
uint16_t dig_T1;
int16_t dig_T2;
int16_t dig_T3;
uint16_t dig_P1;
int16_t dig_P2;
int16_t dig_P3;
int16_t dig_P4;
int16_t dig_P5;
int16_t dig_P6;
int16_t dig_P7;
int16_t dig_P8;
int16_t dig_P9;
int8_t dig_H1;
int16_t dig_H2;
int8_t dig_H3;
int16_t dig_H4;
int16_t dig_H5;
int8_t dig_H6;
void setup()
{
uint8_t osrs_t = 1; //Temperature oversampling x 1
uint8_t osrs_p = 1; //Pressure oversampling x 1
uint8_t osrs_h = 1; //Humidity oversampling x 1
uint8_t mode = 3; //Normal mode
uint8_t t_sb = 5; //Tstandby 1000ms
uint8_t filter = 0; //Filter off
uint8_t spi3w_en = 0; //3-wire SPI Disable
uint8_t ctrl_meas_reg = (osrs_t << 5) | (osrs_p << 2) | mode;
uint8_t config_reg = (t_sb << 5) | (filter << 2) | spi3w_en;
uint8_t ctrl_hum_reg = osrs_h;
Serial.begin(9600);
Wire.begin();
writeReg(0xF2,ctrl_hum_reg);
writeReg(0xF4,ctrl_meas_reg);
writeReg(0xF5,config_reg);
readTrim(); //
}
void loop()
{
double temp_act = 0.0, press_act = 0.0,hum_act=0.0;
signed long int temp_cal;
unsigned long int press_cal,hum_cal;
readData();
temp_cal = calibration_T(temp_raw);
press_cal = calibration_P(pres_raw);
hum_cal = calibration_H(hum_raw);
temp_act = (double)temp_cal / 100.0;
press_act = (double)press_cal / 100.0;
hum_act = (double)hum_cal / 1024.0;
Serial.print("TEMP : ");
Serial.print(temp_act);
Serial.print(" DegC PRESS : ");
Serial.print(press_act);
Serial.print(" hPa HUM : ");
Serial.print(hum_act);
Serial.println(" %");
delay(1000);
}
void readTrim()
{
uint8_t data[32],i=0; // Fix 2014/04/06
Wire.beginTransmission(BME280_ADDRESS);
Wire.write(0x88);
Wire.endTransmission();
Wire.requestFrom(BME280_ADDRESS,24); // Fix 2014/04/06
while(Wire.available()){
data[i] = Wire.read();
i++;
}
Wire.beginTransmission(BME280_ADDRESS); // Add 2014/04/06
Wire.write(0xA1); // Add 2014/04/06
Wire.endTransmission(); // Add 2014/04/06
Wire.requestFrom(BME280_ADDRESS,1); // Add 2014/04/06
data[i] = Wire.read(); // Add 2014/04/06
i++; // Add 2014/04/06
Wire.beginTransmission(BME280_ADDRESS);
Wire.write(0xE1);
Wire.endTransmission();
Wire.requestFrom(BME280_ADDRESS,7); // Fix 2014/04/06
while(Wire.available()){
data[i] = Wire.read();
i++;
}
dig_T1 = (data[1] << 8) | data[0];
dig_T2 = (data[3] << 8) | data[2];
dig_T3 = (data[5] << 8) | data[4];
dig_P1 = (data[7] << 8) | data[6];
dig_P2 = (data[9] << 8) | data[8];
dig_P3 = (data[11]<< 8) | data[10];
dig_P4 = (data[13]<< 8) | data[12];
dig_P5 = (data[15]<< 8) | data[14];
dig_P6 = (data[17]<< 8) | data[16];
dig_P7 = (data[19]<< 8) | data[18];
dig_P8 = (data[21]<< 8) | data[20];
dig_P9 = (data[23]<< 8) | data[22];
dig_H1 = data[24];
dig_H2 = (data[26]<< 8) | data[25];
dig_H3 = data[27];
dig_H4 = (data[28]<< 4) | (0x0F & data[29]);
dig_H5 = (data[30] << 4) | ((data[29] >> 4) & 0x0F); // Fix 2014/04/06
dig_H6 = data[31]; // Fix 2014/04/06
}
void writeReg(uint8_t reg_address, uint8_t data)
{
Wire.beginTransmission(BME280_ADDRESS);
Wire.write(reg_address);
Wire.write(data);
Wire.endTransmission();
}
void readData()
{
int i = 0;
uint32_t data[8];
Wire.beginTransmission(BME280_ADDRESS);
Wire.write(0xF7);
Wire.endTransmission();
Wire.requestFrom(BME280_ADDRESS,8);
while(Wire.available()){
data[i] = Wire.read();
i++;
}
pres_raw = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
temp_raw = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
hum_raw = (data[6] << 8) | data[7];
}
signed long int calibration_T(signed long int adc_T)
{
signed long int var1, var2, T;
var1 = ((((adc_T >> 3) - ((signed long int)dig_T1<<1))) * ((signed long int)dig_T2)) >> 11;
var2 = (((((adc_T >> 4) - ((signed long int)dig_T1)) * ((adc_T>>4) - ((signed long int)dig_T1))) >> 12) * ((signed long int)dig_T3)) >> 14;
t_fine = var1 + var2;
T = (t_fine * 5 + 128) >> 8;
return T;
}
unsigned long int calibration_P(signed long int adc_P)
{
signed long int var1, var2;
unsigned long int P;
var1 = (((signed long int)t_fine)>>1) - (signed long int)64000;
var2 = (((var1>>2) * (var1>>2)) >> 11) * ((signed long int)dig_P6);
var2 = var2 + ((var1*((signed long int)dig_P5))<<1);
var2 = (var2>>2)+(((signed long int)dig_P4)<<16);
var1 = (((dig_P3 * (((var1>>2)*(var1>>2)) >> 13)) >>3) + ((((signed long int)dig_P2) * var1)>>1))>>18;
var1 = ((((32768+var1))*((signed long int)dig_P1))>>15);
if (var1 == 0)
{
return 0;
}
P = (((unsigned long int)(((signed long int)1048576)-adc_P)-(var2>>12)))*3125;
if(P<0x80000000)
{
P = (P << 1) / ((unsigned long int) var1);
}
else
{
P = (P / (unsigned long int)var1) * 2;
}
var1 = (((signed long int)dig_P9) * ((signed long int)(((P>>3) * (P>>3))>>13)))>>12;
var2 = (((signed long int)(P>>2)) * ((signed long int)dig_P8))>>13;
P = (unsigned long int)((signed long int)P + ((var1 + var2 + dig_P7) >> 4));
return P;
}
unsigned long int calibration_H(signed long int adc_H)
{
signed long int v_x1;
v_x1 = (t_fine - ((signed long int)76800));
v_x1 = (((((adc_H << 14) -(((signed long int)dig_H4) << 20) - (((signed long int)dig_H5) * v_x1)) +
((signed long int)16384)) >> 15) * (((((((v_x1 * ((signed long int)dig_H6)) >> 10) *
(((v_x1 * ((signed long int)dig_H3)) >> 11) + ((signed long int) 32768))) >> 10) + (( signed long int)2097152)) *
((signed long int) dig_H2) + 8192) >> 14));
v_x1 = (v_x1 - (((((v_x1 >> 15) * (v_x1 >> 15)) >> 7) * ((signed long int)dig_H1)) >> 4));
v_x1 = (v_x1 < 0 ? 0 : v_x1);
v_x1 = (v_x1 > 419430400 ? 419430400 : v_x1);
return (unsigned long int)(v_x1 >> 12);
}
It works only for Temperature and Pressure. I got humidity still 0%. Can this chip record altitude or not?
Should i try it like it is on that page with Digital Pins? I got it on analog only now.
VCC --> 3.3V
GND --> GND
SCK --> A5
SDI --> A4
If I will try it to digital pins, must i use Resistors? If yes how strong? 1kOhm? 4,7kOhm?
Working with another .ino file! Now i have cca 920 HPa as pressure. It is okay? I am at 800 meters altitude and there is -2°C and there is snowing and is cloudy.
Altitude is calculated by barometric pressure. That pressure changes daily as the weather changes. It does calculate altitude. If you were to want to calculate the flight of a rocket, weather balloon or whatever. Easiest way I see to do that would be to take the measurement and zero it out and re-uploading the sketch.
like this..
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)+4);// +4 to correct altitude
Serial.println(" m");
You would either add or subtract your previous reading to make it zero.
I got now this code:
#include <Wire.h>
#include "SPI.h" //Why? Because library supports SPI and I2C connection
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP280.h"
Adafruit_BMP280 bmp; // I2C
float pressure; //To store the barometric pressure (Pa)
float temperature; //To store the temperature (oC)
float altimeter; //To store the altimeter (m) (you can also use it as a float variable)
void setup() {
bmp.begin(); //Begin the sensor
Serial.begin(9600); //Begin serial communication at 9600bps
}
void loop() {
//Read values from the sensor:
pressure = bmp.readPressure() / 100;
temperature = bmp.readTemperature();
altimeter = bmp.readAltitude (1020.60); //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)
//Print values to serial monitor:
Serial.print(F("Pressure: "));
Serial.print(pressure) ;
Serial.print(" HPa");
Serial.print("\t");
Serial.print(("Temp: "));
Serial.print(temperature);
Serial.print(" oC");
Serial.print("\t");
Serial.print("Altimeter: ");
Serial.print(altimeter); // this should be adjusted to your local forcase
Serial.println(" m");
delay(10000); //Update every 5 sec
}
I got now problem with that:
altimeter = bmp.readAltitude (1020.60); //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)
What to do with that? Now is in my city 1020.60 HPa. But it will change what then? What take there? Some average of HPa for year? Thanks for reply.
Barometric pressure changes daily with the weather. So if you were to use your sensor for altitude, you would have to readjust daily. I just commented it out.
"Barometric pressure changes daily with the weather."
Or hourly.
Okay guys, i understand it will change during day. Can you tell me how can i convert relative pressure, for instance i got 920hPa at altitude 813 meters at -1°C. How to convert it to absolute pressure? Thank you so much
Hi,
I bought this sensor from AliExpress:
https://www.aliexpress.com/item/3In1-BME280-GY-BME280-Digital-Sensor-SPI-I2C-Humidity-Temperature-and-Barometric-Pressure-Sensor-Module-1/32817812439.html
Itis BME/BMP280, and has 4 pins:
- VIN
- GND
- SCL
- SDA
I connected them the following:
VIN --- 3.3V
GND --- GND
SCL --- Arduino Nano A5
SDA --- Arduino Nano A4
Then I try to run this code:
// https://github.com/adafruit/Adafruit_BME280_Library/blob/master/examples/bme280test/bme280test.ino
/***************************************************************************
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. The device's I2C address is either 0x76 or 0x77.
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 </home/matej/Arduino/BMP280_Barometer/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); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
Serial.println(F("BME280 test"));
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop() {
printValues();
delay(delayTime);
}
void printValues() {
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();
}
... and it just prints:
BME280 test
Could not find a valid BME280 sensor, check wiring!
Any help?
Regards,
M.
See if an I2C scanner finds it.
Yes:
Scanning...
I2C device found at address 0x76 !
done
MatejKovacic:
I2C device found at address 0x76 !
Well I dug out the library your sketch uses from here, and it contains this line:
#define BME280_ADDRESS (0x77)
So I guess you need to edit the library with the correct address.
Hi,
sorry, I- forgot to mention, I actually did this (and it is still not working):
/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define BME280_ADDRESS (0x77)