negative altitude out of the bme280

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

negative altitude out of the bme280

Post by mromero »

i am running a BME280 on a datalogger shield and Metro 328 all from adafruit. Using I2C connection

for some reason the output using the example bme280 test is negative? I attched the code used in case i have a typo y missed.

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. 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
  See the LICENSE file for details.
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <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);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));

    unsigned status;
    
    // default settings
    status = bme.begin();  
    // You can also pass in a Wire library object like &Wire2
    // status = bme.begin(0x76, &Wire2)
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
    
    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();
}
Attachments
output bme280.png
output bme280.png (20.13 KiB) Viewed 510 times

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: negative altitude out of the bme280

Post by adafruit_support_bill »

Have you set the current sea-level pressure as reported by your local weather station?

User avatar
sj_remington
 
Posts: 994
Joined: Mon Jul 27, 2020 4:51 pm

Re: negative altitude out of the bme280

Post by sj_remington »

Change this line to the current sea level pressure in your area.

Code: Select all

#define SEALEVELPRESSURE_HPA (1013.25)

User avatar
mromero
 
Posts: 94
Joined: Fri Mar 18, 2016 12:10 pm

Re: negative altitude out of the bme280

Post by mromero »

No i did not realize i had to change that i will find it and try that thanks

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: negative altitude out of the bme280

Post by adafruit_support_bill »

Note that this will change with the weather. Pilots need to calibrate their altimeters to the ground-based sensors at the airport prior to takeoffs and landings.

User avatar
sj_remington
 
Posts: 994
Joined: Mon Jul 27, 2020 4:51 pm

Re: negative altitude out of the bme280

Post by sj_remington »

If you know the current altitude, it is very simple to calibrate the altimeter by calculating the equivalent sea level pressure, and then back-substitute. Subsequently the measured altitude will agree with the actual altitude, until the local air pressure changes significantly (can happen in minutes, or remain stable for days).

See this overview: https://en.wikipedia.org/wiki/Barometric_formula

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”