Go Down

Topic: BME280 by Taylor Glenn v2.3. HeatIndex and DewPoint useage? (Read 629 times) previous topic - next topic

Techno500

How are HeatIndex and DewPoint used in Taylor Glenn's BME280 library?

Taylor Glenn's BME280 Library

Quote
float HeatIndex(float temperature, float humidity, TempUnit tempUnit = TempUnit_Celsius)
Calculate the heat index based on the temperature and humidity with the specified units. The U.S. NWS algorithm is used.

    return: float heat index in TempUnit

    * Temperature: float
      values: any float related to TempUnit

    * Humidity: float, unit = % relative humidity
      values: any float

    * TempUnit: TempUnit, default = TempUnit_Celsius
      values: TempUnit_Celsius = return degrees Celsius, TempUnit_Fahrenheit = return degrees
      Fahrenheit
Quote
float DewPoint(float temp, float hum, TempUnit = TempUnit_Celsius)
Calculate the dew point based on the temperature and humidity with the specified units.

    return: float dew point

    * Temperature: float
      values: any float related to TempUnit

    * Humidity: float, unit = % relative humidity
      values: any float

    * TempUnit: TempUnit, default = TempUnit_Celsius
      values: TempUnit_Celsius = return degrees Celsius, TempUnit_Fahrenheit = return degrees
     Fahrenheit
This is my attempt at using HeatIndex and DewPoint:
Code: [Select]

void getWeatherData()
{

    

     BME280::TempUnit tempUnit(BME280::TempUnit_Fahrenheit);
     BME280::PresUnit presUnit(BME280::PresUnit_Pa);
    
     bme.read(pres, temp, hum, tempUnit, presUnit);

     currentPressure = ((pres * 0.0002953) + .874);   //convert Pascals to inches mercury --add
     correction factor    //  + .877
     millibars = ((pres * .01) + 28.8);   //convert Pascals to millibars  --plus correction factor  // + 29.7

     HeatIndex = (temperature, humidity, TempUnit_Fahrenheit);
    
     DewPoint = (temp, hum, TempUnit_Fahrenheit);
    
     atm = pres * 0.00000986923267;   //Convert Pascals to Atm (atmospheric pressure)

}



Using #include <EnvironmentCalculations.h>

Variables are global; used outside of function.


William

groundFungus

So what is the problem?  If we don't know what is wrong, how can we help to fix it?

Code: [Select]

 HeatIndex = (temperature, humidity, TempUnit_Fahrenheit);   
 DewPoint = (temp, hum, TempUnit_Fahrenheit);


How many different variables are there for temperature and humidity?

Techno500

Quote
So what is the problem?  If we don't know what is wrong, how can we help to fix it?

Code: [Select]

 HeatIndex = (temperature, humidity, TempUnit_Fahrenheit);   
 DewPoint = (temp, hum, TempUnit_Fahrenheit);
HeatIndex and DewPoint are both 0.00; when I use your code in the function getWeatherData.  Function produces valid values for temp and hum; temp is using TempUnit_Fahrenheit.

William

groundFungus

Quote
when I use your code in the function getWeatherData.
That is not my code.  It is your code.  I was trying to point out that there are 2 variables that  hold temperature a 2 variables that hold humidity.  You read the BME280 using temp and hum, but call HeatIndex with temperature and humidity.  Where are values asigned to temperature and humidity?  If you post all of the code instead of a snippet it may be easier to help.

Techno500

#4
Jul 22, 2018, 12:40 am Last Edit: Jul 23, 2018, 09:02 pm by Techno500 Reason: Modified question added compiler error.
Use of HeatIndex and DewPoint do not work with this modified code example from the BME280 Library by Tyler Glenn.  My apologies for misspelling the author's name in the the topic heading.

Specifically how do you get HeatIndex and Dewpoint to work?


Code: [Select]
/*
BME280 I2C Test.ino

This code shows how to record data from the BME280 environmental sensor
using I2C interface. This file is an example file, part of the Arduino
BME280 library.

GNU General Public License

Written: Dec 30 2015.
Last Updated: Oct 07 2017.

Connecting the BME280 Sensor:
Sensor              ->  Board
-----------------------------
Vin (Voltage In)    ->  3.3V
Gnd (Ground)        ->  Gnd
SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

 */

