-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbme280.ino
More file actions
103 lines (83 loc) · 3.24 KB
/
Copy pathbme280.ino
File metadata and controls
103 lines (83 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//============================================================================
// Code to get info from the optional BME280 sensor
//============================================================================
#if defined(USE_BME280)
#include <Wire.h>
#include <SPI.h>
#include <BME280I2C.h>
//#include <Adafruit_Sensor.h> // Can be downloaded from the library manager
//#include <Adafruit_BME280.h> // Can be downloaded from the library manager
// Adafruit_BME280 bme;
BME280I2C bme; // Default : forced mode, standby time = 1000 ms
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
//============================================================================
// setup the bme280 sensor
//============================================================================
void setup_bme280() {
unsigned status;
toSerialConsole("Setting up bme280.\n");
Wire.begin(SDA_PIN, SCL_PIN);
if (!bme.begin())
{
toSerialConsole("Could not find a valid BME280 sensor. Wrong wiring?\n");
return;
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
toSerialConsole("Found BME280 sensor! Success.\n");
break;
case BME280::ChipModel_BMP280:
toSerialConsole("Found BMP280 sensor! No Humidity available.\n");
break;
default:
toSerialConsole("Found UNKNOWN sensor! Error!\n");
}
}
//============================================================================
// get the temperature in °C
//============================================================================
float bme280_temperature() {
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
bme.read(pres, temp, hum, tempUnit, presUnit);
return (temp);
}
//============================================================================
// get the pressure in hPa
//============================================================================
float bme280_pressure() {
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
bme.read(pres, temp, hum, tempUnit, presUnit);
return(pres);
}
//============================================================================
// get the relative humidity in %
//============================================================================
float bme280_humidity() {
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
bme.read(pres, temp, hum, tempUnit, presUnit);
return(hum);
}
#endif
//============================================================================
// Write the BME280 values for debugging purposes to the serial console
//============================================================================
void printbme280Data() {
#if defined(USE_BME280)
toSerialConsole("Temperature: ");
toSerialConsole(bme280_temperature());
toSerialConsole(" °C\n");
toSerialConsole(" Pressure: ");
toSerialConsole(bme280_pressure());
toSerialConsole(" hPa\n");
toSerialConsole(" Humidity: ");
toSerialConsole(bme280_humidity());
toSerialConsole(" %\n");
#endif
}