38#include "freertos/FreeRTOS.h"
39#include "driver/i2c.h"
40#include "driver/gpio.h"
45#define I2C_MASTER_SCL_IO MPU6050_SCL
46#define I2C_MASTER_SDA_IO MPU6050_SDA
47#define I2C_MASTER_NUM I2C_NUM_1
48#define I2C_MASTER_TX_BUF_DISABLE 0
49#define I2C_MASTER_RX_BUF_DISABLE 0
50#define I2C_MASTER_FREQ_HZ 100000
52#define MPU6050_RA_PWR_MGMT_1 0x6B
53#define MPU6050_CLOCK_PLL_XGYRO 0x01
55#define MPU6050_RA_GYRO_CONFIG 0x1B
56#define MPU6050_GYRO_FS_250 0x00
58#define MPU6050_RA_ACCEL_CONFIG 0x1C
59#define MPU6050_ACCEL_FS_2 0x00
61#define MPU6050_ADDR 0x68
62#define ACCE_START_ADDR 0x3B
63#define GYRO_START_ADDR 0x43
65#define WRITE_BIT I2C_MASTER_WRITE
66#define READ_BIT I2C_MASTER_READ
67#define ACK_CHECK_EN 0x1
68#define ACK_CHECK_DIS 0x0
73#define RAD_TO_DEG 57.2957795
76#define MPU_CALIBRATION_AVG_COUNT CONFIG_MPU_CALIBRATION_AVG_COUNT
142void compute_gyro_angle(int16_t gx, int16_t gy, int16_t gz,
float dt,
float *gyro_angle);
152esp_err_t
read_mpu6050_raw(int16_t *acce_raw_value, int16_t *gyro_raw_value);
162void complementary_filter(int16_t *acce_raw_value, int16_t *gyro_raw_value,
float *complementary_angle,
float *mpu_offset);
171esp_err_t
read_mpu6050(
float *euler_angle,
float *mpu_offset);
187esp_err_t
avg_sensors(int16_t *acce_raw_value_avg, int16_t *gyro_raw_value_avg,
const int16_t *acce_offs,
const int16_t *gyro_offs);
esp_err_t enable_mpu6050(void)
Initialise MPU-6050 (by sending the appropriate queued commands); Refer this for more information: ht...
Definition: mpu6050.c:54
esp_err_t read_mpu6050(float *euler_angle, float *mpu_offset)
The ultimate function (application ready); takes in the input raw values and initial conditions and g...
Definition: mpu6050.c:286
esp_err_t mpu6050_read_acce(uint8_t *data_rd, size_t size)
Get the accelerometer raw values (Ax, Ay, Az) into an 8-bit array Note that these raw values are actu...
Definition: mpu6050.c:88
void complementary_filter(int16_t *acce_raw_value, int16_t *gyro_raw_value, float *complementary_angle, float *mpu_offset)
Fuse the gyroscope and accelerometer angle in a complementary fashion More on this here: https://robo...
Definition: mpu6050.c:167
void compute_gyro_angle(int16_t gx, int16_t gy, int16_t gz, float dt, float *gyro_angle)
Compute the Euler angle (Pitch and Roll) from the gyroscope raw values Axes and Angles - X: Roll,...
Definition: mpu6050.c:135
esp_err_t mpu6050_read_gyro(uint8_t *data_rd, size_t size)
Get the gyroscope raw values (Gx, Gy, Gz) into an 8-bit array Note that these raw values are actually...
Definition: mpu6050.c:103
esp_err_t read_mpu6050_raw(int16_t *acce_raw_value, int16_t *gyro_raw_value)
A wrapper for reading the 8-bit raw values from MPU and then combining them to their final form i....
Definition: mpu6050.c:152
esp_err_t avg_sensors(int16_t *acce_raw_value_avg, int16_t *gyro_raw_value_avg, const int16_t *acce_offs, const int16_t *gyro_offs)
Helper function for the function calibrate_mpu6050() to calculate the average of the raw values.
Definition: mpu6050.c:202
void combine_msb_lsb_raw_data(uint8_t *buf_1, int16_t *buf_2)
Combine two 8-bit values to a 16-bit one Note that EVEN indices in the input buffer represent the MSB...
Definition: mpu6050.c:118
void compute_acce_angle(int16_t ax, int16_t ay, int16_t az, float *acce_angle)
Compute the Euler angle (Pitch and Roll) from the accelerometer raw values Axes and Angles - X: Roll,...
Definition: mpu6050.c:128
esp_err_t calibrate_mpu6050()
Function to calculate the MPU offset for raw values.
Definition: mpu6050.c:232
esp_err_t i2c_master_init()
Initialise the ESP32 I2C Driver in Master Mode.
Definition: mpu6050.c:39
lv_color_t * buf_1[DISP_BUF_SIZE]
Definition: oled.c:243