-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparkfun_bme280.h
75 lines (60 loc) · 2.41 KB
/
sparkfun_bme280.h
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
/******************************************************************************
* sparkfun_bme280.h
*
* Sparkfun SEN-14348 - SparkFun Environmental Combo Breakout - CCS811/BME280
* BME280 component
*
* Created by Ioannis Tornazakis ( [email protected] ) on 2021-03-28
******************************************************************************/
#ifndef ION_SPARKFUN_BME280_H
#define ION_SPARKFUN_BME280_H
#include "sensor_server.h"
#include "SparkFunBME280.h"
/* Calibration values for specific board if needed */
#define TEMP_CALIBRATION 0.0
#define HUM_CALIBRATION 0.0
/******************************************************************************
* GLOBAL VARIABLES *
******************************************************************************/
BME280 bme;
extern float bme_calibration_temp;
extern float bme_calibration_hum;
/******************************************************************************
* FUNCTION PROTOTYPES *
******************************************************************************/
void init_sparkfun_bme280();
String print_sparkfun_bme280();
/******************************************************************************
* FUNCTION DEFINITIONS *
******************************************************************************/
void init_sparkfun_bme280() {
#ifdef DEBUG
Serial.print("Initializing Sparkfun BME280 sensor at I2C... \t");
#endif
if (bme.beginI2C() == false) {
#ifdef DEBUG
Serial.println("The sensor did not respond. Please check wiring.");
#endif
while(true);
}
#ifdef DEBUG
Serial.println("[ok]");
delay(10);
#endif
}
String print_sparkfun_bme280() {
String bme280_output = "";
bme280_output += "[sparkfun-bme280]: ";
bme_calibration_temp = bme.readTempC() + TEMP_CALIBRATION;
bme280_output += bme_calibration_temp; /* Update global CCS811 calibration */
bme280_output += " Celsius | ";
bme_calibration_hum = bme.readFloatHumidity() + HUM_CALIBRATION;
bme280_output += bme_calibration_hum ; /* Update global CCS811 calibration */
bme280_output += " % | ";
bme280_output += bme.readFloatPressure() / 100.0F;
bme280_output += " hPa | ";
bme280_output += bme.readFloatAltitudeMeters();
bme280_output += " m";
return bme280_output;
}
#endif /* ION_SPARKFUN_BME280_H */