-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathRAK1902_Pressure_LPS22HB.ino
74 lines (62 loc) · 1.58 KB
/
RAK1902_Pressure_LPS22HB.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
/**
@file RAK1902_Pressure_LPS22HB.ino
@author rakwireless.com
@brief Setup and read values from a lps22hb sensor
@version 0.1
@date 2020-12-28
@copyright Copyright (c) 2020
**/
#include <Wire.h>
#include <Adafruit_LPS2X.h>
#include <Adafruit_Sensor.h> // Click here to get the library: http://librarymanager/All#Adafruit_LPS2X
Adafruit_LPS22 g_lps22hb;
void setup(void) {
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("Adafruit LPS22 test!");
// Try to initialize!
if (!g_lps22hb.begin_I2C(0x5c))
{
Serial.println("Failed to find LPS22 chip");
while (1)
{
delay(10);
}
}
Serial.println("LPS22 Found!");
g_lps22hb.setDataRate(LPS22_RATE_10_HZ);
Serial.print("Data rate set to: ");
switch (g_lps22hb.getDataRate())
{
case LPS22_RATE_ONE_SHOT: Serial.println("One Shot / Power Down");
break;
case LPS22_RATE_1_HZ: Serial.println("1 Hz");
break;
case LPS22_RATE_10_HZ: Serial.println("10 Hz");
break;
case LPS22_RATE_25_HZ: Serial.println("25 Hz");
break;
case LPS22_RATE_50_HZ: Serial.println("50 Hz");
break;
}
}
void loop() {
sensors_event_t temp;
sensors_event_t pressure;
g_lps22hb.getEvent(&pressure, &temp);
Serial.print("Temperature: ");Serial.print(temp.temperature);Serial.println(" degrees C");
Serial.print("Pressure: ");Serial.print(pressure.pressure);Serial.println(" hPa");
Serial.println("");
delay(1000);
}