Skip to content

Commit

Permalink
Adding dewpoint calc and example
Browse files Browse the repository at this point in the history
  • Loading branch information
nseidle committed Nov 4, 2018
1 parent cf73af1 commit 6ef6668
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
54 changes: 54 additions & 0 deletions examples/Example10_DewPoint/Example10_DewPoint.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Calculating dewpoint on the BME280
Nathan Seidle @ SparkFun Electronics
November 3rd, 2018
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 calculate dew point based on humidity and temperature.
Comes from Pavel-Sayekat: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/pull/6
Hardware connections:
BME280 -> Arduino
GND -> GND
3.3 -> 3.3
SDA -> A4
SCL -> A5
*/

#include <Wire.h>

#include "SparkFunBME280.h"
BME280 mySensor;

void setup()
{
Serial.begin(9600);
Serial.println("Example showing dewpoint calculation");

mySensor.setI2CAddress(0x76); //Connect to a second sensor
if (mySensor.beginI2C() == false) Serial.println("Sensor connect failed");
}

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

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

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

Serial.print(" Dewpoint: ");
//Serial.print(mySensor.dewPointC(), 2);
Serial.print(mySensor.dewPointF(), 2);

Serial.println();

delay(50);
}
30 changes: 30 additions & 0 deletions src/SparkFunBME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,36 @@ float BME280::readTempF( void )
return output;
}

//****************************************************************************//
//
// Dew point Section
//
//****************************************************************************//
// Returns Dew point in DegC
double BME280::dewPointC(void)
{
double celsius = readTempC();
double humidity = readFloatHumidity();
// (1) Saturation Vapor Pressure = ESGG(T)
double RATIO = 373.15 / (273.15 + celsius);
double RHS = -7.90298 * (RATIO - 1);
RHS += 5.02808 * log10(RATIO);
RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
RHS += log10(1013.246);
// factor -3 is to adjust units - Vapor Pressure SVP * humidity
double VP = pow(10, RHS - 3) * humidity;
// (2) DEWPOINT = F(Vapor Pressure)
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558 - T);
}

// Returns Dew point in DegF
double BME280::dewPointF(void)
{
return(dewPointC() * 1.8 + 32); //Convert C to F
}

//****************************************************************************//
//
// Utility
Expand Down
7 changes: 6 additions & 1 deletion src/SparkFunBME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct SensorCalibration

};

//This is the man operational class of the driver.
//This is the main operational class of the driver.

class BME280
{
Expand Down Expand Up @@ -213,6 +213,11 @@ class BME280
float readTempC( void );
float readTempF( void );

//Dewpoint related methods
//From Pavel-Sayekat: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/pull/6/files
double dewPointC(void);
double dewPointF(void);

//The following utilities read and write

//ReadRegisterRegion takes a uint8 array address as input and reads
Expand Down

0 comments on commit 6ef6668

Please sign in to comment.