BME280 Sensor Reporting Negative Altitude on RPI

I have a CCS811/BME280 sensor plugged into a Raspberry Pi Zero. (https://www.sparkfun.com/products/14348)

I am trying to get the the BME280 sensor to work in Python, using Sparkfun’s libraries. (https://github.com/sparkfun/Qwiic_BME280_Py)

Running the example code, it seems to work, sort of, but I am getting what I assume are incorrect results for Pressure/Altitude:

$ $ python qwiic_bme280_ex1.py 

SparkFun BME280 Sensor  Example 1

Humidity:       15.247
Pressure:       147927.965
Altitude:       -10857.104
Temperature:    77.11

Humidity:       14.240
Pressure:       115458.551
Altitude:       -3658.661
Temperature:    77.13

I assume temp and humidity values are ok, but I am definitely not 3600 feet below sea level. Is there some sort of calibration that I am missing?

(Separately, I am also getting weird values off of the CCS811, but that’s a question for a different thread.)

Thanks for reaching out to us on this.

The hookup guide mentions:

.begin() Needs to be run once during the setup, or after any settings have been modified. In order to let the sensor’s configuration take place, the BME280 requires a minimum time of about 2 ms in the sketch before you take data.

Please complete the entire hookup guide, found here: https://learn.sparkfun.com/tutorials/cc … okup-guide , as this and many other topics are covered.

Hope this helps, and happy sparking!

Unfortunately, this doesn’t really help. I am running the example provided by Sparkfun after hooking up the sensor. There is already a call to begin. I just added an extra call to time.sleep but I still get negative altitudes reported. Here is the code, as supplied by SparkFun, with the additional sleep:

from __future__ import print_function
import qwiic_bme280
import time
import sys

def runExample():
  print("\nSparkFun BME280 Sensor  Example 1\n")
  mySensor = qwiic_bme280.QwiicBme280()

  if mySensor.connected == False:
    print("The Qwiic BME280 device isn't connected to the system. Please check your connection", \
      file=sys.stderr)
    return

  mySensor.begin()
  time.sleep(1)

  while True:
    print("Humidity:\t%.3f" % mySensor.humidity)
    print("Pressure:\t%.3f" % mySensor.pressure)
    print("Altitude:\t%.3f" % mySensor.altitude_feet)
    print("Temperature:\t%.2f" % mySensor.temperature_fahrenheit)
    print("")
    time.sleep(1)


if __name__ == '__main__':
  try:
    runExample()
  except (KeyboardInterrupt, SystemExit) as exErr:
    print("\nEnding Example 1")
    sys.exit(0)

It runs just fine, but the pressure/altitude settings are wrong.

Do you have an Arduino so that you could try the hardware along with a BME280 library there to ensure that your device isn’t the source of the problem?

At first, I suggest you to cross-check your BME280 with an Arduino. See if it shows the correct altitude or not. You can find some useful guidelines here: https://www.theengineeringprojects.com/ … me280.html

Also here I have found some tips regarding the calibration if you already have not checked this: https://github.com/LeivoSepp/Lesson-Temperature-BME280