#include <BME280I2C.h>
#include <EnvironmentCalculations.h>
#include <Wire.h>

#define SERIAL_BAUD 115200

BME280I2C bme;    // Default : forced mode, standby time = 1000 ms
                  // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

//////////////////////////////////////////////////////////////////
void setup()
{
  Serial.begin(SERIAL_BAUD);

  while(!Serial) {} // Wait

  Wire.begin();

  while(!bme.begin())
  {
    Serial.println("Could not find BME280 sensor!");
    delay(1000);
  }

  switch(bme.chipModel())
  {
     case BME280::ChipModel_BME280:
       Serial.println("Found BME280 sensor! Success.");
       break;
     case BME280::ChipModel_BMP280:
       Serial.println("Found BMP280 sensor! No Humidity available.");
       break;
     default:
       Serial.println("Found UNKNOWN sensor! Error!");
  }
}

//////////////////////////////////////////////////////////////////
void loop()
{
   printBME280Data(&Serial);
   delay(500);
}

//////////////////////////////////////////////////////////////////
void printBME280Data
(
   Stream* client
)
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);

   bme.read(pres, temp, hum, tempUnit, presUnit);

  //Is this correct?  I believe I am using this incorrectly; since it does not compile.  
  //There is no example for next two lines of code and documentation is not clear to me.
  
   float DewPoint(float temp, float hum, TempUnit tempUnit = TempUnit_Celsius);
   //https://github.com/finitespace/BME280/tree/master/docs#environment-calculations
    
   float HeatIndex(float temperature, float humidity, TempUnit tempUnit = TempUnit_Celsius);
   //https://github.com/finitespace/BME280/tree/master/docs#environment-calculations
    
  
  
   client->print("Temp: ");
   client->print(temp);
   client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println("Pa");

   //No attempt to output HeatIndex or DewPoint; since it does not compile.

   delay(1000);
}


Compiler error:  TempUnit is not declared.  Declaring TempUnit as float; this time I get tempUnit is not a type. 



William

Techno500

#5
Jul 23, 2018, 10:15 pm Last Edit: Jul 23, 2018, 10:25 pm by Techno500 Reason: Made correction.
Have this compiling now; need a way to output HeatIndex and DewPoint.  Compiler error:

call of overloaded 'print(float (&)(float, float, TempUnit))' is ambiguous


Code: [Select]
  /*
BME280 I2C Test.ino

This code shows how to record data from the BME280 environmental sensor
using I2C interface. This file is an example file, part of the Arduino
BME280 library.

GNU General Public License

Written: Dec 30 2015.
Last Updated: Oct 07 2017.

Connecting the BME280 Sensor:
Sensor              ->  Board
-----------------------------
Vin (Voltage In)    ->  3.3V
Gnd (Ground)        ->  Gnd
SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

 */

#include <BME280I2C.h>
#include <EnvironmentCalculations.h>
#include <Wire.h>

#define SERIAL_BAUD 115200

/// Temperature unit enumeration.
enum TempUnit
{
   TempUnit_Celsius,
   TempUnit_Fahrenheit
};

BME280I2C bme;    // Default : forced mode, standby time = 1000 ms
                  // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

//////////////////////////////////////////////////////////////////
void setup()
{
  Serial.begin(SERIAL_BAUD);

  while(!Serial) {} // Wait

  Wire.begin();

  while(!bme.begin())
  {
    Serial.println("Could not find BME280 sensor!");
    delay(1000);
  }

  switch(bme.chipModel())
  {
     case BME280::ChipModel_BME280:
       Serial.println("Found BME280 sensor! Success.");
       break;
     case BME280::ChipModel_BMP280:
       Serial.println("Found BMP280 sensor! No Humidity available.");
       break;
     default:
       Serial.println("Found UNKNOWN sensor! Error!");
  }
}

//////////////////////////////////////////////////////////////////
void loop()
{
   printBME280Data(&Serial);
   delay(500);
}

