-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathi2c_mpu6050.dart
42 lines (39 loc) · 1.49 KB
/
i2c_mpu6050.dart
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
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:dart_periphery/dart_periphery.dart';
import 'dart:io';
/// MPU-6050 Six-Axis (Gyro + Accelerometer) sensor
///
/// Datasheet: https://invensense.tdk.com/products/motion-tracking/6-axis/mpu-6050/
///
void main() {
// Select the right I2C bus number /dev/i2c-?
// 1 for Raspberry Pi, 0 for NanoPi (Armbian), 2 Banana Pi (Armbian)
var i2c = I2C(1);
try {
print("dart_periphery Version: $dartPeripheryVersion");
print("c-periphery Version : ${getCperipheryVersion()}");
print('I2C info: ${i2c.getI2Cinfo()}');
print("MPU6050 sensor");
var mpu = MPU6050(i2c);
var index = 0;
var wait = 50; // wait 50 ms
while (true) {
mpu.updateValues(); // call update with a high frequency to get accurate values
sleep(Duration(milliseconds: wait));
index += 50;
if (index % 1000 == 0) {
print('AccelAccelerations: ${mpu.getAccelAccelerations()}');
print('AccelAngles: ${mpu.getAccelAngles()}');
print('FilteredAngles: ${mpu.getFilteredAngles()}');
print('GyroAngularSpeedsOffsets: ${mpu.getGyroAngularSpeedsOffsets()}');
print('GyroAngularSpeeds: ${mpu.getGyroAngularSpeeds()}');
print('GyroAngles: ${mpu.getGyroAngles()}');
print('\n');
}
}
} finally {
i2c.dispose();
}
}