Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leech001/mpu6050
STM32 HAL library for GY-521 (MPU6050) with Kalman filter
https://github.com/leech001/mpu6050
blackpill bluepill gy-521 hal i2c kalman kalman-filter mpu6050 peripheral stm32 stm32f103c8t6 stm32f401ccu6
Last synced: about 5 hours ago
JSON representation
STM32 HAL library for GY-521 (MPU6050) with Kalman filter
- Host: GitHub
- URL: https://github.com/leech001/mpu6050
- Owner: leech001
- License: gpl-3.0
- Created: 2019-11-13T09:31:21.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-17T18:34:19.000Z (about 1 year ago)
- Last Synced: 2023-11-07T18:18:44.402Z (almost 1 year ago)
- Topics: blackpill, bluepill, gy-521, hal, i2c, kalman, kalman-filter, mpu6050, peripheral, stm32, stm32f103c8t6, stm32f401ccu6
- Language: C
- Homepage:
- Size: 1.33 MB
- Stars: 240
- Watchers: 8
- Forks: 69
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# STM32 HAL library for GY-521 (MPU6050) with Kalman filter
## English note
A simple C library (STM32 HAL) for working with the GY-521 module (MPU6050) https://www.aliexpress.com/af/gy%25252d521.html?trafficChannel=af&d=y&CatId=0&SearchText=gy-521<ype=affiliate&SortType= total_tranpro_desc & groupsort = 1 & page = 1Start and initialize the I2C bus using the STM32CubeMX.
![I2C](https://github.com/leech001/MPU6050/blob/master/img/I2C_param.png)
Configure STM32CubeMX by setting "General peripheral Initalizion as a pair of '.c / .h' file per peripheral" in the project settings.
Copy the library header and source file to the appropriate project directories (Inc, Src).
In the head file of your project (main.c), include the header file
```
/ * USER CODE BEGIN Includes * /
#include "mpu6050.h"
/ * USER CODE END Includes * /
```
add structure to the section
```
/ * USER CODE BEGIN PV * /
MPU6050_t MPU6050;
/ * USER CODE END PV * /
```
add int main (void) to the function section
```
/ * USER CODE BEGIN 2 * /while (MPU6050_Init(&hi2c1) == 1);
/ * USER CODE END 2 * /
```
for initial initialization of the GY-521 (MPU6050).add int main (void) to the function section
```
/ * USER CODE BEGIN WHILE * /
while (1)
{
/ * USER CODE END WHILE * // * USER CODE BEGIN 3 * /
MPU6050_Read_All(&hi2c1, &MPU6050);
HAL_Delay (100);
}
/ * USER CODE END 3 * /
```
On this project setup is ready.
After starting the program, information from the GY-521 (MPU6050) will be available through the MPU6050 structure
```
MPU6050.KalmanAngleX
```
The Kalman filter algorithm for calculating angles is taken from the project https://github.com/TKJElectronics/KalmanFilter## Russian note
Простая библиотека на Си (STM32 HAL) для работы с модулем GY-521 (MPU6050) https://www.aliexpress.com/af/gy%25252d521.html?trafficChannel=af&d=y&CatId=0&SearchText=gy-521<ype=affiliate&SortType=total_tranpro_desc&groupsort=1&page=1Запустите и инициализируйте шину I2C c помощью STM32CubeMX.
![I2C](https://github.com/leech001/MPU6050/blob/master/img/I2C_param.png)
Сконфигурируйте STM32CubeMX установив "General peripheral Initalizion as a pair of '.c/.h' file per peripheral" в настройках проекта.
Скопируйте заголовочный и исходный файл библиотеки в соотвесвтующие директории проекта (Inc, Src).
В головном файл вашего проекта (main.c) подключите заголовочный файл
```
/* USER CODE BEGIN Includes */
#include "mpu6050.h"
/* USER CODE END Includes */
```
в секцию добавьте структуру
```
/* USER CODE BEGIN PV */
MPU6050_t MPU6050;
/* USER CODE END PV */
```
добавьте в секцию функции int main(void)
```
/* USER CODE BEGIN 2 */while (MPU6050_Init(&hi2c1) == 1);
/* USER CODE END 2 */
```
для начальной инициализации GY-521 (MPU6050).добавьте в секцию функции int main(void)
```
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE *//* USER CODE BEGIN 3 */
MPU6050_Read_All(&hi2c1, &MPU6050);
HAL_Delay(100);
}
/* USER CODE END 3 */
```
На этом настройка проекта готова.
После запуска программы информация от GY-521 (MPU6050) будет доступна через структуру MPU6050
```
MPU6050.KalmanAngleX
```
Алгоритм фильтра Калмана для расчета углов взят из проекта https://github.com/TKJElectronics/KalmanFilter