-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesp32ms5611.txt
70 lines (54 loc) · 1.65 KB
/
esp32ms5611.txt
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
//This example comes from the https://github.com/jarzebski/Arduino-MS5611 library
#include <Wire.h>
#include <MS5611.h>
MS5611 ms5611;
double referencePressure;
void setup()
{
Serial.begin(9600);
// Initialize MS5611 sensor
Serial.println("Initialize MS5611 Sensor");
while(!ms5611.begin())
{
Serial.println("Could not find a valid MS5611 sensor, check wiring!");
delay(500);
}
// Get reference pressure for relative altitude
referencePressure = ms5611.readPressure();
// Check settings
checkSettings();
}
void checkSettings()
{
Serial.print("Oversampling: ");
Serial.println(ms5611.getOversampling());
}
void loop()
{
// Read raw values
uint32_t rawTemp = ms5611.readRawTemperature();
uint32_t rawPressure = ms5611.readRawPressure();
// Read true temperature & Pressure
double realTemperature = ms5611.readTemperature();
long realPressure = ms5611.readPressure();
// Calculate altitude
float absoluteAltitude = ms5611.getAltitude(realPressure);
float relativeAltitude = ms5611.getAltitude(realPressure, referencePressure);
Serial.println("--");
Serial.print(" rawTemp = ");
Serial.print(rawTemp);
Serial.print(", realTemp = ");
Serial.print(realTemperature);
Serial.println(" *C");
Serial.print(" rawPressure = ");
Serial.print(rawPressure);
Serial.print(", realPressure = ");
Serial.print(realPressure);
Serial.println(" Pa");
Serial.print(" absoluteAltitude = ");
Serial.print(absoluteAltitude);
Serial.print(" m, relativeAltitude = ");
Serial.print(relativeAltitude);
Serial.println(" m");
delay(1000);
}