"SparkFunBME280.h": Can't assign pressure to variable

Hello,

SparkFun example sketch "Example1_BasicReadings.ino" works fine: it prints the values to serial.
But when I try to assign pressure value to float variable and print the variable I get only zeroes.

Can't figure out why is that...how should I do assigning pressure to variable?

Sketch and serial output are below. Otherwise it's mentioned example sketch, but I added couple of lines saying //added in the end.

/*
  Get basic environmental readings from the BME280
  By: Nathan Seidle
  SparkFun Electronics
  Date: March 9th, 2018
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  Feel like supporting our work? Buy a board from SparkFun!
  https://www.sparkfun.com/products/14348 - Qwiic Combo Board
  https://www.sparkfun.com/products/13676 - BME280 Breakout Board
  
  This example shows how to read humidity, pressure, and current temperature from the BME280 over I2C.

  Hardware connections:
  BME280 -> Arduino
  GND -> GND
  3.3 -> 3.3
  SDA -> A4
  SCL -> A5
*/

#include <Wire.h>

#include "SparkFunBME280.h"
BME280 mySensor;

float airPressureSensor;       // added

void setup()
{
  Serial.begin(115200);
  Serial.println("Reading basic values from BME280");

  Wire.begin();

  if (mySensor.beginI2C() == false) //Begin communication over I2C
  {
    Serial.println("The sensor did not respond. Please check wiring.");
    while(1); //Freeze
  }
}

void loop()
{
  Serial.print("Humidity: ");
  Serial.print(mySensor.readFloatHumidity(), 0);

  Serial.print(" Pressure: ");
  Serial.print(mySensor.readFloatPressure(), 0);

  Serial.print(" airPressureSensor: ");                         //added
  airPressureSensor = (mySensor.readFloatPressure(), 0);        //added
  Serial.print(airPressureSensor);                              //added
 
  Serial.print(" Alt: ");
  //Serial.print(mySensor.readFloatAltitudeMeters(), 1);
  Serial.print(mySensor.readFloatAltitudeFeet(), 1);

  Serial.print(" Temp: ");
  //Serial.print(mySensor.readTempC(), 2);
  Serial.print(mySensor.readTempF(), 2);

  Serial.println();

  delay(50);
}

Serial output:

Humidity: 38 Pressure: 99702 airPressureSensor: 0.00 Alt: 446.0 Temp: 72.18
Humidity: 38 Pressure: 99704 airPressureSensor: 0.00 Alt: 445.5 Temp: 72.16
Humidity: 38 Pressure: 99698 airPressureSensor: 0.00 Alt: 447.2 Temp: 72.18
Humidity: 38 Pressure: 99704 airPressureSensor: 0.00 Alt: 445.5 Temp: 72.16
Humidity: 38 Pressure: 99698 airPressureSensor: 0.00 Alt: 448.0 Temp: 72.18
Humidity: 38 Pressure: 99702 airPressureSensor: 0.00 Alt: 446.3 Temp: 72.18

Thanks,
Tipo

What is this nonsense? Did you mean

  airPressureSensor = mySensor.readFloatPressure();        //added
  Serial.print(airPressureSensor, 0);                              //added

???

Exactly. Thanks!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.