//////////////////////////////////////////////////////////////////
void printBME280Data
(
   Stream* client
)
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);

   bme.read(pres, temp, hum, tempUnit, presUnit);

  //Is this correct?  I believe I am using this incorrectly; since it does not compile.  
  //There is no example for next two lines of code and documentation is not clear to me.

   float DewPoint(float temp, float hum, TempUnit tempUnit = TempUnit_Celsius);
   //https://github.com/finitespace/BME280/tree/master/docs#environment-calculations

   float HeatIndex(float temperature, float humidity, TempUnit tempUnit = TempUnit_Celsius);
   //https://github.com/finitespace/BME280/tree/master/docs#environment-calculations



   client->print("Temp: ");
   client->print(temp);
   client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println("Pa");
   client->print(HeatIndex);   //Compiler error
   client->println("  Heat Index");
   client->print(DewPoint);   //Compiler error   
   client->println("  DewPoint");

   delay(1000);
}



William

groundFungus

This version of your code compiles.  I have no way to test if it "works".

I looked at the Environment_Calculations.ino file to see how the heatIndex and dewpoint functions were called.  

Code: [Select]
/*
   BME280 I2C Test.ino

   This code shows how to record data from the BME280 environmental sensor
   using I2C interface. This file is an example file, part of the Arduino
   BME280 library.

   GNU General Public License

   Written: Dec 30 2015.
   Last Updated: Oct 07 2017.

   Connecting the BME280 Sensor:
   Sensor              ->  Board
   -----------------------------
   Vin (Voltage In)    ->  3.3V
   Gnd (Ground)        ->  Gnd
   SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
   SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

*/

#include <BME280I2C.h>
#include <EnvironmentCalculations.h>
#include <Wire.h>

#define SERIAL_BAUD 115200

/// Temperature unit enumeration.
enum TempUnit
{
   TempUnit_Celsius,
   TempUnit_Fahrenheit
};

BME280I2C bme;    // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

//////////////////////////////////////////////////////////////////
void setup()
{
   Serial.begin(SERIAL_BAUD);

   while (!Serial) {} // Wait

   Wire.begin();

   while (!bme.begin())
   {
      Serial.println("Could not find BME280 sensor!");
      delay(1000);
   }

   switch (bme.chipModel())
   {
      case BME280::ChipModel_BME280:
         Serial.println("Found BME280 sensor! Success.");
         break;
      case BME280::ChipModel_BMP280:
         Serial.println("Found BMP280 sensor! No Humidity available.");
         break;
      default:
         Serial.println("Found UNKNOWN sensor! Error!");
   }
}

//////////////////////////////////////////////////////////////////
void loop()
{
   printBME280Data(&Serial);
   delay(500);
}

