-
Notifications
You must be signed in to change notification settings - Fork 0
/
BME280Codes.ino
90 lines (76 loc) · 2.27 KB
/
BME280Codes.ino
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
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
#define SEALEVELPRESSURE_HPA (1026.52)
#define SEALEVELHIGH_M (194)
bool BME280_Init(){
Serial.println("Start inicialize BME280");
Wire.begin(D3, D4); //SDA - D2, SDL - D1
//Wire.setClock(100000);
delay(1000);
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
//while (1);
return false;
}
Serial.println("BME280 sensor was initialized.");
bme.setSampling(Adafruit_BME280::MODE_FORCED, // takeForcedMeasurement must be called before each reading
Adafruit_BME280::SAMPLING_X1, // Temp. oversampling
Adafruit_BME280::SAMPLING_X1, // Pressure oversampling
Adafruit_BME280::SAMPLING_X1, // Humidity oversampling
Adafruit_BME280::FILTER_OFF,
Adafruit_BME280::STANDBY_MS_1000);
Serial.println("BME280 sensor was configured.");
return true;
}
String BME280_ReadStrTemperature(){
bme.takeForcedMeasurement();
double data = bme.readTemperature();
char charData[6];
dtostrf(data, 5, 1, charData);
delay(100);
return String(charData);
}
String BME280_ReadStrHumidity(){
bme.takeForcedMeasurement();
double data = bme.readHumidity();
char charData[6];
dtostrf(data, 5, 1, charData);
delay(100);
return String(charData);
}
String BME280_ReadStrPressure(){
bme.takeForcedMeasurement();
double pres = bme.readPressure()/100.0F;
double data = bme.seaLevelForAltitude(SEALEVELHIGH_M, pres);
char charData[6];
dtostrf(data, 5, 1, charData);
delay(100);
return String(charData);
}
double BME280_ReadHumidity(){
bme.takeForcedMeasurement();
return bme.readHumidity();
}
double BME280_ReadPressure(){
bme.takeForcedMeasurement();
double pres = bme.readPressure()/100.0F;
double data = bme.seaLevelForAltitude(SEALEVELHIGH_M, pres);
return data;
}
double BME280_ReadTemperature(){
bme.takeForcedMeasurement();
return bme.readTemperature();
}
void BME280_ReadData() {
Serial.print("Temperature = ");
Serial.print(BME280_ReadStrTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(BME280_ReadStrPressure());
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(BME280_ReadStrHumidity());
Serial.println(" %");
}