2024-01-09 21:03:01 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <unistd.h>
|
2024-01-09 19:15:14 +00:00
|
|
|
#include <stdio.h>
|
2024-01-09 21:03:01 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
2024-01-09 19:15:14 +00:00
|
|
|
#include "mpu6050.h"
|
2024-01-09 21:03:01 +00:00
|
|
|
#include "registers.h"
|
2024-01-09 19:15:14 +00:00
|
|
|
#include "i2c.h"
|
|
|
|
|
|
|
|
int main() {
|
2024-01-09 21:03:01 +00:00
|
|
|
|
2024-01-10 00:33:31 +00:00
|
|
|
mpu6050_t mpu6050;
|
2024-01-10 02:16:07 +00:00
|
|
|
|
2024-01-10 00:33:31 +00:00
|
|
|
mpu6050.dev.init = i2c_init;
|
|
|
|
mpu6050.dev.deinit = i2c_deinit;
|
|
|
|
mpu6050.dev.read = i2c_read;
|
|
|
|
mpu6050.dev.write = i2c_write;
|
|
|
|
mpu6050.dev.sleep = usleep;
|
2024-01-13 19:51:57 +00:00
|
|
|
|
2024-01-10 00:33:31 +00:00
|
|
|
if (mpu6050_init(&mpu6050)) {
|
2024-01-09 21:03:01 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2024-01-13 19:51:57 +00:00
|
|
|
if (mpu6050_calibrate_gyro(&mpu6050)) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("[CALIB] G_x=%4.1f, G_y=%4.1f, G_z=%4.1f\n",
|
|
|
|
(float)mpu6050.offset.gyro_x / 10.f,
|
|
|
|
(float)mpu6050.offset.gyro_y / 10.f,
|
|
|
|
(float)mpu6050.offset.gyro_z / 10.f);
|
|
|
|
|
2024-01-10 15:39:14 +00:00
|
|
|
mpu6050.cfg.gyro = MPU6050_GYRO_FS_250;
|
2024-01-10 02:16:07 +00:00
|
|
|
mpu6050.cfg.acc = MPU6050_ACC_FS_2G;
|
2024-01-10 20:09:23 +00:00
|
|
|
mpu6050.cfg.dlpl = 6;
|
|
|
|
mpu6050.cfg.sdiv = 200;
|
2024-01-10 17:57:25 +00:00
|
|
|
mpu6050.cfg.int_enable.data_rdy = 1;
|
2024-01-10 01:03:54 +00:00
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
if (mpu6050_configure(&mpu6050)) {
|
2024-01-09 21:03:01 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
for ( ;; ) {
|
2024-01-09 21:03:01 +00:00
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
if (mpu6050_read(&mpu6050)) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2024-01-09 21:03:01 +00:00
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
printf("[GYRO °/s] x:%4.1f y:%4.1f z:%4.1f ",
|
|
|
|
(float)mpu6050.data.gyro.x / 10.f,
|
|
|
|
(float)mpu6050.data.gyro.y / 10.f,
|
|
|
|
(float)mpu6050.data.gyro.z / 10.f);
|
2024-01-09 21:03:01 +00:00
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
printf("[ACC g] x:%4.3f y:%4.3f z:%4.3f ",
|
|
|
|
(float)mpu6050.data.acc.x / 1000.f,
|
|
|
|
(float)mpu6050.data.acc.y / 1000.f,
|
|
|
|
(float)mpu6050.data.acc.z / 1000.f);
|
2024-01-09 21:03:01 +00:00
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
printf("t:%4.1f°C\n", (float)mpu6050.data.temp / 10.f);
|
2024-01-09 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2024-01-10 20:09:23 +00:00
|
|
|
mpu6050_deinit(&mpu6050);
|
2024-01-09 21:03:01 +00:00
|
|
|
|
2024-01-09 19:15:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|