forked from RT-Thread-packages/mpu-6xxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpu6xxx_sample.c
49 lines (39 loc) · 1.22 KB
/
mpu6xxx_sample.c
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
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-10-23 flybreak the first version
*/
#include <rtthread.h>
#include "mpu6xxx.h"
/* Default configuration, please change according to the actual situation, support i2c and spi device name */
#define MPU6XXX_DEVICE_NAME "i2c2"
/* Test function */
static int mpu6xxx_test()
{
struct mpu6xxx_device *dev;
struct mpu6xxx_3axes accel, gyro;
int i;
/* Initialize mpu6xxx, The parameter is RT_NULL, means auto probing for i2c*/
dev = mpu6xxx_init(MPU6XXX_DEVICE_NAME, RT_NULL);
if (dev == RT_NULL)
{
rt_kprintf("mpu6xxx init failed\n");
return -1;
}
rt_kprintf("mpu6xxx init succeed\n");
for (i = 0; i < 5; i++)
{
mpu6xxx_get_accel(dev, &accel);
mpu6xxx_get_gyro(dev, &gyro);
rt_kprintf("accel.x = %3d, accel.y = %3d, accel.z = %3d ", accel.x, accel.y, accel.z);
rt_kprintf("gyro.x = %3d gyro.y = %3d, gyro.z = %3d\n", gyro.x, gyro.y, gyro.z);
rt_thread_mdelay(100);
}
mpu6xxx_deinit(dev);
return 0;
}
MSH_CMD_EXPORT(mpu6xxx_test, mpu6xxx sensor test function);