Go Down

Topic: BMP 280 - didn't work (Read 7452 times) previous topic - next topic

MatejKovacic

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:

Code: [Select]
// 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:
Code: [Select]
BME280 test
Could not find a valid BME280 sensor, check wiring!



Any help?

Regards,
M.

LesserMole


MatejKovacic

Yes:

Scanning...
I2C device found at address 0x76  !
done

LesserMole

I2C device found at address 0x76  !
Well I dug out the library your sketch uses from here, and it contains this line:

Code: [Select]

 #define BME280_ADDRESS                (0x77)


So I guess you need to edit the library with the correct address.




MatejKovacic

Hi,

sorry, I- forgot to mention, I actually did this (and it is still not working):

Code: [Select]
/*=========================================================================
    I2C ADDRESS/BITS
    -----------------------------------------------------------------------*/
    #define BME280_ADDRESS                (0x77)

MatejKovacic

OK, I am really sorry... I have several versions of code and I was changing one in one diretory and compiling the other in other directory.


Now it works:

Code: [Select]
Temperature = 26.35 *C
Pressure = 988.90 hPa
Approx. Altitude = 204.73 m
Humidity = 23.47 %


Thanks for your help.


Greenman

Thank you martinius96, with your find program I finally got my weather board to work.

userboy

can any one help me to integrate this code so i can get temp display?

this is the code for screen

Quote
https://www.aliexpress.com/item/1-3-1-3-inch-White-Color-128X64-OLED-LCD-LED-Display-Module-For-Arduino-SPI/32834440673.html?spm=a2g0s.9042311.0.0.2FKerN
Quote
/*

  HelloWorld.pde
 
  "Hello World!" example code.
 
  >>> Before compiling: Please remove comment from the constructor of the
  >>> connected graphics display (see below).
 
  Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/
 
  Copyright (c) 2012, olikraus@gmail.com
  All rights reserved.

  Redistribution and use in source and binary forms, with or without modification,
  are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list
    of conditions and the following disclaimer.
   
  * Redistributions in binary form must reproduce the above copyright notice, this
    list of conditions and the following disclaimer in the documentation and/or other
    materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
*/


#include "U8glib.h"

// setup u8g object, please remove comment from one of the following constructor calls
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
// devices with all constructor calls is here: https://github.com/olikraus/u8glib/wiki/device

U8GLIB_SH1106_128X64 u8g(10, 9, 12, 11, 13); // SW SPI Com: SCK = 10, MOSI = 9, CS = 12, D/C = 11, RESET = 13


void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 22, "Hello World!");
}

void setup(void) {
  // flip screen, if required
  // u8g.setRot180();
 
  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
 
  pinMode(8, OUTPUT);
}

void loop(void) {
  // picture loop
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );
 
  // rebuild the picture after some delay
  //delay(50);
}

luxornet

I use BMP280 and is working properly; the temperature its OK, the pressure is OK but the altitude is displayed 780m (I am at 860m).
How can I correct the altitude?

gwareloth

How can I correct the altitude?

Your library will be using standard pressure of 1013.25hPa, and basing the altitude on that. To get an altimeter to show the correct altitude based on actual local pressure, you need to contact your nearest airfield and get the so-called QNH and use that value in your sketch. But you'll need to change that all the time, since every time the pressure changes, so will your apparent altitude.


pylon

That is the absolute pressure. Do you want the pressure equivalent at sea level? What does the term "absolute pressure" mean for you?

bmp280

I have a problem with adafruit bmp280 sensor

I already tried 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); // SPI hardware
// Adafruit_BMP280 bme (BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
  
void setup () {
  Serial.begin (9600);
  Serial.println (F ("BMP280 test"));
  
  if (! bme.begin ()) {
    Serial.println ("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}
  
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 DOES NOT CONTINUE TO GIVE ME ANYTHING IN THE SERIAL MONITOR
JUST THIS

BMP280 test
Could not find a valid BMP280 sensor, check wiring!



HAVING ALSO THESE LINKS

VIN - 5V
GND-- GND
SCK-- A5
SDI - A4

marine_hm

Code: [Select]
/*BMP280 Barometric/Temp sensor with OLED display

   I2C

   Wiring Diagram:
   SDA from BMP and OLED to A4 Pin on Arduino Uno
   SCL from BMP and OLED to A5 Pin
   GND to GND
   VCC from BMP and OLED to 3V
*/

#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Fonts/FreeSerif9pt7b.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

Adafruit_BMP280 bmp; // I2C

const int led1Pin = 7;// LED to notify Baro is TOO HIGH
const int led2Pin = 8;// LED to notify Baro is TOO LOW

void setup() {
  Serial.begin(9600);
  pinMode(led1Pin, OUTPUT);
  digitalWrite(led1Pin, LOW);// Set led off at start-up
  pinMode(led2Pin, OUTPUT);
  digitalWrite(led2Pin, LOW);// Set led off at start-up

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)

  display.clearDisplay();

  display.setFont(&FreeSerif9pt7b);
  display.setTextColor(WHITE);
  display.setCursor(40, 20);
  display.println( F("BMP280"));
  display.setCursor(20, 45);
  display.println( F("Baro-Sensor"));

  display.display(); // SEND SPLASH SCREEN   Goes away once connected to WiFi

  delay(5000);//  SHOW SPLASH SCREEN FOR 5 SECONDS
  display.clearDisplay();

  Serial.begin(9600);
  display.setFont(&FreeSerif9pt7b);

  Serial.println(F("BMP280 Baro Sensor"));

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    display.clearDisplay();
    display.setCursor(0, 20);
    display.println( F("BMP SENSOR"));
    display.setCursor(0, 50);
    display.println( F("NOT FOUND!"));
    display.display();

    while (1);
  }
}

void loop() {
  display.clearDisplay();


  //  ******************** Temperature **********************
  //  ********************  Farenheit  **********************
  float temp = bmp.readTemperature() * 9.0 / 5.0 + 32.0;//  Convert to F

  display.setFont(&FreeSerif9pt7b);
  Serial.print(F("Temperature = "));
  Serial.print(temp,1);//     ,# sets the number of decimal places
  Serial.println(" *F");
  display.setCursor(0, 20);
  display.print( F("Temp: "));
  display.setCursor(62, 20);
  display.print(temp,1);//    ,# sets the number of decimal places
  display.print(F("   F"));
  display.setFont();//  Assign default font set to display degree symbol
  display.setCursor(100, 8);
  display.print((char)247); // degree symbol


  //  ******************* Pressure **********************
  //  ********************  mmHg  ***********************
  float pressure = bmp.readPressure() * 0.00750061683;
  display.setFont(&FreeSerif9pt7b);
  Serial.print(F("Pressure = "));
  Serial.print(pressure,1);//    ,# sets the number of decimal places
  Serial.println(F(" mmHg"));

  display.setCursor(0, 55);
  display.print( F("mmHg:"));
  display.setCursor(62, 55);
  display.print(pressure,1);//   ,# sets the number of decimal places
  display.display();

  delay(1000);       // UPDATE EVERY 1 SECOND
}

Go Up