-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetSensorData.ino
104 lines (86 loc) · 2.5 KB
/
getSensorData.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/**
* @file getSensorData.ino
* @brief M5Unit IMU Pro Mini Get Sensor Data Demo.
* @version 0.2
* @date 2024-07-02
*
* @Hardwares:M5Unit IMU Pro Mini
* @Platform Version: Arduino M5Stack Board Manager v2.0.7
* @Dependent Library:
* M5_IMU_PRO: https://github.com/m5stack/M5Unit-IMU-Pro-Mini
* Adafruit BMP280 Library: https://github.com/adafruit/Adafruit_BMP280_Library
* M5Unified: https://github.com/m5stack/M5Unified
* M5GFX: https://github.com/m5stack/M5GFX
*
*/
#include <M5Unified.h>
#include "M5_IMU_PRO.h"
#define BIM270_SENSOR_ADDR 0x68
#define BMP280_SENSOR_ADDR 0x76
BMI270::BMI270 bmi270;
Adafruit_BMP280 bmp(&Wire);
void setup() {
M5.begin();
M5.Ex_I2C.begin();
unsigned status = bmp.begin(BMP280_SENSOR_ADDR);
if (!status) {
Serial.println(
F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
Serial.print("SensorID was: 0x");
Serial.println(bmp.sensorID(), 16);
while (1) delay(10);
}
bmi270.init(I2C_NUM_0, BIM270_SENSOR_ADDR);
}
void loop(void) {
// put your main code here, to run repeatedly:
float x, y, z;
if (bmi270.accelerationAvailable()) {
bmi270.readAcceleration(x, y, z);
Serial.print("accel: \t");
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.print(z);
Serial.println();
}
if (bmi270.gyroscopeAvailable()) {
bmi270.readGyroscope(x, y, z);
Serial.print("gyro: \t");
Serial.print(x);
Serial.print('\t');
Serial.print(y);
Serial.print('\t');
Serial.print(z);
Serial.println();
}
if (bmi270.magneticFieldAvailable()) {
int16_t mx, my, mz = 0;
bmi270.readMagneticField(mx, my, mz);
Serial.print("mag: \t");
Serial.print(mx);
Serial.print('\t');
Serial.print(my);
Serial.print('\t');
Serial.print(mz);
Serial.println();
}
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
delay(500);
}