Skip to content

Commit 6ef6668

Browse files
committedNov 4, 2018
Adding dewpoint calc and example
1 parent cf73af1 commit 6ef6668

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Calculating dewpoint on the BME280
3+
Nathan Seidle @ SparkFun Electronics
4+
November 3rd, 2018
5+
6+
Feel like supporting our work? Buy a board from SparkFun!
7+
https://www.sparkfun.com/products/14348 - Qwiic Combo Board
8+
https://www.sparkfun.com/products/13676 - BME280 Breakout Board
9+
10+
This example shows how to calculate dew point based on humidity and temperature.
11+
Comes from Pavel-Sayekat: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/pull/6
12+
13+
Hardware connections:
14+
BME280 -> Arduino
15+
GND -> GND
16+
3.3 -> 3.3
17+
SDA -> A4
18+
SCL -> A5
19+
*/
20+
21+
#include <Wire.h>
22+
23+
#include "SparkFunBME280.h"
24+
BME280 mySensor;
25+
26+
void setup()
27+
{
28+
Serial.begin(9600);
29+
Serial.println("Example showing dewpoint calculation");
30+
31+
mySensor.setI2CAddress(0x76); //Connect to a second sensor
32+
if (mySensor.beginI2C() == false) Serial.println("Sensor connect failed");
33+
}
34+
35+
void loop()
36+
{
37+
Serial.print("Humidity: ");
38+
Serial.print(mySensor.readFloatHumidity(), 0);
39+
40+
Serial.print(" Pressure: ");
41+
Serial.print(mySensor.readFloatPressure(), 0);
42+
43+
Serial.print(" Temp: ");
44+
//Serial.print(mySensor.readTempC(), 2);
45+
Serial.print(mySensor.readTempF(), 2);
46+
47+
Serial.print(" Dewpoint: ");
48+
//Serial.print(mySensor.dewPointC(), 2);
49+
Serial.print(mySensor.dewPointF(), 2);
50+
51+
Serial.println();
52+
53+
delay(50);
54+
}

‎src/SparkFunBME280.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,36 @@ float BME280::readTempF( void )
495495
return output;
496496
}
497497

498+
//****************************************************************************//
499+
//
500+
// Dew point Section
501+
//
502+
//****************************************************************************//
503+
// Returns Dew point in DegC
504+
double BME280::dewPointC(void)
505+
{
506+
double celsius = readTempC();
507+
double humidity = readFloatHumidity();
508+
// (1) Saturation Vapor Pressure = ESGG(T)
509+
double RATIO = 373.15 / (273.15 + celsius);
510+
double RHS = -7.90298 * (RATIO - 1);
511+
RHS += 5.02808 * log10(RATIO);
512+
RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
513+
RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
514+
RHS += log10(1013.246);
515+
// factor -3 is to adjust units - Vapor Pressure SVP * humidity
516+
double VP = pow(10, RHS - 3) * humidity;
517+
// (2) DEWPOINT = F(Vapor Pressure)
518+
double T = log(VP/0.61078); // temp var
519+
return (241.88 * T) / (17.558 - T);
520+
}
521+
522+
// Returns Dew point in DegF
523+
double BME280::dewPointF(void)
524+
{
525+
return(dewPointC() * 1.8 + 32); //Convert C to F
526+
}
527+
498528
//****************************************************************************//
499529
//
500530
// Utility

‎src/SparkFunBME280.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct SensorCalibration
158158

159159
};
160160

161-
//This is the man operational class of the driver.
161+
//This is the main operational class of the driver.
162162

163163
class BME280
164164
{
@@ -213,6 +213,11 @@ class BME280
213213
float readTempC( void );
214214
float readTempF( void );
215215

216+
//Dewpoint related methods
217+
//From Pavel-Sayekat: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/pull/6/files
218+
double dewPointC(void);
219+
double dewPointF(void);
220+
216221
//The following utilities read and write
217222

218223
//ReadRegisterRegion takes a uint8 array address as input and reads

0 commit comments

Comments
 (0)
Please sign in to comment.