//////////////////////////////////////////////////////////////////
void printBME280Data
(
   Stream* client
)
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);
   EnvironmentCalculations::TempUnit     envTempUnit =  EnvironmentCalculations::TempUnit_Celsius;

   bme.read(pres, temp, hum, tempUnit, presUnit);

   //Is this correct?  I believe I am using this incorrectly; since it does not compile.
   //There is no example for next two lines of code and documentation is not clear to me.

   float DewPoint(float temp, float hum, TempUnit tempUnit = TempUnit_Celsius);
   //https://github.com/finitespace/BME280/tree/master/docs#environment-calculations

   float HeatIndex(float temperature, float humidity, TempUnit tempUnit = TempUnit_Celsius);
   //https://github.com/finitespace/BME280/tree/master/docs#environment-calculations



   client->print("Temp: ");
   client->print(temp);
   client->print("°" + String(tempUnit == BME280::TempUnit_Celsius ? 'C' : 'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println("Pa");
   //client->print(HeatIndex);   //Compiler error
   float heatIndex = EnvironmentCalculations::HeatIndex(temp, hum, envTempUnit);
   client->println(heatIndex);
   client->println("  Heat Index");
   //client->print(DewPoint);   //Compiler error
   float dewPoint = EnvironmentCalculations::DewPoint(temp, hum, envTempUnit);
   client->print(dewPoint);
   client->println("  DewPoint");

   delay(1000);
}

Techno500

Thank you groundFungus for taking another look.  Your code works!


HeatIndex and DewPoint useage --> Tyler Glenn's BME280 library v2.3.0

Code: [Select]
/*
   BME280 I2C Test.ino

   This code shows how to record data from the BME280 environmental sensor
   using I2C interface. This file is an example file, part of the Arduino
   BME280 library.

   GNU General Public License

   Written: Dec 30 2015.
   Last Updated: Oct 07 2017.

   Connecting the BME280 Sensor:
   Sensor              ->  Board
   -----------------------------
   Vin (Voltage In)    ->  3.3V
   Gnd (Ground)        ->  Gnd
   SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
   SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

*/

#include <BME280I2C.h>
#include <EnvironmentCalculations.h>
#include <Wire.h>

#define SERIAL_BAUD 115200

/// Temperature unit enumeration.
enum TempUnit
{
   TempUnit_Celsius,
   TempUnit_Fahrenheit
};

BME280I2C bme;    // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

//////////////////////////////////////////////////////////////////
void setup()
{
   Serial.begin(SERIAL_BAUD);

   while (!Serial) {} // Wait

   Wire.begin();

   while (!bme.begin())
   {
      Serial.println("Could not find BME280 sensor!");
      delay(1000);
   }

   switch (bme.chipModel())
   {
      case BME280::ChipModel_BME280:
         Serial.println("Found BME280 sensor! Success.");
         break;
      case BME280::ChipModel_BMP280:
         Serial.println("Found BMP280 sensor! No Humidity available.");
         break;
      default:
         Serial.println("Found UNKNOWN sensor! Error!");
   }
}

//////////////////////////////////////////////////////////////////
void loop()
{
   printBME280Data(&Serial);
   delay(500);
}

//////////////////////////////////////////////////////////////////
void printBME280Data
(
   Stream* client
)
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Fahrenheit);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);
   EnvironmentCalculations::TempUnit     envTempUnit =  EnvironmentCalculations::TempUnit_Fahrenheit;

   bme.read(pres, temp, hum, tempUnit, presUnit);
  
   client->print("Temp: ");
   client->print(temp);
   client->print("°" + String(tempUnit == BME280::TempUnit_Fahrenheit ? 'C' : 'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println("Pa");
   float heatIndex = EnvironmentCalculations::HeatIndex(temp, hum, envTempUnit);
   client->println(heatIndex);
   client->println("  Heat Index");
   float dewPoint = EnvironmentCalculations::DewPoint(temp, hum, envTempUnit);
   client->print(dewPoint);
   client->println("  DewPoint");

   delay(1000);
}


William

groundFungus

The code that I posted did compile using IDE 1.8.5 on an Uno, but, as I said, I could not test it.    I will try it and the Environment_Calculations.ino on an ESP8266 when I get time.

giano2002

Hi,

I loaded the sketch and I could see that it works very well on Arduino Nano,with BME280.

I would add that the Taylor Glenn BME library is the only one I found on the Internet that allows reading, in addition to the values of Temperature, Humidity and Pressure, also Heat Index and Dew Point. So my congratulations!

Now, however, I would need the help of someone who is much more experienced than me in Arduino programming.

I would like to make a small portable, battery powered instrument that uses the BME280 sensor, connected via I2C to Arduino Nano, to read the values of Temperature, Humidity, Pressure and Heat Index, on a 0.96" OLED mini display, I2C, 128x64 (32) pixels.

I made a few attempts to modify the sketch, but I'm a beginner in programming and I did not get any results. Could you help me? I would be very grateful!!

groundFungus

Post a link to the display and the code that does not work and I will take a look.

giano2002

Post a link to the display and the code that does not work and I will take a look.
The sketch I am using is:

Version 11_11_2018, modified for Celsius

  BME280 I2C Test.ino

  This code shows how to record data from the BME280 environmental sensor
  using I2C interface. This file is an example file, part of the Arduino
  BME280 library.

  GNU General Public License

/*
  BME280 I2C Test.ino

  This code shows how to record data from the BME280 environmental sensor
  using I2C interface. This file is an example file, part of the Arduino
  BME280 library.

  GNU General Public License

  Written: Dec 30 2015.
  Last Updated: Oct 07 2017.

  Connecting the BME280 Sensor:
  Sensor              ->  Board
  -----------------------------
  Vin (Voltage In)    ->  3.3V
  Gnd (Ground)        ->  Gnd
  SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
  SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

*/

#include <BME280I2C.h>
#include <EnvironmentCalculations.h>
#include <Wire.h>

#define SERIAL_BAUD 115200

/// Temperature unit enumeration.
enum TempUnit
{
  TempUnit_Celsius,
  TempUnit_Fahrenheit
};

BME280I2C bme;    // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

//////////////////////////////////////////////////////////////////
void setup()
{
  Serial.begin(SERIAL_BAUD);

  while (!Serial) {} // Wait

  Wire.begin();

  while (!bme.begin())
  {
     Serial.println("Could not find BME280 sensor!");
     delay(1000);
  }

  switch (bme.chipModel())
  {
     case BME280::ChipModel_BME280:
        Serial.println("Found BME280 sensor! Success.");
        break;
     case BME280::ChipModel_BMP280:
        Serial.println("Found BMP280 sensor! No Humidity available.");
        break;
     default:
        Serial.println("Found UNKNOWN sensor! Error!");
  }
}

//////////////////////////////////////////////////////////////////
void loop()
{
  printBME280Data(&Serial);
  delay(500);
}

//////////////////////////////////////////////////////////////////
void printBME280Data
(
  Stream* client
)
{
  float temp(NAN), hum(NAN), pres(NAN);

  BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
  BME280::PresUnit presUnit(BME280::PresUnit_Pa);
  EnvironmentCalculations::TempUnit     envTempUnit =  EnvironmentCalculations::TempUnit_Celsius;

  bme.read(pres, temp, hum, tempUnit, presUnit);

  client->print("Temperatura: ");
  client->print(temp);
  client->print(" °" + String(tempUnit == BME280::TempUnit_Celsius ? 'C' : 'F'));
  client->print("\t\tUmid: ");
  client->print(hum);
  client->print(" %RH");
  client->print("\t\tPressione: ");
  client->print(pres/100);
  client->println(" hPa");
  float heatIndex = EnvironmentCalculations::HeatIndex(temp, hum, envTempUnit);
  client->print("\t\tIndice calore:  ");
  client->print(heatIndex);
  client->println(" °C");
  float dewPoint = EnvironmentCalculations::DewPoint(temp, hum, envTempUnit);
  client->print("\t\tDewPoint: ");
  client->println(dewPoint);
  client->println("°C");

  delay(1000);
}


I would like to add to the above sketch some lines of code to have its results (Temperature, Humidity, Pressure and Heat index values) on an Oled display 0.96", connected to Arduino Nano via I2C:
   OLED GND - Arduino GND
   OLED VCC - Arduino 5V
   OLED SCL - Arduino Uno A5
   OLED SDA - Arduino Uno A4


There are several Libraries for 128x32 or 128x64 Oled display, but honestly I am not able to write the code necessary to show also on the small display oled the values that are read on the Serial monitor. Even if the 0.96 "display is small, there is still enough space to show all the values - in small characters - (for example:
T: 22.56CH: 64.20% HP: 1021.34 hPa HI: 23C). I repeat, I am not good at programming, so I will greatly appreciate your help. Thank you very much for the help.



groundFungus

I still do not know which display that you are using.  I need to know which display controller that the display uses.  Which library(s) did you try?  What happened when you tried to write to the display?

giano2002

I use a monochrome Oled display 0.96",  driver: SSD1306, 3.3V, I2C bus (3.3V+, Gnd, SDA, SCL), address: 0x3C.

Regarding libraries, I found these:

Adafruit_SSD1306, which handles the low-level communication with the hardware,

and Adafruit_GFX, which builds atop this to add graphics functions like lines, circles and text;

or u8glib.

But, honestly, as I said, I am not able to write the code to use one of the above libraries, and therefore I do not know how to start editing the sketch, to be able to read the data on the display.

I hope I have answered fully.

Thanks again for the time you are dedicating to me.


groundFungus

I have no experience with that particular display. Maybe this guide will help. I use the Adafruit libraries for my graphic LCD. 

Go Up