File tree 2 files changed +47
-0
lines changed
examples/MPU6050/BasicReadings
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 26
26
example :
27
27
- " examples/PCA9685/Servo/Servo.ino"
28
28
- " examples/PCA9685/VibroPulse/VibroPulse.ino"
29
+ - " examples/MPU6050/BasicReadings/BasicReadings.ino"
29
30
boards : [ [ uno, esp32dev ] ]
30
31
31
32
steps :
Original file line number Diff line number Diff line change
1
+ #include < I2CDevLib.h>
2
+ #include < i2cdev/mpu6050.hpp>
3
+
4
+ i2cdev::MPU6050 mpu6050;
5
+
6
+ void setup (void ) {
7
+ Serial.begin (115200 );
8
+ while (!Serial)
9
+ delay (10 ); // will pause Zero, Leonardo, etc until serial console opens
10
+
11
+ Wire.begin ();
12
+
13
+ Serial.println (" I2CDevLibContrib MPU6050 test!" );
14
+
15
+ // Wait for the MPU6050 to be ready
16
+ delay (1000 );
17
+
18
+ if (mpu6050.check () != I2CDEV_RESULT_OK) {
19
+ Serial.println (" Failed to find MPU6050 chip" );
20
+ while (true ) {}
21
+ }
22
+ Serial.println (" MPU6050 Found!" );
23
+
24
+ if (mpu6050.reset () != I2CDEV_RESULT_OK) {
25
+ Serial.println (" Failed to reset MPU6050 chip" );
26
+ while (true ) {}
27
+ }
28
+
29
+ mpu6050.setAccelerometerRange (MPU6050_ACCEL_RANGE_8G);
30
+ mpu6050.setGyroscopeRange (MPU6050_GYRO_RANGE_500_DEG);
31
+ mpu6050.setFilterBandwidth (MPU6050_BANDWIDTH_21_HZ);
32
+
33
+ Serial.println (" " );
34
+ delay (100 );
35
+ }
36
+
37
+ void loop () {
38
+ auto measurements = mpu6050.getAllMeasurements ();
39
+
40
+ Serial.print (" Accelerometer X: " ); Serial.print (measurements.accel .x ); Serial.print (" Y: " ); Serial.print (measurements.accel .y ); Serial.print (" Z: " ); Serial.println (measurements.accel .z );
41
+ Serial.print (" Gyroscope X: " ); Serial.print (measurements.gyro .x ); Serial.print (" Y: " ); Serial.print (measurements.gyro .y ); Serial.print (" Z: " ); Serial.println (measurements.gyro .z );
42
+ Serial.print (" Temperature: " ); Serial.print (measurements.temperature ); Serial.println (" C" );
43
+ Serial.println (" " );
44
+
45
+ delay (500 );
46
+ }
You can’t perform that action at this time.
0 commit comments