This repository was archived by the owner on May 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBMP388-Basic.ino
78 lines (60 loc) · 2.65 KB
/
BMP388-Basic.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
/**
* @brief Basic example demonstrating usage of 107-Arduino-BMP388 library.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <SPI.h>
#include <107-Arduino-BMP388.h>
/**************************************************************************************
* CONSTANTS
**************************************************************************************/
static int const BMP388_CS_PIN = 2;
static int const BMP388_INT_PIN = 6;
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
using namespace drone;
/**************************************************************************************
* GLOBAL VARIABLES
**************************************************************************************/
ArduinoBMP388 bmp388([](){ digitalWrite(BMP388_CS_PIN, LOW); },
[](){ digitalWrite(BMP388_CS_PIN, HIGH); },
[](uint8_t const d) -> uint8_t { return SPI.transfer(d); },
[](unit::Pressure const pressure)
{
Serial.print(pressure.value() / 100.0);
Serial.print(" hPa / ");
Serial.print(ArduinoBMP388::convertPressureToAltitude(pressure).value());
Serial.println(" m");
},
[](unit::Temperature const temperature)
{
Serial.print(temperature.value() + 273.15);
Serial.println(" °C");
});
/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/
void setup()
{
Serial.begin(9600);
while(!Serial) { }
/* Print data of BMP388 sensor. */
Serial.print(bmp388);
/* Setup SPI access */
SPI.begin();
pinMode(BMP388_CS_PIN, OUTPUT);
digitalWrite(BMP388_CS_PIN, HIGH);
/* Attach interrupt handler */
pinMode(BMP388_INT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BMP388_INT_PIN), [](){ bmp388.onExternalEventHandler(); }, FALLING);
/* Configure BMP388 */
bmp388.begin(BMP388::OutputDataRate::ODR_12_5_Hz);
}
void loop()
{
}
/**************************************************************************************
* FUNCTION DEFINITION
**************************************************************************************/